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>
7 * Rewritten for Linux 2.1. Peter Braam <braam@cs.cmu.edu>
8 * Copyright (C) Carnegie Mellon University
11 #define __NO_VERSION__
12 #include <linux/module.h>
13 #include <linux/kernel.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>
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
,
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 */
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
;
65 kdev_t dev
= sb
->s_dev
;
72 sbi
= &coda_super_info
;
75 printk("Already mounted\n");
83 sbi
->sbi_psdev
= psdev
;
85 INIT_LIST_HEAD(&(sbi
->sbi_cchead
));
86 INIT_LIST_HEAD(&(sbi
->sbi_volroothead
));
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
;
94 sb
->s_op
= &coda_super_operations
;
96 /* get root fid from Venus: this needs the root inode */
97 error
= venus_rootfid(sb
, &fid
);
99 printk("coda_read_super: coda_get_rootfid failed with %d\n",
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
);
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
);
127 sbi
->sbi_vcomm
= NULL
;
128 sbi
->sbi_root
= NULL
;
138 static void coda_put_super(struct super_block
*sb
)
140 struct coda_sb_info
*sb_info
;
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
));
156 /* all filling in of inodes postponed until lookup */
157 static void coda_read_inode(struct inode
*inode
)
159 struct coda_inode_info
*cii
;
166 static void coda_put_inode(struct inode
*in
)
170 CDEBUG(D_INODE
,"ino: %ld, count %d\n", in
->i_ino
, in
->i_count
);
172 if ( in
->i_count
== 1 )
177 static void coda_delete_inode(struct inode
*inode
)
179 struct coda_inode_info
*cii
;
180 struct inode
*open_inode
;
183 CDEBUG(D_SUPER
, " inode->ino: %ld, count: %d\n",
184 inode
->i_ino
, inode
->i_count
);
187 if ( inode
->i_ino
== CTL_INO
|| cii
->c_magic
!= CODA_CNODE_MAGIC
) {
193 if ( ! list_empty(&cii
->c_volrootlist
) )
194 list_del(&cii
->c_volrootlist
);
196 open_inode
= cii
->c_ovp
;
198 CDEBUG(D_SUPER
, "DELINO cached file: ino %ld count %d.\n",
199 open_inode
->i_ino
, open_inode
->i_count
);
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
;
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
;
219 memset(&vattr
, 0, sizeof(vattr
));
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
);
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
);
240 static int coda_statfs(struct super_block
*sb
, struct statfs
*buf
,
246 memset(&tmp
, 0, sizeof(struct statfs
));
248 error
= venus_statfs(sb
, &tmp
);
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
;
262 tmp
.f_namelen
= CODA_MAXNAMLEN
;
264 copy_to_user(buf
, &tmp
, bufsiz
);
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
);