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>
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>
20 #include <linux/smp_lock.h>
22 #include <asm/system.h>
23 #include <asm/uaccess.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
,
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
;
58 kdev_t dev
= sb
->s_dev
;
64 sbi
= &coda_super_info
;
67 printk("Already mounted\n");
73 sbi
->sbi_psdev
= psdev
;
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
;
83 sb
->s_op
= &coda_super_operations
;
85 /* get root fid from Venus: this needs the root inode */
86 error
= venus_rootfid(sb
, &fid
);
88 printk("coda_read_super: coda_get_rootfid failed with %d\n",
92 printk("coda_read_super: rootfid is %s\n", coda_f2s(&fid
));
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
);
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
);
111 sbi
->sbi_vcomm
= NULL
;
112 sbi
->sbi_root
= NULL
;
121 static void coda_put_super(struct super_block
*sb
)
123 struct coda_sb_info
*sb_info
;
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
));
136 /* all filling in of inodes postponed until lookup */
137 static void coda_read_inode(struct inode
*inode
)
139 struct coda_inode_info
*cii
;
146 static void coda_clear_inode(struct inode
*inode
)
148 struct coda_inode_info
*cii
= ITOC(inode
);
149 struct inode
*open_inode
;
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
)
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
;
173 coda_cache_clear_inode(inode
);
176 CDEBUG(D_DOWNCALL
, "clearing inode: %ld, %x\n", inode
->i_ino
, cii
->c_flags
);
178 inode
->u
.coda_i
.c_magic
= 0;
182 int coda_notify_change(struct dentry
*de
, struct iattr
*iattr
)
184 struct inode
*inode
= de
->d_inode
;
185 struct coda_vattr vattr
;
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
);
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
);
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
)
218 error
= venus_statfs(sb
, buf
);
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
;
232 buf
->f_namelen
= CODA_MAXNAMLEN
;
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
);