1 /* cnode related routines for the coda kernel code
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
)
21 if (fid1
->Volume
!= fid2
->Volume
)
23 if (fid1
->Unique
!= fid2
->Unique
)
29 static void coda_fill_inode(struct inode
*inode
, struct coda_vattr
*attr
)
31 CDEBUG(D_SUPER
, "ino: %ld\n", inode
->i_ino
);
33 if (coda_debug
& D_SUPER
)
36 coda_vattr_to_iattr(inode
, attr
);
38 if (S_ISREG(inode
->i_mode
))
39 inode
->i_op
= &coda_file_inode_operations
;
40 else if (S_ISDIR(inode
->i_mode
))
41 inode
->i_op
= &coda_dir_inode_operations
;
42 else if (S_ISLNK(inode
->i_mode
))
43 inode
->i_op
= &coda_symlink_inode_operations
;
45 init_special_inode(inode
, inode
->i_mode
, attr
->va_rdev
);
48 /* this is effectively coda_iget:
49 - get attributes (might be cached)
50 - get the inode for the fid using vfs iget
51 - link the two up if this is needed
52 - fill in the attributes
54 int coda_cnode_make(struct inode
**inode
, ViceFid
*fid
, struct super_block
*sb
)
56 struct coda_inode_info
*cnp
;
57 struct coda_sb_info
*sbi
= coda_sbp(sb
);
58 struct coda_vattr attr
;
65 * We get inode numbers from Venus -- see venus source
68 error
= venus_getattr(sb
, fid
, &attr
);
71 "coda_cnode_make: coda_getvattr returned %d for %s.\n",
72 error
, coda_f2s(fid
));
78 *inode
= iget(sb
, ino
);
80 printk("coda_cnode_make: iget failed\n");
85 /* see if we've got it already */
86 if ( cnp
->c_magic
!= 0 && coda_fideq(fid
, &cnp
->c_fid
)) {
90 /* not fresh: collision */
91 if ( cnp
->c_magic
!= 0 ) {
92 printk("coda_cnode_make on initialized inode %ld, old %s new
94 (*inode
)->i_ino
, coda_f2s(&cnp
->c_fid
), coda_f2s2(fid
));
99 memset(cnp
, 0, (int) sizeof(struct coda_inode_info
));
101 cnp
->c_magic
= CODA_CNODE_MAGIC
;
103 cnp
->c_vnode
= *inode
;
104 INIT_LIST_HEAD(&(cnp
->c_cnhead
));
105 INIT_LIST_HEAD(&(cnp
->c_volrootlist
));
107 /* fill in the inode attributes */
108 if ( coda_f2i(fid
) != ino
) {
109 if ( !coda_fid_is_weird(fid
) )
110 printk("Coda: unknown weird fid: ino %ld, fid %s."
111 "Tell Peter.\n", (long)ino
, coda_f2s(&cnp
->c_fid
));
112 list_add(&cnp
->c_volrootlist
, &sbi
->sbi_volroothead
);
113 CDEBUG(D_UPCALL
, "Added %ld ,%s to volroothead\n",
114 (long)ino
, coda_f2s(&cnp
->c_fid
));
117 coda_fill_inode(*inode
, &attr
);
118 CDEBUG(D_DOWNCALL
, "Done making inode: ino %ld, count %d with %s\n",
119 (*inode
)->i_ino
, (*inode
)->i_count
,
120 coda_f2s(&cnp
->c_fid
));
127 void coda_replace_fid(struct inode
*inode
, struct ViceFid
*oldfid
,
128 struct ViceFid
*newfid
)
130 struct coda_inode_info
*cnp
;
131 struct coda_sb_info
*sbi
= coda_sbp(inode
->i_sb
);
135 if ( ! coda_fideq(&cnp
->c_fid
, oldfid
) )
136 printk("What? oldfid != cnp->c_fid. Call 911.\n");
138 cnp
->c_fid
= *newfid
;
140 list_del(&cnp
->c_volrootlist
);
141 if ( !coda_fid_is_weird(newfid
) )
142 list_add(&cnp
->c_volrootlist
, &sbi
->sbi_volroothead
);
150 /* convert a fid to an inode. Mostly we can compute
151 the inode number from the FID, but not for volume
152 mount points: those are in a list */
153 struct inode
*coda_fid_to_inode(ViceFid
*fid
, struct super_block
*sb
)
157 struct coda_inode_info
*cnp
;
162 printk("coda_fid_to_inode: no sb!\n");
167 printk("coda_fid_to_inode: no fid!\n");
170 CDEBUG(D_INODE
, "%s\n", coda_f2s(fid
));
173 if ( coda_fid_is_weird(fid
) ) {
174 struct coda_inode_info
*cii
;
175 struct list_head
*lh
, *le
;
176 struct coda_sb_info
*sbi
= coda_sbp(sb
);
177 le
= lh
= &sbi
->sbi_volroothead
;
179 while ( (le
= le
->next
) != lh
) {
180 cii
= list_entry(le
, struct coda_inode_info
,
182 CDEBUG(D_DOWNCALL
, "iterating, now doing %s, ino %ld\n",
183 coda_f2s(&cii
->c_fid
), cii
->c_vnode
->i_ino
);
184 if ( coda_fideq(&cii
->c_fid
, fid
) ) {
185 inode
= cii
->c_vnode
;
186 CDEBUG(D_INODE
, "volume root, found %ld\n", cii
->c_vnode
->i_ino
);
187 if ( cii
->c_magic
!= CODA_CNODE_MAGIC
)
188 printk("%s: Bad magic in inode, tell Peter.\n",
197 /* fid is not weird: ino should be computable */
199 inode
= iget(sb
, nr
);
201 printk("coda_fid_to_inode: null from iget, sb %p, nr %ld.\n",
206 /* check if this inode is linked to a cnode */
208 if ( cnp
->c_magic
!= CODA_CNODE_MAGIC
) {
209 CDEBUG(D_INODE
, "uninitialized inode. Return.\n");
214 /* make sure fid is the one we want;
215 unfortunately Venus will shamelessly send us mount-symlinks.
216 These have the same inode as the root of the volume they
217 mount, but the fid will be wrong.
219 if ( !coda_fideq(fid
, &(cnp
->c_fid
)) ) {
220 /* printk("coda_fid2inode: bad cnode (ino %ld, fid %s)"
221 "Tell Peter.\n", nr, coda_f2s(fid)); */
226 CDEBUG(D_INODE
, "found %ld\n", inode
->i_ino
);
231 /* the CONTROL inode is made without asking attributes from Venus */
232 int coda_cnode_makectl(struct inode
**inode
, struct super_block
*sb
)
236 *inode
= iget(sb
, CTL_INO
);
238 (*inode
)->i_op
= &coda_ioctl_inode_operations
;
239 (*inode
)->i_mode
= 00444;