Skip to content
Snippets Groups Projects
mount.c 1.65 KiB
Newer Older
  • Learn to ignore specific revisions
  • Linus Torvalds's avatar
    Linus Torvalds committed
    /*
    
    Tejun Heo's avatar
    Tejun Heo committed
     * fs/sysfs/symlink.c - operations for initializing and mounting sysfs
     *
     * Copyright (c) 2001-3 Patrick Mochel
     * Copyright (c) 2007 SUSE Linux Products GmbH
     * Copyright (c) 2007 Tejun Heo <teheo@suse.de>
     *
     * This file is released under the GPLv2.
     *
     * Please see Documentation/filesystems/sysfs.txt for more information.
    
    Linus Torvalds's avatar
    Linus Torvalds committed
     */
    
    
    #define DEBUG
    
    Linus Torvalds's avatar
    Linus Torvalds committed
    
    #include <linux/fs.h>
    #include <linux/mount.h>
    #include <linux/init.h>
    
    #include <linux/user_namespace.h>
    
    Linus Torvalds's avatar
    Linus Torvalds committed
    
    #include "sysfs.h"
    
    
    static struct kernfs_root *sysfs_root;
    struct sysfs_dirent *sysfs_root_sd;
    
    Al Viro's avatar
    Al Viro committed
    static struct dentry *sysfs_mount(struct file_system_type *fs_type,
    	int flags, const char *dev_name, void *data)
    
    Linus Torvalds's avatar
    Linus Torvalds committed
    {
    
    	struct dentry *root;
    	void *ns;
    
    	if (!(flags & MS_KERNMOUNT)) {
    		if (!capable(CAP_SYS_ADMIN) && !fs_fully_visible(fs_type))
    			return ERR_PTR(-EPERM);
    
    
    		if (!kobj_ns_current_may_mount(KOBJ_NS_TYPE_NET))
    			return ERR_PTR(-EPERM);
    
    	ns = kobj_ns_grab_current(KOBJ_NS_TYPE_NET);
    	root = kernfs_mount_ns(fs_type, flags, sysfs_root, ns);
    	if (IS_ERR(root))
    		kobj_ns_drop(KOBJ_NS_TYPE_NET, ns);
    	return root;
    }
    
    
    static void sysfs_kill_sb(struct super_block *sb)
    
    	void *ns = (void *)kernfs_super_ns(sb);
    
    
    	kernfs_kill_sb(sb);
    
    	kobj_ns_drop(KOBJ_NS_TYPE_NET, ns);
    
    Linus Torvalds's avatar
    Linus Torvalds committed
    static struct file_system_type sysfs_fs_type = {
    	.name		= "sysfs",
    
    Al Viro's avatar
    Al Viro committed
    	.mount		= sysfs_mount,
    
    	.kill_sb	= sysfs_kill_sb,
    
    	.fs_flags	= FS_USERNS_MOUNT,
    
    Linus Torvalds's avatar
    Linus Torvalds committed
    };
    
    
    int __init sysfs_init(void)
    {
    	int err;
    
    Peter Zijlstra's avatar
    Peter Zijlstra committed
    
    
    	sysfs_root = kernfs_create_root(NULL);
    
    	if (IS_ERR(sysfs_root))
    		return PTR_ERR(sysfs_root);
    
    
    	sysfs_root_sd = sysfs_root->sd;
    
    
    Linus Torvalds's avatar
    Linus Torvalds committed
    	err = register_filesystem(&sysfs_fs_type);
    
    	if (err) {
    		kernfs_destroy_root(sysfs_root);
    		return err;
    	}
    
    Linus Torvalds's avatar
    Linus Torvalds committed
    }