pre-2.1.109-2..
[davej-history.git] / fs / coda / cnode.c
blob2f0f868789b6e0c5424f4289785c62cdc8a68b87
1 /* cnode related routines for the coda kernel code
2 (C) 1996 Peter Braam
3 */
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;
16 /* cnode.c */
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 )
23 print_vattr(attr);
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))
40 init_fifo(inode);
41 else if (S_ISSOCK(inode->i_mode))
42 inode->i_op = NULL;
43 else {
44 printk ("coda_read_inode: what's this? i_mode = %o\n",
45 inode->i_mode);
46 inode->i_op = NULL;
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;
61 int error;
62 ino_t ino;
64 ENTRY;
66 /*
67 * We get inode numbers from Venus -- see venus source
70 error = venus_getattr(sb, fid, &attr);
71 if ( error ) {
72 CDEBUG(D_CNODE, "coda_cnode_make: coda_getvattr returned %d for %s.\n",
73 error, coda_f2s(fid));
74 *inode = NULL;
75 return error;
78 ino = attr.va_fileid;
79 *inode = iget(sb, ino);
80 if ( !*inode ) {
81 printk("coda_cnode_make: iget failed\n");
82 return -ENOMEM;
85 cnp = ITOC(*inode);
86 if ( cnp->c_magic == 0 ) {
87 memset(cnp, 0, (int) sizeof(struct coda_inode_info));
88 cnp->c_fid = *fid;
89 cnp->c_magic = CODA_CNODE_MAGIC;
90 cnp->c_flags = 0;
91 cnp->c_vnode = *inode;
92 INIT_LIST_HEAD(&(cnp->c_cnhead));
93 INIT_LIST_HEAD(&(cnp->c_volrootlist));
94 } else {
95 cnp->c_flags = 0;
96 CDEBUG(D_CNODE, "coda_cnode make on initialized"
97 "inode %ld, %s!\n",
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));
116 EXIT;
117 return 0;
121 inline int coda_fideq(ViceFid *fid1, ViceFid *fid2)
123 int eq;
124 eq = ( (fid1->Vnode == fid2->Vnode) &&
125 (fid1->Volume == fid2->Volume) &&
126 (fid1->Unique == fid2->Unique) );
127 return eq;
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)
137 ino_t nr;
138 struct inode *inode;
139 struct coda_inode_info *cnp;
140 ENTRY;
143 if ( !sb ) {
144 printk("coda_fid_to_inode: no sb!\n");
145 return NULL;
148 if ( !fid ) {
149 printk("coda_fid_to_inode: no fid!\n");
150 return NULL;
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,
163 c_volrootlist);
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",
171 __FUNCTION__);
172 return cii->c_vnode;
176 return NULL;
179 /* fid is not weird: ino should be computable */
180 nr = coda_f2i(fid);
181 inode = iget(sb, nr);
182 if ( !inode ) {
183 printk("coda_fid_to_inode: null from iget, sb %p, nr %ld.\n",
184 sb, nr);
185 return NULL;
188 /* check if this inode is linked to a cnode */
189 cnp = ITOC(inode);
190 if ( cnp->c_magic != CODA_CNODE_MAGIC ) {
191 CDEBUG(D_INODE, "uninitialized inode. Return.\n");
192 iput(inode);
193 return NULL;
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)); */
204 iput(inode);
205 return NULL;
208 CDEBUG(D_INODE, "found %ld\n", inode->i_ino);
209 iput(inode);
210 return inode;
213 /* the CONTROL inode is made without asking attributes from Venus */
214 int coda_cnode_makectl(struct inode **inode, struct super_block *sb)
216 int error = 0;
218 *inode = iget(sb, CTL_INO);
219 if ( *inode ) {
220 (*inode)->i_op = &coda_ioctl_inode_operations;
221 (*inode)->i_mode = 00444;
222 error = 0;
223 } else {
224 error = -ENOMEM;
227 return error;