cregit-Linux how code gets into the kernel

Release 4.10 fs/configfs/symlink.c

Directory: fs/configfs
/* -*- mode: c; c-basic-offset: 8; -*-
 * vim: noexpandtab sw=8 ts=8 sts=0:
 *
 * symlink.c - operations for configfs symlinks.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this program; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 021110-1307, USA.
 *
 * Based on sysfs:
 *      sysfs is Copyright (C) 2001, 2002, 2003 Patrick Mochel
 *
 * configfs Copyright (C) 2005 Oracle.  All rights reserved.
 */

#include <linux/fs.h>
#include <linux/module.h>
#include <linux/namei.h>
#include <linux/slab.h>

#include <linux/configfs.h>
#include "configfs_internal.h"

/* Protects attachments of new symlinks */

DEFINE_MUTEX(configfs_symlink_mutex);


static int item_depth(struct config_item * item) { struct config_item * p = item; int depth = 0; do { depth++; } while ((p = p->ci_parent) && !configfs_is_root(p)); return depth; }

Contributors

PersonTokensPropCommitsCommitProp
joel beckerjoel becker49100.00%1100.00%
Total49100.00%1100.00%


static int item_path_length(struct config_item * item) { struct config_item * p = item; int length = 1; do { length += strlen(config_item_name(p)) + 1; p = p->ci_parent; } while (p && !configfs_is_root(p)); return length; }

Contributors

PersonTokensPropCommitsCommitProp
joel beckerjoel becker58100.00%1100.00%
Total58100.00%1100.00%


static void fill_item_path(struct config_item * item, char * buffer, int length) { struct config_item * p; --length; for (p = item; p && !configfs_is_root(p); p = p->ci_parent) { int cur = strlen(config_item_name(p)); /* back up enough to print this bus id with '/' */ length -= cur; strncpy(buffer + length,config_item_name(p),cur); *(buffer + --length) = '/'; } }

Contributors

PersonTokensPropCommitsCommitProp
joel beckerjoel becker88100.00%1100.00%
Total88100.00%1100.00%


static int create_link(struct config_item *parent_item, struct config_item *item, struct dentry *dentry) { struct configfs_dirent *target_sd = item->ci_dentry->d_fsdata; struct configfs_symlink *sl; int ret; ret = -ENOENT; if (!configfs_dirent_is_ready(target_sd)) goto out; ret = -ENOMEM; sl = kmalloc(sizeof(struct configfs_symlink), GFP_KERNEL); if (sl) { sl->sl_target = config_item_get(item); spin_lock(&configfs_dirent_lock); if (target_sd->s_type & CONFIGFS_USET_DROPPING) { spin_unlock(&configfs_dirent_lock); config_item_put(item); kfree(sl); return -ENOENT; } list_add(&sl->sl_list, &target_sd->s_links); spin_unlock(&configfs_dirent_lock); ret = configfs_create_link(sl, parent_item->ci_dentry, dentry); if (ret) { spin_lock(&configfs_dirent_lock); list_del_init(&sl->sl_list); spin_unlock(&configfs_dirent_lock); config_item_put(item); kfree(sl); } } out: return ret; }

Contributors

PersonTokensPropCommitsCommitProp
joel beckerjoel becker12663.64%125.00%
louis rillinglouis rilling7236.36%375.00%
Total198100.00%4100.00%


static int get_target(const char *symname, struct path *path, struct config_item **target, struct super_block *sb) { int ret; ret = kern_path(symname, LOOKUP_FOLLOW|LOOKUP_DIRECTORY, path); if (!ret) { if (path->dentry->d_sb == sb) { *target = configfs_get_config_item(path->dentry); if (!*target) { ret = -ENOENT; path_put(path); } } else { ret = -EPERM; path_put(path); } } return ret; }

Contributors

PersonTokensPropCommitsCommitProp
joel beckerjoel becker8378.30%116.67%
al viroal viro1917.92%350.00%
jan blunckjan blunck43.77%233.33%
Total106100.00%6100.00%


int configfs_symlink(struct inode *dir, struct dentry *dentry, const char *symname) { int ret; struct path path; struct configfs_dirent *sd; struct config_item *parent_item; struct config_item *target_item = NULL; struct config_item_type *type; sd = dentry->d_parent->d_fsdata; /* * Fake invisibility if dir belongs to a group/default groups hierarchy * being attached */ ret = -ENOENT; if (!configfs_dirent_is_ready(sd)) goto out; parent_item = configfs_get_config_item(dentry->d_parent); type = parent_item->ci_type; ret = -EPERM; if (!type || !type->ct_item_ops || !type->ct_item_ops->allow_link) goto out_put; ret = get_target(symname, &path, &target_item, dentry->d_sb); if (ret) goto out_put; ret = type->ct_item_ops->allow_link(parent_item, target_item); if (!ret) { mutex_lock(&configfs_symlink_mutex); ret = create_link(parent_item, target_item, dentry); mutex_unlock(&configfs_symlink_mutex); if (ret && type->ct_item_ops->drop_link) type->ct_item_ops->drop_link(parent_item, target_item); } config_item_put(target_item); path_put(&path); out_put: config_item_put(parent_item); out: return ret; }

