~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/fs/sysfs/mount.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0
  2 /*
  3  * fs/sysfs/symlink.c - operations for initializing and mounting sysfs
  4  *
  5  * Copyright (c) 2001-3 Patrick Mochel
  6  * Copyright (c) 2007 SUSE Linux Products GmbH
  7  * Copyright (c) 2007 Tejun Heo <teheo@suse.de>
  8  *
  9  * Please see Documentation/filesystems/sysfs.rst for more information.
 10  */
 11 
 12 #include <linux/fs.h>
 13 #include <linux/magic.h>
 14 #include <linux/mount.h>
 15 #include <linux/init.h>
 16 #include <linux/slab.h>
 17 #include <linux/user_namespace.h>
 18 #include <linux/fs_context.h>
 19 #include <net/net_namespace.h>
 20 
 21 #include "sysfs.h"
 22 
 23 static struct kernfs_root *sysfs_root;
 24 struct kernfs_node *sysfs_root_kn;
 25 
 26 static int sysfs_get_tree(struct fs_context *fc)
 27 {
 28         struct kernfs_fs_context *kfc = fc->fs_private;
 29         int ret;
 30 
 31         ret = kernfs_get_tree(fc);
 32         if (ret)
 33                 return ret;
 34 
 35         if (kfc->new_sb_created)
 36                 fc->root->d_sb->s_iflags |= SB_I_USERNS_VISIBLE;
 37         return 0;
 38 }
 39 
 40 static void sysfs_fs_context_free(struct fs_context *fc)
 41 {
 42         struct kernfs_fs_context *kfc = fc->fs_private;
 43 
 44         if (kfc->ns_tag)
 45                 kobj_ns_drop(KOBJ_NS_TYPE_NET, kfc->ns_tag);
 46         kernfs_free_fs_context(fc);
 47         kfree(kfc);
 48 }
 49 
 50 static const struct fs_context_operations sysfs_fs_context_ops = {
 51         .free           = sysfs_fs_context_free,
 52         .get_tree       = sysfs_get_tree,
 53 };
 54 
 55 static int sysfs_init_fs_context(struct fs_context *fc)
 56 {
 57         struct kernfs_fs_context *kfc;
 58         struct net *netns;
 59 
 60         if (!(fc->sb_flags & SB_KERNMOUNT)) {
 61                 if (!kobj_ns_current_may_mount(KOBJ_NS_TYPE_NET))
 62                         return -EPERM;
 63         }
 64 
 65         kfc = kzalloc(sizeof(struct kernfs_fs_context), GFP_KERNEL);
 66         if (!kfc)
 67                 return -ENOMEM;
 68 
 69         kfc->ns_tag = netns = kobj_ns_grab_current(KOBJ_NS_TYPE_NET);
 70         kfc->root = sysfs_root;
 71         kfc->magic = SYSFS_MAGIC;
 72         fc->fs_private = kfc;
 73         fc->ops = &sysfs_fs_context_ops;
 74         if (netns) {
 75                 put_user_ns(fc->user_ns);
 76                 fc->user_ns = get_user_ns(netns->user_ns);
 77         }
 78         fc->global = true;
 79         return 0;
 80 }
 81 
 82 static void sysfs_kill_sb(struct super_block *sb)
 83 {
 84         void *ns = (void *)kernfs_super_ns(sb);
 85 
 86         kernfs_kill_sb(sb);
 87         kobj_ns_drop(KOBJ_NS_TYPE_NET, ns);
 88 }
 89 
 90 static struct file_system_type sysfs_fs_type = {
 91         .name                   = "sysfs",
 92         .init_fs_context        = sysfs_init_fs_context,
 93         .kill_sb                = sysfs_kill_sb,
 94         .fs_flags               = FS_USERNS_MOUNT,
 95 };
 96 
 97 int __init sysfs_init(void)
 98 {
 99         int err;
100 
101         sysfs_root = kernfs_create_root(NULL, KERNFS_ROOT_EXTRA_OPEN_PERM_CHECK,
102                                         NULL);
103         if (IS_ERR(sysfs_root))
104                 return PTR_ERR(sysfs_root);
105 
106         sysfs_root_kn = kernfs_root_to_node(sysfs_root);
107 
108         err = register_filesystem(&sysfs_fs_type);
109         if (err) {
110                 kernfs_destroy_root(sysfs_root);
111                 return err;
112         }
113 
114         return 0;
115 }
116 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php