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

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

Version: ~ [ linux-5.15-rc1 ] ~ [ linux-5.14.5 ] ~ [ linux-5.13.18 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.66 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.147 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.206 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.246 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.282 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.283 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.18.140 ] ~ [ linux-3.16.85 ] ~ [ linux-3.14.79 ] ~ [ linux-3.12.74 ] ~ [ 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.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0-or-later
  2 /* -*- mode: c; c-basic-offset: 8; -*-
  3  * vim: noexpandtab sw=8 ts=8 sts=0:
  4  *
  5  * mount.c - operations for initializing and mounting configfs.
  6  *
  7  * Based on sysfs:
  8  *      sysfs is Copyright (C) 2001, 2002, 2003 Patrick Mochel
  9  *
 10  * configfs Copyright (C) 2005 Oracle.  All rights reserved.
 11  */
 12 
 13 #include <linux/fs.h>
 14 #include <linux/module.h>
 15 #include <linux/mount.h>
 16 #include <linux/pagemap.h>
 17 #include <linux/init.h>
 18 #include <linux/slab.h>
 19 
 20 #include <linux/configfs.h>
 21 #include "configfs_internal.h"
 22 
 23 /* Random magic number */
 24 #define CONFIGFS_MAGIC 0x62656570
 25 
 26 static struct vfsmount *configfs_mount = NULL;
 27 struct kmem_cache *configfs_dir_cachep;
 28 static int configfs_mnt_count = 0;
 29 
 30 static const struct super_operations configfs_ops = {
 31         .statfs         = simple_statfs,
 32         .drop_inode     = generic_delete_inode,
 33 };
 34 
 35 static struct config_group configfs_root_group = {
 36         .cg_item = {
 37                 .ci_namebuf     = "root",
 38                 .ci_name        = configfs_root_group.cg_item.ci_namebuf,
 39         },
 40 };
 41 
 42 int configfs_is_root(struct config_item *item)
 43 {
 44         return item == &configfs_root_group.cg_item;
 45 }
 46 
 47 static struct configfs_dirent configfs_root = {
 48         .s_sibling      = LIST_HEAD_INIT(configfs_root.s_sibling),
 49         .s_children     = LIST_HEAD_INIT(configfs_root.s_children),
 50         .s_element      = &configfs_root_group.cg_item,
 51         .s_type         = CONFIGFS_ROOT,
 52         .s_iattr        = NULL,
 53 };
 54 
 55 static int configfs_fill_super(struct super_block *sb, void *data, int silent)
 56 {
 57         struct inode *inode;
 58         struct dentry *root;
 59 
 60         sb->s_blocksize = PAGE_SIZE;
 61         sb->s_blocksize_bits = PAGE_SHIFT;
 62         sb->s_magic = CONFIGFS_MAGIC;
 63         sb->s_op = &configfs_ops;
 64         sb->s_time_gran = 1;
 65 
 66         inode = configfs_new_inode(S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
 67                                    &configfs_root, sb);
 68         if (inode) {
 69                 inode->i_op = &configfs_root_inode_operations;
 70                 inode->i_fop = &configfs_dir_operations;
 71                 /* directory inodes start off with i_nlink == 2 (for "." entry) */
 72                 inc_nlink(inode);
 73         } else {
 74                 pr_debug("could not get root inode\n");
 75                 return -ENOMEM;
 76         }
 77 
 78         root = d_make_root(inode);
 79         if (!root) {
 80                 pr_debug("%s: could not get root dentry!\n",__func__);
 81                 return -ENOMEM;
 82         }
 83         config_group_init(&configfs_root_group);
 84         configfs_root_group.cg_item.ci_dentry = root;
 85         root->d_fsdata = &configfs_root;
 86         sb->s_root = root;
 87         sb->s_d_op = &configfs_dentry_ops; /* the rest get that */
 88         return 0;
 89 }
 90 
 91 static struct dentry *configfs_do_mount(struct file_system_type *fs_type,
 92         int flags, const char *dev_name, void *data)
 93 {
 94         return mount_single(fs_type, flags, data, configfs_fill_super);
 95 }
 96 
 97 static struct file_system_type configfs_fs_type = {
 98         .owner          = THIS_MODULE,
 99         .name           = "configfs",
100         .mount          = configfs_do_mount,
101         .kill_sb        = kill_litter_super,
102 };
103 MODULE_ALIAS_FS("configfs");
104 
105 struct dentry *configfs_pin_fs(void)
106 {
107         int err = simple_pin_fs(&configfs_fs_type, &configfs_mount,
108                              &configfs_mnt_count);
109         return err ? ERR_PTR(err) : configfs_mount->mnt_root;
110 }
111 
112 void configfs_release_fs(void)
113 {
114         simple_release_fs(&configfs_mount, &configfs_mnt_count);
115 }
116 
117 
118 static int __init configfs_init(void)
119 {
120         int err = -ENOMEM;
121 
122         configfs_dir_cachep = kmem_cache_create("configfs_dir_cache",
123                                                 sizeof(struct configfs_dirent),
124                                                 0, 0, NULL);
125         if (!configfs_dir_cachep)
126                 goto out;
127 
128         err = sysfs_create_mount_point(kernel_kobj, "config");
129         if (err)
130                 goto out2;
131 
132         err = register_filesystem(&configfs_fs_type);
133         if (err)
134                 goto out3;
135 
136         return 0;
137 out3:
138         pr_err("Unable to register filesystem!\n");
139         sysfs_remove_mount_point(kernel_kobj, "config");
140 out2:
141         kmem_cache_destroy(configfs_dir_cachep);
142         configfs_dir_cachep = NULL;
143 out:
144         return err;
145 }
146 
147 static void __exit configfs_exit(void)
148 {
149         unregister_filesystem(&configfs_fs_type);
150         sysfs_remove_mount_point(kernel_kobj, "config");
151         kmem_cache_destroy(configfs_dir_cachep);
152         configfs_dir_cachep = NULL;
153 }
154 
155 MODULE_AUTHOR("Oracle");
156 MODULE_LICENSE("GPL");
157 MODULE_VERSION("0.0.2");
158 MODULE_DESCRIPTION("Simple RAM filesystem for user driven kernel subsystem configuration.");
159 
160 core_initcall(configfs_init);
161 module_exit(configfs_exit);
162 

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

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | 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.

osdn.jp