Import 2.3.10pre5
[davej-history.git] / fs / coda / inode.c
blob604e906a234ee4fe49f3e4a200961e9e9cf9f37c
1 /*
2 * Super block/filesystem wide operations
4 * Copryright (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 */
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>
21 #include <asm/system.h>
22 #include <asm/uaccess.h>
24 #include <linux/fs.h>
25 #include <linux/vmalloc.h>
26 #include <asm/segment.h>
28 #include <linux/coda.h>
29 #include <linux/coda_linux.h>
30 #include <linux/coda_psdev.h>
31 #include <linux/coda_fs_i.h>
32 #include <linux/coda_cache.h>
34 /* VFS super_block ops */
35 static struct super_block *coda_read_super(struct super_block *, void *, int);
36 static void coda_read_inode(struct inode *);
37 static int coda_notify_change(struct dentry *dentry, struct iattr *attr);
38 static void coda_put_inode(struct inode *);
39 static void coda_delete_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 int bufsiz);
44 /* exported operations */
45 struct super_operations coda_super_operations =
47 coda_read_inode, /* read_inode */
48 NULL, /* write_inode */
49 coda_put_inode, /* put_inode */
50 coda_delete_inode, /* delete_inode */
51 coda_notify_change, /* notify_change */
52 coda_put_super, /* put_super */
53 NULL, /* write_super */
54 coda_statfs, /* statfs */
55 NULL /* remount_fs */
58 static struct super_block * coda_read_super(struct super_block *sb,
59 void *data, int silent)
61 struct inode *psdev = 0, *root = 0;
62 struct coda_sb_info *sbi = NULL;
63 struct venus_comm *vc = NULL;
64 ViceFid fid;
65 kdev_t dev = sb->s_dev;
66 int error;
68 ENTRY;
69 MOD_INC_USE_COUNT;
71 vc = &coda_upc_comm;
72 sbi = &coda_super_info;
74 if ( sbi->sbi_sb ) {
75 printk("Already mounted\n");
76 unlock_super(sb);
77 EXIT;
78 MOD_DEC_USE_COUNT;
79 return NULL;
82 sbi->sbi_sb = sb;
83 sbi->sbi_psdev = psdev;
84 sbi->sbi_vcomm = vc;
85 INIT_LIST_HEAD(&(sbi->sbi_cchead));
86 INIT_LIST_HEAD(&(sbi->sbi_volroothead));
88 lock_super(sb);
89 sb->u.generic_sbp = sbi;
90 sb->s_blocksize = 1024; /* XXXXX what do we put here?? */
91 sb->s_blocksize_bits = 10;
92 sb->s_magic = CODA_SUPER_MAGIC;
93 sb->s_dev = dev;
94 sb->s_op = &coda_super_operations;
96 /* get root fid from Venus: this needs the root inode */
97 error = venus_rootfid(sb, &fid);
98 if ( error ) {
99 printk("coda_read_super: coda_get_rootfid failed with %d\n",
100 error);
101 sb->s_dev = 0;
102 goto error;
104 printk("coda_read_super: rootfid is %s\n", coda_f2s(&fid));
106 /* make root inode */
107 error = coda_cnode_make(&root, &fid, sb);
108 if ( error || !root ) {
109 printk("Failure of coda_cnode_make for root: error %d\n", error);
110 sb->s_dev = 0;
111 goto error;
114 printk("coda_read_super: rootinode is %ld dev %d\n",
115 root->i_ino, root->i_dev);
116 sbi->sbi_root = root;
117 sb->s_root = d_alloc_root(root);
118 unlock_super(sb);
119 EXIT;
120 return sb;
122 error:
123 unlock_super(sb);
124 EXIT;
125 MOD_DEC_USE_COUNT;
126 if (sbi) {
127 sbi->sbi_vcomm = NULL;
128 sbi->sbi_root = NULL;
129 sbi->sbi_sb = NULL;
131 if (root) {
132 iput(root);
134 sb->s_dev = 0;
135 return NULL;
138 static void coda_put_super(struct super_block *sb)
140 struct coda_sb_info *sb_info;
142 ENTRY;
145 sb->s_dev = 0;
146 coda_cache_clear_all(sb);
147 sb_info = coda_sbp(sb);
148 coda_super_info.sbi_sb = NULL;
149 printk("Coda: Bye bye.\n");
150 memset(sb_info, 0, sizeof(* sb_info));
152 MOD_DEC_USE_COUNT;
153 EXIT;
156 /* all filling in of inodes postponed until lookup */
157 static void coda_read_inode(struct inode *inode)
159 struct coda_inode_info *cii;
160 ENTRY;
161 cii = ITOC(inode);
162 cii->c_magic = 0;
163 return;
166 static void coda_put_inode(struct inode *in)
168 ENTRY;
170 CDEBUG(D_INODE,"ino: %ld, count %d\n", in->i_ino, in->i_count);
172 if ( in->i_count == 1 )
173 in->i_nlink = 0;
177 static void coda_delete_inode(struct inode *inode)
179 struct coda_inode_info *cii;
180 struct inode *open_inode;
182 ENTRY;
183 CDEBUG(D_SUPER, " inode->ino: %ld, count: %d\n",
184 inode->i_ino, inode->i_count);
186 cii = ITOC(inode);
187 if ( inode->i_ino == CTL_INO || cii->c_magic != CODA_CNODE_MAGIC ) {
188 clear_inode(inode);
189 return;
193 if ( ! list_empty(&cii->c_volrootlist) )
194 list_del(&cii->c_volrootlist);
196 open_inode = cii->c_ovp;
197 if ( open_inode ) {
198 CDEBUG(D_SUPER, "DELINO cached file: ino %ld count %d.\n",
199 open_inode->i_ino, open_inode->i_count);
200 cii->c_ovp = NULL;
201 iput(open_inode);
204 coda_cache_clear_inode(inode);
205 CDEBUG(D_DOWNCALL, "clearing inode: %ld, %x\n", inode->i_ino, cii->c_flags);
206 inode->u.generic_ip = NULL;
207 clear_inode(inode);
208 EXIT;
211 static int coda_notify_change(struct dentry *de, struct iattr *iattr)
213 struct inode *inode = de->d_inode;
214 struct coda_inode_info *cii;
215 struct coda_vattr vattr;
216 int error;
218 ENTRY;
219 memset(&vattr, 0, sizeof(vattr));
220 cii = ITOC(inode);
221 CHECK_CNODE(cii);
223 coda_iattr_to_vattr(iattr, &vattr);
224 vattr.va_type = C_VNON; /* cannot set type */
225 CDEBUG(D_SUPER, "vattr.va_mode %o\n", vattr.va_mode);
227 error = venus_setattr(inode->i_sb, &cii->c_fid, &vattr);
229 if ( !error ) {
230 coda_vattr_to_iattr(inode, &vattr);
231 coda_cache_clear_inode(inode);
233 CDEBUG(D_SUPER, "inode.i_mode %o, error %d\n",
234 inode->i_mode, error);
236 EXIT;
237 return error;
240 static int coda_statfs(struct super_block *sb, struct statfs *buf,
241 int bufsiz)
243 struct statfs tmp;
244 int error;
246 memset(&tmp, 0, sizeof(struct statfs));
248 error = venus_statfs(sb, &tmp);
250 if (error) {
251 /* fake something like AFS does */
252 tmp.f_blocks = 9000000;
253 tmp.f_bfree = 9000000;
254 tmp.f_bavail = 9000000;
255 tmp.f_files = 9000000;
256 tmp.f_ffree = 9000000;
259 /* and fill in the rest */
260 tmp.f_type = CODA_SUPER_MAGIC;
261 tmp.f_bsize = 1024;
262 tmp.f_namelen = CODA_MAXNAMLEN;
264 copy_to_user(buf, &tmp, bufsiz);
266 return 0;
270 /* init_coda: used by filesystems.c to register coda */
272 struct file_system_type coda_fs_type = {
273 "coda", 0, coda_read_super, NULL
276 int init_coda_fs(void)
278 return register_filesystem(&coda_fs_type);