1 /* $Id: capifs.c,v 1.1.2.3 2004/01/16 21:09:26 keil Exp $
3 * Copyright 2000 by Carsten Paeth <calle@calle.de>
5 * Heavily based on devpts filesystem from H. Peter Anvin
7 * This software may be used and distributed according to the terms
8 * of the GNU General Public License, incorporated herein by reference.
13 #include <linux/mount.h>
14 #include <linux/namei.h>
15 #include <linux/module.h>
16 #include <linux/init.h>
17 #include <linux/ctype.h>
18 #include <linux/sched.h> /* current */
22 MODULE_DESCRIPTION("CAPI4Linux: /dev/capi/ filesystem");
23 MODULE_AUTHOR("Carsten Paeth");
24 MODULE_LICENSE("GPL");
26 /* ------------------------------------------------------------------ */
28 #define CAPIFS_SUPER_MAGIC (('C'<<8)|'N')
30 static struct vfsmount
*capifs_mnt
;
31 static int capifs_mnt_count
;
39 } config
= {.mode
= 0600};
41 /* ------------------------------------------------------------------ */
43 static int capifs_remount(struct super_block
*s
, int *flags
, char *data
)
51 char *new_opt
= kstrdup(data
, GFP_KERNEL
);
54 while ((this_char
= strsep(&data
, ",")) != NULL
) {
59 if (sscanf(this_char
, "uid=%i%c", &n
, &dummy
) == 1) {
62 } else if (sscanf(this_char
, "gid=%i%c", &n
, &dummy
) == 1) {
65 } else if (sscanf(this_char
, "mode=%o%c", &n
, &dummy
) == 1)
69 printk("capifs: called with bogus options\n");
74 mutex_lock(&s
->s_root
->d_inode
->i_mutex
);
76 replace_mount_options(s
, new_opt
);
77 config
.setuid
= setuid
;
78 config
.setgid
= setgid
;
83 mutex_unlock(&s
->s_root
->d_inode
->i_mutex
);
88 static const struct super_operations capifs_sops
=
90 .statfs
= simple_statfs
,
91 .remount_fs
= capifs_remount
,
92 .show_options
= generic_show_options
,
97 capifs_fill_super(struct super_block
*s
, void *data
, int silent
)
101 s
->s_blocksize
= 1024;
102 s
->s_blocksize_bits
= 10;
103 s
->s_magic
= CAPIFS_SUPER_MAGIC
;
104 s
->s_op
= &capifs_sops
;
107 inode
= new_inode(s
);
111 inode
->i_mtime
= inode
->i_atime
= inode
->i_ctime
= CURRENT_TIME
;
112 inode
->i_mode
= S_IFDIR
| S_IRUGO
| S_IXUGO
| S_IWUSR
;
113 inode
->i_op
= &simple_dir_inode_operations
;
114 inode
->i_fop
= &simple_dir_operations
;
117 s
->s_root
= d_alloc_root(inode
);
121 printk("capifs: get root dentry failed\n");
127 static int capifs_get_sb(struct file_system_type
*fs_type
,
128 int flags
, const char *dev_name
, void *data
, struct vfsmount
*mnt
)
130 return get_sb_single(fs_type
, flags
, data
, capifs_fill_super
, mnt
);
133 static struct file_system_type capifs_fs_type
= {
134 .owner
= THIS_MODULE
,
136 .get_sb
= capifs_get_sb
,
137 .kill_sb
= kill_anon_super
,
140 static struct dentry
*new_ncci(unsigned int number
, dev_t device
)
142 struct super_block
*s
= capifs_mnt
->mnt_sb
;
143 struct dentry
*root
= s
->s_root
;
144 struct dentry
*dentry
;
149 mutex_lock(&root
->d_inode
->i_mutex
);
151 namelen
= sprintf(name
, "%d", number
);
152 dentry
= lookup_one_len(name
, root
, namelen
);
153 if (IS_ERR(dentry
)) {
158 if (dentry
->d_inode
) {
164 inode
= new_inode(s
);
171 /* config contents is protected by root's i_mutex */
172 inode
->i_uid
= config
.setuid
? config
.uid
: current_fsuid();
173 inode
->i_gid
= config
.setgid
? config
.gid
: current_fsgid();
174 inode
->i_mtime
= inode
->i_atime
= inode
->i_ctime
= CURRENT_TIME
;
175 inode
->i_ino
= number
+ 2;
176 init_special_inode(inode
, S_IFCHR
|config
.mode
, device
);
178 d_instantiate(dentry
, inode
);
182 mutex_unlock(&root
->d_inode
->i_mutex
);
187 struct dentry
*capifs_new_ncci(unsigned int number
, dev_t device
)
189 struct dentry
*dentry
;
191 if (simple_pin_fs(&capifs_fs_type
, &capifs_mnt
, &capifs_mnt_count
) < 0)
194 dentry
= new_ncci(number
, device
);
196 simple_release_fs(&capifs_mnt
, &capifs_mnt_count
);
201 void capifs_free_ncci(struct dentry
*dentry
)
203 struct dentry
*root
= capifs_mnt
->mnt_sb
->s_root
;
209 mutex_lock(&root
->d_inode
->i_mutex
);
211 inode
= dentry
->d_inode
;
219 mutex_unlock(&root
->d_inode
->i_mutex
);
221 simple_release_fs(&capifs_mnt
, &capifs_mnt_count
);
224 static int __init
capifs_init(void)
226 return register_filesystem(&capifs_fs_type
);
229 static void __exit
capifs_exit(void)
231 unregister_filesystem(&capifs_fs_type
);
234 EXPORT_SYMBOL(capifs_new_ncci
);
235 EXPORT_SYMBOL(capifs_free_ncci
);
237 module_init(capifs_init
);
238 module_exit(capifs_exit
);