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/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
,
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 */
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
;
67 kdev_t dev
= sb
->s_dev
;
74 sbi
= &coda_super_info
;
77 printk("Already mounted\n");
82 sbi
->sbi_psdev
= psdev
;
84 INIT_LIST_HEAD(&(sbi
->sbi_cchead
));
85 INIT_LIST_HEAD(&(sbi
->sbi_volroothead
));
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
;
93 sb
->s_op
= &coda_super_operations
;
95 /* get root fid from Venus: this needs the root inode */
96 error
= venus_rootfid(sb
, &fid
);
98 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
);
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
);
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 /* 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
));
157 /* all filling in of inodes postponed until lookup */
158 static void coda_read_inode(struct inode
*inode
)
160 struct coda_inode_info
*cii
;
167 static void coda_put_inode(struct inode
*in
)
171 CDEBUG(D_INODE
,"ino: %ld, count %d\n", in
->i_ino
, in
->i_count
);
173 if ( in
->i_count
== 1 )
178 static void coda_delete_inode(struct inode
*inode
)
180 struct coda_inode_info
*cii
;
181 struct inode
*open_inode
;
184 CDEBUG(D_SUPER
, " inode->ino: %ld, count: %d\n",
185 inode
->i_ino
, inode
->i_count
);
188 if ( inode
->i_ino
== CTL_INO
|| cii
->c_magic
!= CODA_CNODE_MAGIC
) {
194 if ( ! list_empty(&cii
->c_volrootlist
) )
195 list_del(&cii
->c_volrootlist
);
197 open_inode
= cii
->c_ovp
;
199 CDEBUG(D_SUPER
, "DELINO cached file: ino %ld count %d.\n",
200 open_inode
->i_ino
, open_inode
->i_count
);
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
;
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
;
220 memset(&vattr
, 0, sizeof(vattr
));
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
);
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
);
241 /* we need _something_ for this routine. Let's mimic AFS */
242 static int coda_statfs(struct super_block
*sb
, struct statfs
*buf
,
247 tmp
.f_type
= CODA_SUPER_MAGIC
;
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;
255 copy_to_user(buf
, &tmp
, bufsiz
);
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
);