Import 2.4.0-test2pre6
[davej-history.git] / fs / coda / cnode.c
blob197855e1db255dab2e87078270ab0c133d0c5d47
1 /* cnode related routines for the coda kernel code
2 (C) 1996 Peter Braam
3 */
5 #include <linux/types.h>
6 #include <linux/string.h>
7 #include <linux/time.h>
9 #include <linux/coda.h>
10 #include <linux/coda_linux.h>
11 #include <linux/coda_fs_i.h>
12 #include <linux/coda_psdev.h>
14 extern int coda_debug;
15 extern int coda_print_entry;
17 inline int coda_fideq(ViceFid *fid1, ViceFid *fid2)
19 if (fid1->Vnode != fid2->Vnode)
20 return 0;
21 if (fid1->Volume != fid2->Volume)
22 return 0;
23 if (fid1->Unique != fid2->Unique)
24 return 0;
25 return 1;
28 static struct inode_operations coda_symlink_inode_operations = {
29 readlink: page_readlink,
30 follow_link: page_follow_link,
31 setattr: coda_notify_change,
34 /* cnode.c */
35 static void coda_fill_inode(struct inode *inode, struct coda_vattr *attr)
37 CDEBUG(D_SUPER, "ino: %ld\n", inode->i_ino);
39 if (coda_debug & D_SUPER )
40 print_vattr(attr);
42 coda_vattr_to_iattr(inode, attr);
44 if (S_ISREG(inode->i_mode)) {
45 inode->i_op = &coda_file_inode_operations;
46 inode->i_fop = &coda_file_operations;
47 } else if (S_ISDIR(inode->i_mode)) {
48 inode->i_op = &coda_dir_inode_operations;
49 inode->i_fop = &coda_dir_operations;
50 } else if (S_ISLNK(inode->i_mode)) {
51 inode->i_op = &coda_symlink_inode_operations;
52 inode->i_data.a_ops = &coda_symlink_aops;
53 } else
54 init_special_inode(inode, inode->i_mode, attr->va_rdev);
57 struct inode * coda_iget(struct super_block * sb, ViceFid * fid,
58 struct coda_vattr * attr)
60 struct inode *inode;
61 struct coda_sb_info *sbi= coda_sbp(sb);
62 struct coda_inode_info *cii;
63 ino_t ino = attr->va_fileid;
65 inode = iget(sb, ino);
66 if ( !inode ) {
67 CDEBUG(D_CNODE, "coda_iget: no inode\n");
68 return NULL;
71 /* check if the inode is already initialized */
72 cii = ITOC(inode);
73 if (cii->c_magic == CODA_CNODE_MAGIC)
74 goto out;
76 /* Initialize the Coda inode info structure */
77 memset(cii, 0, (int) sizeof(struct coda_inode_info));
78 cii->c_magic = CODA_CNODE_MAGIC;
79 cii->c_fid = *fid;
80 cii->c_flags = 0;
81 cii->c_vnode = inode;
82 INIT_LIST_HEAD(&(cii->c_cnhead));
83 INIT_LIST_HEAD(&(cii->c_volrootlist));
85 coda_fill_inode(inode, attr);
87 /* check if it is a weird fid (hashed fid != ino), f.i mountpoints
88 repair object, expanded local-global conflict trees, etc.
90 if ( coda_f2i(fid) == ino )
91 goto out;
93 /* check if we expect this weird fid */
94 if ( !coda_fid_is_weird(fid) )
95 printk("Coda: unknown weird fid: ino %ld, fid %s."
96 "Tell Peter.\n", (long)ino, coda_f2s(&cii->c_fid));
98 /* add the inode to a global list so we can find it back later */
99 list_add(&cii->c_volrootlist, &sbi->sbi_volroothead);
100 CDEBUG(D_CNODE, "Added %ld, %s to volroothead\n",
101 (long)ino, coda_f2s(&cii->c_fid));
102 out:
103 return inode;
106 /* this is effectively coda_iget:
107 - get attributes (might be cached)
108 - get the inode for the fid using vfs iget
109 - link the two up if this is needed
110 - fill in the attributes
112 int coda_cnode_make(struct inode **inode, ViceFid *fid, struct super_block *sb)
114 struct coda_inode_info *cnp;
115 struct coda_vattr attr;
116 int error;
118 ENTRY;
120 /* We get inode numbers from Venus -- see venus source */
122 error = venus_getattr(sb, fid, &attr);
123 if ( error ) {
124 CDEBUG(D_CNODE,
125 "coda_cnode_make: coda_getvattr returned %d for %s.\n",
126 error, coda_f2s(fid));
127 *inode = NULL;
128 return error;
131 *inode = coda_iget(sb, fid, &attr);
132 if ( !(*inode) ) {
133 printk("coda_cnode_make: coda_iget failed\n");
134 return -ENOMEM;
137 cnp = ITOC(*inode);
138 /* see if it is the right one (we might have an inode collision) */
139 if ( coda_fideq(fid, &cnp->c_fid) ) {
140 CDEBUG(D_DOWNCALL,
141 "Done making inode: ino %ld, count %d with %s\n",
142 (*inode)->i_ino, atomic_read(&(*inode)->i_count),
143 coda_f2s(&cnp->c_fid));
144 EXIT;
145 return 0;
148 /* collision */
149 printk("coda_cnode_make on initialized inode %ld, old %s new %s!\n",
150 (*inode)->i_ino, coda_f2s(&cnp->c_fid), coda_f2s2(fid));
151 iput(*inode);
152 EXIT;
153 return -ENOENT;
157 void coda_replace_fid(struct inode *inode, struct ViceFid *oldfid,
158 struct ViceFid *newfid)
160 struct coda_inode_info *cnp;
161 struct coda_sb_info *sbi= coda_sbp(inode->i_sb);
163 cnp = ITOC(inode);
165 if ( ! coda_fideq(&cnp->c_fid, oldfid) )
166 printk("What? oldfid != cnp->c_fid. Call 911.\n");
168 cnp->c_fid = *newfid;
170 list_del(&cnp->c_volrootlist);
171 if ( !coda_fid_is_weird(newfid) )
172 list_add(&cnp->c_volrootlist, &sbi->sbi_volroothead);
174 return;
180 /* convert a fid to an inode. Mostly we can compute
181 the inode number from the FID, but not for volume
182 mount points: those are in a list */
183 struct inode *coda_fid_to_inode(ViceFid *fid, struct super_block *sb)
185 ino_t nr;
186 struct inode *inode;
187 struct coda_inode_info *cnp;
188 ENTRY;
191 if ( !sb ) {
192 printk("coda_fid_to_inode: no sb!\n");
193 return NULL;
196 if ( !fid ) {
197 printk("coda_fid_to_inode: no fid!\n");
198 return NULL;
200 CDEBUG(D_INODE, "%s\n", coda_f2s(fid));
203 if ( coda_fid_is_weird(fid) ) {
204 struct coda_inode_info *cii;
205 struct list_head *lh, *le;
206 struct coda_sb_info *sbi = coda_sbp(sb);
207 le = lh = &sbi->sbi_volroothead;
209 while ( (le = le->next) != lh ) {
210 cii = list_entry(le, struct coda_inode_info,
211 c_volrootlist);
212 CDEBUG(D_DOWNCALL, "iterating, now doing %s, ino %ld\n",
213 coda_f2s(&cii->c_fid), cii->c_vnode->i_ino);
214 if ( coda_fideq(&cii->c_fid, fid) ) {
215 inode = cii->c_vnode;
216 CDEBUG(D_INODE, "volume root, found %ld\n", inode->i_ino);
217 if ( cii->c_magic != CODA_CNODE_MAGIC )
218 printk("%s: Bad magic in inode, tell Peter.\n",
219 __FUNCTION__);
221 iget(sb, inode->i_ino);
222 return inode;
226 return NULL;
229 /* fid is not weird: ino should be computable */
230 nr = coda_f2i(fid);
231 inode = iget(sb, nr);
232 if ( !inode ) {
233 printk("coda_fid_to_inode: null from iget, sb %p, nr %ld.\n",
234 sb, (long)nr);
235 return NULL;
238 /* check if this inode is linked to a cnode */
239 cnp = ITOC(inode);
240 if ( cnp->c_magic != CODA_CNODE_MAGIC ) {
241 CDEBUG(D_INODE, "uninitialized inode. Return.\n");
242 iput(inode);
243 return NULL;
246 /* make sure fid is the one we want;
247 unfortunately Venus will shamelessly send us mount-symlinks.
248 These have the same inode as the root of the volume they
249 mount, but the fid will be wrong.
251 if ( !coda_fideq(fid, &(cnp->c_fid)) ) {
252 /* printk("coda_fid2inode: bad cnode (ino %ld, fid %s)"
253 "Tell Peter.\n", nr, coda_f2s(fid)); */
254 iput(inode);
255 return NULL;
258 CDEBUG(D_INODE, "found %ld\n", inode->i_ino);
259 return inode;
262 /* the CONTROL inode is made without asking attributes from Venus */
263 int coda_cnode_makectl(struct inode **inode, struct super_block *sb)
265 int error = 0;
267 *inode = iget(sb, CTL_INO);
268 if ( *inode ) {
269 (*inode)->i_op = &coda_ioctl_inode_operations;
270 (*inode)->i_fop = &coda_ioctl_operations;
271 (*inode)->i_mode = 00444;
272 error = 0;
273 } else {
274 error = -ENOMEM;
277 return error;