Import 2.3.7pre9
[davej-history.git] / fs / coda / inode.c
blob49359f260c3a9397b3a8467feca77ac1b9f320d0
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/stat.h>
26 #include <asm/uaccess.h>
27 #include <linux/vmalloc.h>
28 #include <asm/segment.h>
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>
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 int coda_notify_change(struct dentry *dentry, struct iattr *attr);
40 static void coda_put_inode(struct inode *);
41 static void coda_delete_inode(struct inode *);
42 static void coda_put_super(struct super_block *);
43 static int coda_statfs(struct super_block *sb, struct statfs *buf,
44 int bufsiz);
46 /* exported operations */
47 struct super_operations coda_super_operations =
49 coda_read_inode, /* read_inode */
50 NULL, /* write_inode */
51 coda_put_inode, /* put_inode */
52 coda_delete_inode, /* delete_inode */
53 coda_notify_change, /* notify_change */
54 coda_put_super, /* put_super */
55 NULL, /* write_super */
56 coda_statfs, /* statfs */
57 NULL /* remount_fs */
60 static struct super_block * coda_read_super(struct super_block *sb,
61 void *data, int silent)
63 struct inode *psdev = 0, *root = 0;
64 struct coda_sb_info *sbi = NULL;
65 struct venus_comm *vc = NULL;
66 ViceFid fid;
67 kdev_t dev = sb->s_dev;
68 int error;
70 ENTRY;
71 MOD_INC_USE_COUNT;
73 vc = &coda_upc_comm;
74 sbi = &coda_super_info;
76 if ( sbi->sbi_sb ) {
77 printk("Already mounted\n");
78 return NULL;
81 sbi->sbi_sb = sb;
82 sbi->sbi_psdev = psdev;
83 sbi->sbi_vcomm = vc;
84 INIT_LIST_HEAD(&(sbi->sbi_cchead));
85 INIT_LIST_HEAD(&(sbi->sbi_volroothead));
87 lock_super(sb);
88 sb->u.generic_sbp = sbi;
89 sb->s_blocksize = 1024; /* XXXXX what do we put here?? */
90 sb->s_blocksize_bits = 10;
91 sb->s_magic = CODA_SUPER_MAGIC;
92 sb->s_dev = dev;
93 sb->s_op = &coda_super_operations;
95 /* get root fid from Venus: this needs the root inode */
96 error = venus_rootfid(sb, &fid);
97 if ( error ) {
98 printk("coda_read_super: coda_get_rootfid failed with %d\n",
99 error);
100 sb->s_dev = 0;
101 unlock_super(sb);
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 unlock_super(sb);
112 goto error;
115 printk("coda_read_super: rootinode is %ld dev %d\n",
116 root->i_ino, root->i_dev);
117 sbi->sbi_root = root;
118 sb->s_root = d_alloc_root(root);
119 unlock_super(sb);
120 EXIT;
121 return sb;
123 error:
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 /* sb_info->sbi_vcomm->vc_inuse = 0; You can not do this: psdev_release would see usagecount == 0 and would refuse to decrease MOD_USE_COUNT --pavel */
149 coda_super_info.sbi_sb = NULL;
150 printk("Coda: Bye bye.\n");
151 memset(sb_info, 0, sizeof(* sb_info));
153 MOD_DEC_USE_COUNT;
154 EXIT;
157 /* all filling in of inodes postponed until lookup */
158 static void coda_read_inode(struct inode *inode)
160 struct coda_inode_info *cii;
161 ENTRY;
162 cii = ITOC(inode);
163 cii->c_magic = 0;
164 return;
167 static void coda_put_inode(struct inode *in)
169 ENTRY;
171 CDEBUG(D_INODE,"ino: %ld, count %d\n", in->i_ino, in->i_count);
173 if ( in->i_count == 1 )
174 in->i_nlink = 0;
178 static void coda_delete_inode(struct inode *inode)
180 struct coda_inode_info *cii;
181 struct inode *open_inode;
183 ENTRY;
184 CDEBUG(D_SUPER, " inode->ino: %ld, count: %d\n",
185 inode->i_ino, inode->i_count);
187 cii = ITOC(inode);
188 if ( inode->i_ino == CTL_INO || cii->c_magic != CODA_CNODE_MAGIC ) {
189 clear_inode(inode);
190 return;
194 if ( ! list_empty(&cii->c_volrootlist) )
195 list_del(&cii->c_volrootlist);
197 open_inode = cii->c_ovp;
198 if ( open_inode ) {
199 CDEBUG(D_SUPER, "DELINO cached file: ino %ld count %d.\n",
200 open_inode->i_ino, open_inode->i_count);
201 cii->c_ovp = NULL;
202 iput(open_inode);
205 coda_cache_clear_inode(inode);
206 CDEBUG(D_DOWNCALL, "clearing inode: %ld, %x\n", inode->i_ino, cii->c_flags);
207 inode->u.generic_ip = NULL;
208 clear_inode(inode);
209 EXIT;
212 static int coda_notify_change(struct dentry *de, struct iattr *iattr)
214 struct inode *inode = de->d_inode;
215 struct coda_inode_info *cii;
216 struct coda_vattr vattr;
217 int error;
219 ENTRY;
220 memset(&vattr, 0, sizeof(vattr));
221 cii = ITOC(inode);
222 CHECK_CNODE(cii);
224 coda_iattr_to_vattr(iattr, &vattr);
225 vattr.va_type = C_VNON; /* cannot set type */
226 CDEBUG(D_SUPER, "vattr.va_mode %o\n", vattr.va_mode);
228 error = venus_setattr(inode->i_sb, &cii->c_fid, &vattr);
230 if ( !error ) {
231 coda_vattr_to_iattr(inode, &vattr);
232 coda_cache_clear_inode(inode);
234 CDEBUG(D_SUPER, "inode.i_mode %o, error %d\n",
235 inode->i_mode, error);
237 EXIT;
238 return error;
241 /* we need _something_ for this routine. Let's mimic AFS */
242 static int coda_statfs(struct super_block *sb, struct statfs *buf,
243 int bufsiz)
245 struct statfs tmp;
247 tmp.f_type = CODA_SUPER_MAGIC;
248 tmp.f_bsize = 1024;
249 tmp.f_blocks = 9000000;
250 tmp.f_bfree = 9000000;
251 tmp.f_bavail = 9000000 ;
252 tmp.f_files = 9000000;
253 tmp.f_ffree = 9000000;
254 tmp.f_namelen = 0;
255 copy_to_user(buf, &tmp, bufsiz);
256 return 0;
260 /* init_coda: used by filesystems.c to register coda */
262 struct file_system_type coda_fs_type = {
263 "coda", 0, coda_read_super, NULL
266 int init_coda_fs(void)
268 return register_filesystem(&coda_fs_type);