ath5k: fix values for bus error bits in ISR2
[linux-2.6/next.git] / drivers / isdn / capi / capifs.c
blobbff72d81f2636781d444d7180be11c9937207fa5
1 /* $Id: capifs.c,v 1.1.2.3 2004/01/16 21:09:26 keil Exp $
2 *
3 * Copyright 2000 by Carsten Paeth <calle@calle.de>
5 * Heavily based on devpts filesystem from H. Peter Anvin
6 *
7 * This software may be used and distributed according to the terms
8 * of the GNU General Public License, incorporated herein by reference.
12 #include <linux/fs.h>
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 */
20 #include "capifs.h"
22 MODULE_DESCRIPTION("CAPI4Linux: /dev/capi/ filesystem");
23 MODULE_AUTHOR("Carsten Paeth");
24 MODULE_LICENSE("GPL");
26 /* ------------------------------------------------------------------ */
28 static char *revision = "$Revision: 1.1.2.3 $";
30 /* ------------------------------------------------------------------ */
32 #define CAPIFS_SUPER_MAGIC (('C'<<8)|'N')
34 static struct vfsmount *capifs_mnt;
35 static struct dentry *capifs_root;
37 static struct {
38 int setuid;
39 int setgid;
40 uid_t uid;
41 gid_t gid;
42 umode_t mode;
43 } config = {.mode = 0600};
45 /* ------------------------------------------------------------------ */
47 static int capifs_remount(struct super_block *s, int *flags, char *data)
49 int setuid = 0;
50 int setgid = 0;
51 uid_t uid = 0;
52 gid_t gid = 0;
53 umode_t mode = 0600;
54 char *this_char;
55 char *new_opt = kstrdup(data, GFP_KERNEL);
57 this_char = NULL;
58 while ((this_char = strsep(&data, ",")) != NULL) {
59 int n;
60 char dummy;
61 if (!*this_char)
62 continue;
63 if (sscanf(this_char, "uid=%i%c", &n, &dummy) == 1) {
64 setuid = 1;
65 uid = n;
66 } else if (sscanf(this_char, "gid=%i%c", &n, &dummy) == 1) {
67 setgid = 1;
68 gid = n;
69 } else if (sscanf(this_char, "mode=%o%c", &n, &dummy) == 1)
70 mode = n & ~S_IFMT;
71 else {
72 kfree(new_opt);
73 printk("capifs: called with bogus options\n");
74 return -EINVAL;
78 mutex_lock(&s->s_root->d_inode->i_mutex);
80 replace_mount_options(s, new_opt);
81 config.setuid = setuid;
82 config.setgid = setgid;
83 config.uid = uid;
84 config.gid = gid;
85 config.mode = mode;
87 mutex_unlock(&s->s_root->d_inode->i_mutex);
89 return 0;
92 static struct super_operations capifs_sops =
94 .statfs = simple_statfs,
95 .remount_fs = capifs_remount,
96 .show_options = generic_show_options,
100 static int
101 capifs_fill_super(struct super_block *s, void *data, int silent)
103 struct inode * inode;
105 s->s_blocksize = 1024;
106 s->s_blocksize_bits = 10;
107 s->s_magic = CAPIFS_SUPER_MAGIC;
108 s->s_op = &capifs_sops;
109 s->s_time_gran = 1;
111 inode = new_inode(s);
112 if (!inode)
113 goto fail;
114 inode->i_ino = 1;
115 inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
116 inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO | S_IWUSR;
117 inode->i_op = &simple_dir_inode_operations;
118 inode->i_fop = &simple_dir_operations;
119 inode->i_nlink = 2;
121 capifs_root = s->s_root = d_alloc_root(inode);
122 if (s->s_root)
123 return 0;
125 printk("capifs: get root dentry failed\n");
126 iput(inode);
127 fail:
128 return -ENOMEM;
131 static int capifs_get_sb(struct file_system_type *fs_type,
132 int flags, const char *dev_name, void *data, struct vfsmount *mnt)
134 return get_sb_single(fs_type, flags, data, capifs_fill_super, mnt);
137 static struct file_system_type capifs_fs_type = {
138 .owner = THIS_MODULE,
139 .name = "capifs",
140 .get_sb = capifs_get_sb,
141 .kill_sb = kill_anon_super,
144 static struct dentry *get_node(int num)
146 char s[10];
147 struct dentry *root = capifs_root;
148 mutex_lock(&root->d_inode->i_mutex);
149 return lookup_one_len(s, root, sprintf(s, "%d", num));
152 void capifs_new_ncci(unsigned int number, dev_t device)
154 struct dentry *dentry;
155 struct inode *inode = new_inode(capifs_mnt->mnt_sb);
156 if (!inode)
157 return;
158 inode->i_ino = number+2;
160 dentry = get_node(number);
162 /* config contents is protected by root's i_mutex */
163 inode->i_uid = config.setuid ? config.uid : current_fsuid();
164 inode->i_gid = config.setgid ? config.gid : current_fsgid();
165 inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
166 init_special_inode(inode, S_IFCHR|config.mode, device);
167 //inode->i_op = &capifs_file_inode_operations;
169 if (!IS_ERR(dentry) && !dentry->d_inode)
170 d_instantiate(dentry, inode);
171 mutex_unlock(&capifs_root->d_inode->i_mutex);
174 void capifs_free_ncci(unsigned int number)
176 struct dentry *dentry = get_node(number);
178 if (!IS_ERR(dentry)) {
179 struct inode *inode = dentry->d_inode;
180 if (inode) {
181 inode->i_nlink--;
182 d_delete(dentry);
183 dput(dentry);
185 dput(dentry);
187 mutex_unlock(&capifs_root->d_inode->i_mutex);
190 static int __init capifs_init(void)
192 char rev[32];
193 char *p;
194 int err;
196 if ((p = strchr(revision, ':')) != NULL && p[1]) {
197 strlcpy(rev, p + 2, sizeof(rev));
198 if ((p = strchr(rev, '$')) != NULL && p > rev)
199 *(p-1) = 0;
200 } else
201 strcpy(rev, "1.0");
203 err = register_filesystem(&capifs_fs_type);
204 if (!err) {
205 capifs_mnt = kern_mount(&capifs_fs_type);
206 if (IS_ERR(capifs_mnt)) {
207 err = PTR_ERR(capifs_mnt);
208 unregister_filesystem(&capifs_fs_type);
211 if (!err)
212 printk(KERN_NOTICE "capifs: Rev %s\n", rev);
213 return err;
216 static void __exit capifs_exit(void)
218 unregister_filesystem(&capifs_fs_type);
219 mntput(capifs_mnt);
222 EXPORT_SYMBOL(capifs_new_ncci);
223 EXPORT_SYMBOL(capifs_free_ncci);
225 module_init(capifs_init);
226 module_exit(capifs_exit);