Contributors

PersonTokensPropCommitsCommitProp
joel beckerjoel becker14464.00%112.50%
louis rillinglouis rilling7031.11%337.50%
al viroal viro73.11%225.00%
jan blunckjan blunck20.89%112.50%
subrata modaksubrata modak20.89%112.50%
Total225100.00%8100.00%


int configfs_unlink(struct inode *dir, struct dentry *dentry) { struct configfs_dirent *sd = dentry->d_fsdata; struct configfs_symlink *sl; struct config_item *parent_item; struct config_item_type *type; int ret; ret = -EPERM; /* What lack-of-symlink returns */ if (!(sd->s_type & CONFIGFS_ITEM_LINK)) goto out; sl = sd->s_element; parent_item = configfs_get_config_item(dentry->d_parent); type = parent_item->ci_type; spin_lock(&configfs_dirent_lock); list_del_init(&sd->s_sibling); spin_unlock(&configfs_dirent_lock); configfs_drop_dentry(sd, dentry->d_parent); dput(dentry); configfs_put(sd); /* * drop_link() must be called before * list_del_init(&sl->sl_list), so that the order of * drop_link(this, target) and drop_item(target) is preserved. */ if (type && type->ct_item_ops && type->ct_item_ops->drop_link) type->ct_item_ops->drop_link(parent_item, sl->sl_target); spin_lock(&configfs_dirent_lock); list_del_init(&sl->sl_list); spin_unlock(&configfs_dirent_lock); /* Put reference from create_link() */ config_item_put(sl->sl_target); kfree(sl); config_item_put(parent_item); ret = 0; out: return ret; }

Contributors

PersonTokensPropCommitsCommitProp
joel beckerjoel becker17387.82%133.33%
louis rillinglouis rilling2412.18%266.67%
Total197100.00%3100.00%


static int configfs_get_target_path(struct config_item * item, struct config_item * target, char *path) { char * s; int depth, size; depth = item_depth(item); size = item_path_length(target) + depth * 3 - 1; if (size > PATH_MAX) return -ENAMETOOLONG; pr_debug("%s: depth = %d, size = %d\n", __func__, depth, size); for (s = path; depth--; s += 3) strcpy(s,"../"); fill_item_path(target, path, size); pr_debug("%s: path = '%s'\n", __func__, path); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
joel beckerjoel becker10998.20%150.00%
harvey harrisonharvey harrison21.80%150.00%
Total111100.00%2100.00%


static int configfs_getlink(struct dentry *dentry, char * path) { struct config_item *item, *target_item; int error = 0; item = configfs_get_config_item(dentry->d_parent); if (!item) return -EINVAL; target_item = configfs_get_config_item(dentry); if (!target_item) { config_item_put(item); return -EINVAL; } down_read(&configfs_rename_sem); error = configfs_get_target_path(item, target_item, path); up_read(&configfs_rename_sem); config_item_put(item); config_item_put(target_item); return error; }

Contributors

PersonTokensPropCommitsCommitProp
joel beckerjoel becker105100.00%1100.00%
Total105100.00%1100.00%


static const char *configfs_get_link(struct dentry *dentry, struct inode *inode, struct delayed_call *done) { char *body; int error; if (!dentry) return ERR_PTR(-ECHILD); body = kzalloc(PAGE_SIZE, GFP_KERNEL); if (!body) return ERR_PTR(-ENOMEM); error = configfs_getlink(dentry, body); if (!error) { set_delayed_call(done, kfree_link, body); return body; } kfree(body); return ERR_PTR(error); }

Contributors

PersonTokensPropCommitsCommitProp
al viroal viro6462.75%480.00%
joel beckerjoel becker3837.25%120.00%
Total102100.00%5100.00%

const struct inode_operations configfs_symlink_inode_operations = { .get_link = configfs_get_link, .setattr = configfs_setattr, };

Overall Contributors

PersonTokensPropCommitsCommitProp
joel beckerjoel becker100378.30%29.52%
louis rillinglouis rilling17213.43%628.57%
al viroal viro927.18%733.33%
jan blunckjan blunck60.47%29.52%
tejun heotejun heo30.23%14.76%
harvey harrisonharvey harrison20.16%14.76%
subrata modaksubrata modak20.16%14.76%
arjan van de venarjan van de ven10.08%14.76%
Total1281100.00%21100.00%
Directory: fs/configfs
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.