1 /* cnode related routines for the coda kernel code
5 #include <linux/types.h>
6 #include <linux/time.h>
8 #include <linux/coda.h>
9 #include <linux/coda_linux.h>
10 #include <linux/coda_fs_i.h>
11 #include <linux/coda_psdev.h>
13 extern int coda_debug
;
14 extern int coda_print_entry
;
18 static void coda_fill_inode(struct inode
*inode
, struct coda_vattr
*attr
)
20 CDEBUG(D_SUPER
, "ino: %ld\n", inode
->i_ino
);
22 if (coda_debug
& D_SUPER
)
25 coda_vattr_to_iattr(inode
, attr
);
27 if (S_ISREG(inode
->i_mode
))
28 inode
->i_op
= &coda_file_inode_operations
;
29 else if (S_ISDIR(inode
->i_mode
))
30 inode
->i_op
= &coda_dir_inode_operations
;
31 else if (S_ISLNK(inode
->i_mode
))
32 inode
->i_op
= &coda_symlink_inode_operations
;
33 else if (S_ISCHR(inode
->i_mode
)) {
34 inode
->i_op
= &chrdev_inode_operations
;
35 inode
->i_rdev
= to_kdev_t(attr
->va_rdev
);
36 } else if (S_ISBLK(inode
->i_mode
)) {
37 inode
->i_op
= &blkdev_inode_operations
;
38 inode
->i_rdev
= to_kdev_t(attr
->va_rdev
);
39 } else if (S_ISFIFO(inode
->i_mode
))
41 else if (S_ISSOCK(inode
->i_mode
))
44 printk ("coda_read_inode: what's this? i_mode = %o\n",
50 /* this is effectively coda_iget:
51 - get attributes (might be cached)
52 - get the inode for the fid using vfs iget
53 - link the two up if this is needed
54 - fill in the attributes
56 int coda_cnode_make(struct inode
**inode
, ViceFid
*fid
, struct super_block
*sb
)
58 struct coda_inode_info
*cnp
;
59 struct coda_sb_info
*sbi
= coda_sbp(sb
);
60 struct coda_vattr attr
;
67 * We get inode numbers from Venus -- see venus source
70 error
= venus_getattr(sb
, fid
, &attr
);
72 CDEBUG(D_CNODE
, "coda_cnode_make: coda_getvattr returned %d for %s.\n",
73 error
, coda_f2s(fid
));
79 *inode
= iget(sb
, ino
);
81 printk("coda_cnode_make: iget failed\n");
86 if ( cnp
->c_magic
== 0 ) {
87 memset(cnp
, 0, (int) sizeof(struct coda_inode_info
));
89 cnp
->c_magic
= CODA_CNODE_MAGIC
;
91 cnp
->c_vnode
= *inode
;
92 INIT_LIST_HEAD(&(cnp
->c_cnhead
));
93 INIT_LIST_HEAD(&(cnp
->c_volrootlist
));
96 CDEBUG(D_CNODE
, "coda_cnode make on initialized"
98 (*inode
)->i_ino
, coda_f2s(&cnp
->c_fid
));
101 /* fill in the inode attributes */
102 if ( coda_f2i(fid
) != ino
) {
103 if ( !coda_fid_is_weird(fid
) )
104 printk("Coda: unknown weird fid: ino %ld, fid %s."
105 "Tell Peter.\n", ino
, coda_f2s(&cnp
->c_fid
));
106 list_add(&cnp
->c_volrootlist
, &sbi
->sbi_volroothead
);
107 CDEBUG(D_UPCALL
, "Added %ld ,%s to volroothead\n",
108 ino
, coda_f2s(&cnp
->c_fid
));
111 coda_fill_inode(*inode
, &attr
);
112 CDEBUG(D_DOWNCALL
, "Done making inode: ino %ld, count %d with %s\n",
113 (*inode
)->i_ino
, (*inode
)->i_count
,
114 coda_f2s(&cnp
->c_fid
));
121 inline int coda_fideq(ViceFid
*fid1
, ViceFid
*fid2
)
124 eq
= ( (fid1
->Vnode
== fid2
->Vnode
) &&
125 (fid1
->Volume
== fid2
->Volume
) &&
126 (fid1
->Unique
== fid2
->Unique
) );
132 /* convert a fid to an inode. Mostly we can compute
133 the inode number from the FID, but not for volume
134 mount points: those are in a list */
135 struct inode
*coda_fid_to_inode(ViceFid
*fid
, struct super_block
*sb
)
139 struct coda_inode_info
*cnp
;
144 printk("coda_fid_to_inode: no sb!\n");
149 printk("coda_fid_to_inode: no fid!\n");
152 CDEBUG(D_INODE
, "%s\n", coda_f2s(fid
));
155 if ( coda_fid_is_weird(fid
) ) {
156 struct coda_inode_info
*cii
;
157 struct list_head
*lh
, *le
;
158 struct coda_sb_info
*sbi
= coda_sbp(sb
);
159 le
= lh
= &sbi
->sbi_volroothead
;
161 while ( (le
= le
->next
) != lh
) {
162 cii
= list_entry(le
, struct coda_inode_info
,
164 CDEBUG(D_DOWNCALL
, "iterating, now doing %s, ino %ld\n",
165 coda_f2s(&cii
->c_fid
), cii
->c_vnode
->i_ino
);
166 if ( coda_fideq(&cii
->c_fid
, fid
) ) {
167 inode
= cii
->c_vnode
;
168 CDEBUG(D_INODE
, "volume root, found %ld\n", cii
->c_vnode
->i_ino
);
169 if ( cii
->c_magic
!= CODA_CNODE_MAGIC
)
170 printk("%s: Bad magic in inode, tell Peter.\n",
179 /* fid is not weird: ino should be computable */
181 inode
= iget(sb
, nr
);
183 printk("coda_fid_to_inode: null from iget, sb %p, nr %ld.\n",
188 /* check if this inode is linked to a cnode */
190 if ( cnp
->c_magic
!= CODA_CNODE_MAGIC
) {
191 CDEBUG(D_INODE
, "uninitialized inode. Return.\n");
196 /* make sure fid is the one we want;
197 unfortunately Venus will shamelessly send us mount-symlinks.
198 These have the same inode as the root of the volume they
199 mount, but the fid will be wrong.
201 if ( !coda_fideq(fid
, &(cnp
->c_fid
)) ) {
202 /* printk("coda_fid2inode: bad cnode (ino %ld, fid %s)"
203 "Tell Peter.\n", nr, coda_f2s(fid)); */
208 CDEBUG(D_INODE
, "found %ld\n", inode
->i_ino
);
213 /* the CONTROL inode is made without asking attributes from Venus */
214 int coda_cnode_makectl(struct inode
**inode
, struct super_block
*sb
)
218 *inode
= iget(sb
, CTL_INO
);
220 (*inode
)->i_op
= &coda_ioctl_inode_operations
;
221 (*inode
)->i_mode
= 00444;