Fix reported Samba bug.
[linux-2.6/linux-mips.git] / fs / coda / inode.c
blob84191c4942835cfed4181189e23dcdc9525f4463
1 /*
2 * Super block/filesystem wide operations
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 */
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>
22 #include <asm/system.h>
23 #include <asm/uaccess.h>
25 #include <linux/fs.h>
26 #include <linux/vmalloc.h>
27 #include <asm/segment.h>
29 #include <linux/coda.h>
30 #include <linux/coda_linux.h>
31 #include <linux/coda_psdev.h>
32 #include <linux/coda_fs_i.h>
33 #include <linux/coda_cache.h>
35 /* VFS super_block ops */
36 static struct super_block *coda_read_super(struct super_block *, void *, int);
37 static void coda_read_inode(struct inode *);
38 static void coda_clear_inode(struct inode *);
39 static void coda_put_super(struct super_block *);
40 static int coda_statfs(struct super_block *sb, struct statfs *buf);
42 /* exported operations */
43 struct super_operations coda_super_operations =
45 read_inode: coda_read_inode,
46 clear_inode: coda_clear_inode,
47 put_super: coda_put_super,
48 statfs: coda_statfs,
51 static struct super_block * coda_read_super(struct super_block *sb,
52 void *data, int silent)
54 struct inode *psdev = 0, *root = 0;
55 struct coda_sb_info *sbi = NULL;
56 struct venus_comm *vc = NULL;
57 ViceFid fid;
58 kdev_t dev = sb->s_dev;
59 int error;
61 ENTRY;
63 vc = &coda_upc_comm;
64 sbi = &coda_super_info;
66 if ( sbi->sbi_sb ) {
67 printk("Already mounted\n");
68 EXIT;
69 return NULL;
72 sbi->sbi_sb = sb;
73 sbi->sbi_psdev = psdev;
74 sbi->sbi_vcomm = vc;
75 INIT_LIST_HEAD(&(sbi->sbi_cchead));
76 INIT_LIST_HEAD(&(sbi->sbi_volroothead));
78 sb->u.generic_sbp = sbi;
79 sb->s_blocksize = 1024; /* XXXXX what do we put here?? */
80 sb->s_blocksize_bits = 10;
81 sb->s_magic = CODA_SUPER_MAGIC;
82 sb->s_dev = dev;
83 sb->s_op = &coda_super_operations;
85 /* get root fid from Venus: this needs the root inode */
86 error = venus_rootfid(sb, &fid);
87 if ( error ) {
88 printk("coda_read_super: coda_get_rootfid failed with %d\n",
89 error);
90 goto error;
92 printk("coda_read_super: rootfid is %s\n", coda_f2s(&fid));
94 /* make root inode */
95 error = coda_cnode_make(&root, &fid, sb);
96 if ( error || !root ) {
97 printk("Failure of coda_cnode_make for root: error %d\n", error);
98 goto error;
101 printk("coda_read_super: rootinode is %ld dev %d\n",
102 root->i_ino, root->i_dev);
103 sbi->sbi_root = root;
104 sb->s_root = d_alloc_root(root);
105 EXIT;
106 return sb;
108 error:
109 EXIT;
110 if (sbi) {
111 sbi->sbi_vcomm = NULL;
112 sbi->sbi_root = NULL;
113 sbi->sbi_sb = NULL;
115 if (root) {
116 iput(root);
118 return NULL;
121 static void coda_put_super(struct super_block *sb)
123 struct coda_sb_info *sb_info;
125 ENTRY;
127 coda_cache_clear_all(sb);
128 sb_info = coda_sbp(sb);
129 coda_super_info.sbi_sb = NULL;
130 printk("Coda: Bye bye.\n");
131 memset(sb_info, 0, sizeof(* sb_info));
133 EXIT;
136 /* all filling in of inodes postponed until lookup */
137 static void coda_read_inode(struct inode *inode)
139 struct coda_inode_info *cii;
140 ENTRY;
141 cii = ITOC(inode);
142 cii->c_magic = 0;
143 return;
146 static void coda_clear_inode(struct inode *inode)
148 struct coda_inode_info *cii = ITOC(inode);
149 struct inode *open_inode;
151 ENTRY;
152 CDEBUG(D_SUPER, " inode->ino: %ld, count: %d\n",
153 inode->i_ino, atomic_read(&inode->i_count));
155 if ( inode->i_ino == CTL_INO || cii->c_magic != CODA_CNODE_MAGIC )
156 goto out;
158 lock_kernel();
160 if ( !list_empty(&cii->c_volrootlist) ) {
161 list_del(&cii->c_volrootlist);
162 INIT_LIST_HEAD(&cii->c_volrootlist);
165 if ( inode->i_mapping != &inode->i_data ) {
166 open_inode = (struct inode *)inode->i_mapping->host;
167 CDEBUG(D_SUPER, "DELINO cached file: ino %ld count %d.\n",
168 open_inode->i_ino, atomic_read(&open_inode->i_count));
169 inode->i_mapping = &inode->i_data;
170 iput(open_inode);
173 coda_cache_clear_inode(inode);
174 unlock_kernel();
176 CDEBUG(D_DOWNCALL, "clearing inode: %ld, %x\n", inode->i_ino, cii->c_flags);
177 out:
178 inode->u.coda_i.c_magic = 0;
179 EXIT;
182 int coda_notify_change(struct dentry *de, struct iattr *iattr)
184 struct inode *inode = de->d_inode;
185 struct coda_vattr vattr;
186 int error;
188 ENTRY;
189 memset(&vattr, 0, sizeof(vattr));
191 coda_iattr_to_vattr(iattr, &vattr);
192 vattr.va_type = C_VNON; /* cannot set type */
193 CDEBUG(D_SUPER, "vattr.va_mode %o\n", vattr.va_mode);
195 /* Venus is responsible for truncating the container-file!!! */
196 error = venus_setattr(inode->i_sb, coda_i2f(inode), &vattr);
198 if ( !error ) {
199 coda_vattr_to_iattr(inode, &vattr);
200 coda_cache_clear_inode(inode);
202 CDEBUG(D_SUPER, "inode.i_mode %o, error %d\n", inode->i_mode, error);
204 EXIT;
205 return error;
208 struct inode_operations coda_file_inode_operations = {
209 permission: coda_permission,
210 revalidate: coda_revalidate_inode,
211 setattr: coda_notify_change,
214 static int coda_statfs(struct super_block *sb, struct statfs *buf)
216 int error;
218 error = venus_statfs(sb, buf);
220 if (error) {
221 /* fake something like AFS does */
222 buf->f_blocks = 9000000;
223 buf->f_bfree = 9000000;
224 buf->f_bavail = 9000000;
225 buf->f_files = 9000000;
226 buf->f_ffree = 9000000;
229 /* and fill in the rest */
230 buf->f_type = CODA_SUPER_MAGIC;
231 buf->f_bsize = 1024;
232 buf->f_namelen = CODA_MAXNAMLEN;
234 return 0;
237 /* init_coda: used by filesystems.c to register coda */
239 DECLARE_FSTYPE( coda_fs_type, "coda", coda_read_super, 0);
241 int init_coda_fs(void)
243 return register_filesystem(&coda_fs_type);