1 /* -*- mode: c; c-basic-offset: 8; -*-
2 * vim: noexpandtab sw=8 ts=8 sts=0:
4 * mount.c - operations for initializing and mounting configfs.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public
17 * License along with this program; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 021110-1307, USA.
22 * sysfs is Copyright (C) 2001, 2002, 2003 Patrick Mochel
24 * configfs Copyright (C) 2005 Oracle. All rights reserved.
28 #include <linux/module.h>
29 #include <linux/mount.h>
30 #include <linux/pagemap.h>
31 #include <linux/init.h>
33 #include <linux/configfs.h>
34 #include "configfs_internal.h"
36 /* Random magic number */
37 #define CONFIGFS_MAGIC 0x62656570
39 struct vfsmount
* configfs_mount
= NULL
;
40 struct super_block
* configfs_sb
= NULL
;
41 static int configfs_mnt_count
= 0;
43 static struct super_operations configfs_ops
= {
44 .statfs
= simple_statfs
,
45 .drop_inode
= generic_delete_inode
,
48 static struct config_group configfs_root_group
= {
51 .ci_name
= configfs_root_group
.cg_item
.ci_namebuf
,
55 int configfs_is_root(struct config_item
*item
)
57 return item
== &configfs_root_group
.cg_item
;
60 static struct configfs_dirent configfs_root
= {
61 .s_sibling
= LIST_HEAD_INIT(configfs_root
.s_sibling
),
62 .s_children
= LIST_HEAD_INIT(configfs_root
.s_children
),
63 .s_element
= &configfs_root_group
.cg_item
,
64 .s_type
= CONFIGFS_ROOT
,
67 static int configfs_fill_super(struct super_block
*sb
, void *data
, int silent
)
72 sb
->s_blocksize
= PAGE_CACHE_SIZE
;
73 sb
->s_blocksize_bits
= PAGE_CACHE_SHIFT
;
74 sb
->s_magic
= CONFIGFS_MAGIC
;
75 sb
->s_op
= &configfs_ops
;
78 inode
= configfs_new_inode(S_IFDIR
| S_IRWXU
| S_IRUGO
| S_IXUGO
);
80 inode
->i_op
= &configfs_dir_inode_operations
;
81 inode
->i_fop
= &configfs_dir_operations
;
82 /* directory inodes start off with i_nlink == 2 (for "." entry) */
85 pr_debug("configfs: could not get root inode\n");
89 root
= d_alloc_root(inode
);
91 pr_debug("%s: could not get root dentry!\n",__FUNCTION__
);
95 config_group_init(&configfs_root_group
);
96 configfs_root_group
.cg_item
.ci_dentry
= root
;
97 root
->d_fsdata
= &configfs_root
;
102 static struct super_block
*configfs_get_sb(struct file_system_type
*fs_type
,
103 int flags
, const char *dev_name
, void *data
)
105 return get_sb_single(fs_type
, flags
, data
, configfs_fill_super
);
108 static struct file_system_type configfs_fs_type
= {
109 .owner
= THIS_MODULE
,
111 .get_sb
= configfs_get_sb
,
112 .kill_sb
= kill_litter_super
,
115 int configfs_pin_fs(void)
117 return simple_pin_fs("configfs", &configfs_mount
,
118 &configfs_mnt_count
);
121 void configfs_release_fs(void)
123 simple_release_fs(&configfs_mount
, &configfs_mnt_count
);
127 static decl_subsys(config
, NULL
, NULL
);
129 static int __init
configfs_init(void)
133 kset_set_kset_s(&config_subsys
, kernel_subsys
);
134 err
= subsystem_register(&config_subsys
);
138 err
= register_filesystem(&configfs_fs_type
);
140 printk(KERN_ERR
"configfs: Unable to register filesystem!\n");
141 subsystem_unregister(&config_subsys
);
147 static void __exit
configfs_exit(void)
149 unregister_filesystem(&configfs_fs_type
);
150 subsystem_unregister(&config_subsys
);
153 MODULE_AUTHOR("Oracle");
154 MODULE_LICENSE("GPL");
155 MODULE_VERSION("0.0.1");
156 MODULE_DESCRIPTION("Simple RAM filesystem for user driven kernel subsystem configuration.");
158 module_init(configfs_init
);
159 module_exit(configfs_exit
);