2 * fs/sysfs/symlink.c - operations for initializing and mounting sysfs
4 * Copyright (c) 2001-3 Patrick Mochel
5 * Copyright (c) 2007 SUSE Linux Products GmbH
6 * Copyright (c) 2007 Tejun Heo <teheo@suse.de>
8 * This file is released under the GPLv2.
10 * Please see Documentation/filesystems/sysfs.txt for more information.
16 #include <linux/mount.h>
17 #include <linux/init.h>
18 #include <linux/user_namespace.h>
22 static struct kernfs_root
*sysfs_root
;
23 struct kernfs_node
*sysfs_root_kn
;
25 static struct dentry
*sysfs_mount(struct file_system_type
*fs_type
,
26 int flags
, const char *dev_name
, void *data
)
32 if (!(flags
& MS_KERNMOUNT
)) {
33 if (!capable(CAP_SYS_ADMIN
) && !fs_fully_visible(fs_type
))
34 return ERR_PTR(-EPERM
);
36 if (!kobj_ns_current_may_mount(KOBJ_NS_TYPE_NET
))
37 return ERR_PTR(-EPERM
);
40 ns
= kobj_ns_grab_current(KOBJ_NS_TYPE_NET
);
41 root
= kernfs_mount_ns(fs_type
, flags
, sysfs_root
, &new_sb
, ns
);
42 if (IS_ERR(root
) || !new_sb
)
43 kobj_ns_drop(KOBJ_NS_TYPE_NET
, ns
);
47 static void sysfs_kill_sb(struct super_block
*sb
)
49 void *ns
= (void *)kernfs_super_ns(sb
);
52 kobj_ns_drop(KOBJ_NS_TYPE_NET
, ns
);
55 static struct file_system_type sysfs_fs_type
= {
58 .kill_sb
= sysfs_kill_sb
,
59 .fs_flags
= FS_USERNS_MOUNT
,
62 int __init
sysfs_init(void)
66 sysfs_root
= kernfs_create_root(NULL
, KERNFS_ROOT_EXTRA_OPEN_PERM_CHECK
,
68 if (IS_ERR(sysfs_root
))
69 return PTR_ERR(sysfs_root
);
71 sysfs_root_kn
= sysfs_root
->kn
;
73 err
= register_filesystem(&sysfs_fs_type
);
75 kernfs_destroy_root(sysfs_root
);