1 /*
2 * Super block/filesystem wide operations
3 *
4 * Copyright (C) 1996 Peter J. Braam <braam@maths.ox.ac.uk> and
5 * Michael Callahan <callahan@maths.ox.ac.uk>
6 *
7 * Rewritten for Linux 2.1. Peter Braam <braam@cs.cmu.edu>
8 * Copyright (C) Carnegie Mellon University
9 */
10
11 #define __NO_VERSION__
12 #include <linux/module.h>
13 #include <linux/kernel.h>
14 #include <linux/mm.h>
15 #include <linux/string.h>
16 #include <linux/stat.h>
17 #include <linux/errno.h>
18 #include <linux/locks.h>
19 #include <linux/unistd.h>
20 #include <linux/smp_lock.h>
21 #include <linux/file.h>
22
23 #include <asm/system.h>
24 #include <asm/uaccess.h>
25
26 #include <linux/fs.h>
27 #include <linux/vmalloc.h>
28 #include <asm/segment.h>
29
30 #include <linux/coda.h>
31 #include <linux/coda_linux.h>
32 #include <linux/coda_psdev.h>
33 #include <linux/coda_fs_i.h>
34 #include <linux/coda_cache.h>
35
36 /* VFS super_block ops */
37 static struct super_block *coda_read_super(struct super_block *, void *, int);
38 static void coda_read_inode(struct inode *);
39 static void coda_clear_inode(struct inode *);
40 static void coda_put_super(struct super_block *);
41 static int coda_statfs(struct super_block *sb, struct statfs *buf);
42
43 /* exported operations */
44 struct super_operations coda_super_operations =
45 {
46 read_inode: coda_read_inode,
47 clear_inode: coda_clear_inode,
48 put_super: coda_put_super,
49 statfs: coda_statfs,
50 };
51
52 static int get_device_index(struct coda_mount_data *data)
53 {
54 struct file *file;
55 struct inode *inode;
56 int idx;
57
58 if(data == NULL) {
59 printk("coda_read_super: Bad mount data\n");
60 return -1;
61 }
62
63 if(data->version != CODA_MOUNT_VERSION) {
64 printk("coda_read_super: Bad mount version\n");
65 return -1;
66 }
67
68 file = fget(data->fd);
69 inode = NULL;
70 if(file)
71 inode = file->f_dentry->d_inode;
72
73 if(!inode || !S_ISCHR(inode->i_mode) ||
74 MAJOR(inode->i_rdev) != CODA_PSDEV_MAJOR) {
75 if(file)
76 fput(file);
77
78 printk("coda_read_super: Bad file\n");
79 return -1;
80 }
81
82 idx = MINOR(inode->i_rdev);
83 fput(file);
84
85 if(idx < 0 || idx >= MAX_CODADEVS) {
86 printk("coda_read_super: Bad minor number\n");
87 return -1;
88 }
89
90 return idx;
91 }
92
93 static struct super_block * coda_read_super(struct super_block *sb,
94 void *data, int silent)
95 {
96 struct inode *root = 0;
97 struct coda_sb_info *sbi = NULL;
98 struct venus_comm *vc = NULL;
99 ViceFid fid;
100 kdev_t dev = sb->s_dev;
101 int error;
102 int idx;
103 ENTRY;
104
105 idx = get_device_index((struct coda_mount_data *) data);
106
107 /* Ignore errors in data, for backward compatibility */
108 if(idx == -1)
109 idx = 0;
110
111 printk(KERN_INFO "coda_read_super: device index: %i\n", idx);
112
113 vc = &coda_comms[idx];
114 if (!vc->vc_inuse) {
115 printk("coda_read_super: No pseudo device\n");
116 EXIT;
117 return NULL;
118 }
119
120 if ( vc->vc_sb ) {
121 printk("coda_read_super: Device already mounted\n");
122 EXIT;
123 return NULL;
124 }
125
126 sbi = kmalloc(sizeof(struct coda_sb_info), GFP_KERNEL);
127 if(!sbi) {
128 EXIT;
129 return NULL;
130 }
131
132 vc->vc_sb = sb;
133
134 sbi->sbi_sb = sb;
135 sbi->sbi_vcomm = vc;
136 INIT_LIST_HEAD(&sbi->sbi_cihead);
137
138 sb->u.generic_sbp = sbi;
139 sb->s_blocksize = 1024; /* XXXXX what do we put here?? */
140 sb->s_blocksize_bits = 10;
141 sb->s_magic = CODA_SUPER_MAGIC;
142 sb->s_dev = dev;
143 sb->s_op = &coda_super_operations;
144
145 /* get root fid from Venus: this needs the root inode */
146 error = venus_rootfid(sb, &fid);
147 if ( error ) {
148 printk("coda_read_super: coda_get_rootfid failed with %d\n",
149 error);
150 goto error;
151 }
152 printk("coda_read_super: rootfid is %s\n", coda_f2s(&fid));
153
154 /* make root inode */
155 error = coda_cnode_make(&root, &fid, sb);
156 if ( error || !root ) {
157 printk("Failure of coda_cnode_make for root: error %d\n", error);
158 goto error;
159 }
160
161 printk("coda_read_super: rootinode is %ld dev %d\n",
162 root->i_ino, root->i_dev);
163 sb->s_root = d_alloc_root(root);
164 EXIT;
165 return sb;
166
167 error:
168 EXIT;
169 if (sbi) {
170 kfree(sbi);
171 if(vc)
172 vc->vc_sb = NULL;
173 }
174 if (root) {
175 iput(root);
176 }
177 return NULL;
178 }
179
180 static void coda_put_super(struct super_block *sb)
181 {
182 struct coda_sb_info *sbi;
183
184 ENTRY;
185
186 sbi = coda_sbp(sb);
187 sbi->sbi_vcomm->vc_sb = NULL;
188 list_del_init(&sbi->sbi_cihead);
189
190 printk("Coda: Bye bye.\n");
191 kfree(sbi);
192
193 EXIT;
194 }
195
196 /* all filling in of inodes postponed until lookup */
197 static void coda_read_inode(struct inode *inode)
198 {
199 struct coda_sb_info *sbi = coda_sbp(inode->i_sb);
200 struct coda_inode_info *cii;
201 ENTRY;
202
203 if (!sbi) BUG();
204
205 cii = ITOC(inode);
206 if (cii->c_magic == CODA_CNODE_MAGIC) {
207 printk("coda_read_inode: initialized inode");
208 return;
209 }
210
211 memset(cii, 0, sizeof(struct coda_inode_info));
212 list_add(&cii->c_cilist, &sbi->sbi_cihead);
213 cii->c_magic = CODA_CNODE_MAGIC;
214 }
215
216 static void coda_clear_inode(struct inode *inode)
217 {
218 struct coda_inode_info *cii = ITOC(inode);
219 struct inode *open_inode;
220
221 ENTRY;
222 CDEBUG(D_SUPER, " inode->ino: %ld, count: %d\n",
223 inode->i_ino, atomic_read(&inode->i_count));
224
225 if ( cii->c_magic != CODA_CNODE_MAGIC )
226 return;
227
228 list_del_init(&cii->c_cilist);
229
230 if ( inode->i_ino == CTL_INO )
231 goto out;
232
233 if ( inode->i_mapping != &inode->i_data ) {
234 open_inode = inode->i_mapping->host;
235 CDEBUG(D_SUPER, "DELINO cached file: ino %ld count %d.\n",
236 open_inode->i_ino, atomic_read(&open_inode->i_count));
237 inode->i_mapping = &inode->i_data;
238 iput(open_inode);
239 }
240
241 CDEBUG(D_DOWNCALL, "clearing inode: %ld, %x\n", inode->i_ino, cii->c_flags);
242 coda_cache_clear_inode(inode);
243 out:
244 inode->u.coda_i.c_magic = 0;
245 memset(&inode->u.coda_i.c_fid, 0, sizeof(struct ViceFid));
246 EXIT;
247 }
248
249 int coda_notify_change(struct dentry *de, struct iattr *iattr)
250 {
251 struct inode *inode = de->d_inode;
252 struct coda_vattr vattr;
253 int error;
254
255 ENTRY;
256 memset(&vattr, 0, sizeof(vattr));
257
258 coda_iattr_to_vattr(iattr, &vattr);
259 vattr.va_type = C_VNON; /* cannot set type */
260 CDEBUG(D_SUPER, "vattr.va_mode %o\n", vattr.va_mode);
261
262 /* Venus is responsible for truncating the container-file!!! */
263 error = venus_setattr(inode->i_sb, coda_i2f(inode), &vattr);
264
265 if ( !error ) {
266 coda_vattr_to_iattr(inode, &vattr);
267 coda_cache_clear_inode(inode);
268 }
269 CDEBUG(D_SUPER, "inode.i_mode %o, error %d\n", inode->i_mode, error);
270
271 EXIT;
272 return error;
273 }
274
275 struct inode_operations coda_file_inode_operations = {
276 permission: coda_permission,
277 revalidate: coda_revalidate_inode,
278 setattr: coda_notify_change,
279 };
280
281 static int coda_statfs(struct super_block *sb, struct statfs *buf)
282 {
283 int error;
284
285 error = venus_statfs(sb, buf);
286
287 if (error) {
288 /* fake something like AFS does */
289 buf->f_blocks = 9000000;
290 buf->f_bfree = 9000000;
291 buf->f_bavail = 9000000;
292 buf->f_files = 9000000;
293 buf->f_ffree = 9000000;
294 }
295
296 /* and fill in the rest */
297 buf->f_type = CODA_SUPER_MAGIC;
298 buf->f_bsize = 1024;
299 buf->f_namelen = CODA_MAXNAMLEN;
300
301 return 0;
302 }
303
304 /* init_coda: used by filesystems.c to register coda */
305
306 DECLARE_FSTYPE( coda_fs_type, "coda", coda_read_super, 0);
307
308
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.