Merge master.kernel.org:/pub/scm/linux/kernel/git/dtor/input
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / fs / coda / cnode.c
blob23aeef5aa8144a94dc69ea5abfc29ab286da77d7
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 static inline int coda_fideq(struct CodaFid *fid1, struct CodaFid *fid2)
16 return memcmp(fid1, fid2, sizeof(*fid1)) == 0;
19 static struct inode_operations coda_symlink_inode_operations = {
20 .readlink = generic_readlink,
21 .follow_link = page_follow_link_light,
22 .put_link = page_put_link,
23 .setattr = coda_setattr,
26 /* cnode.c */
27 static void coda_fill_inode(struct inode *inode, struct coda_vattr *attr)
29 coda_vattr_to_iattr(inode, attr);
31 if (S_ISREG(inode->i_mode)) {
32 inode->i_op = &coda_file_inode_operations;
33 inode->i_fop = &coda_file_operations;
34 } else if (S_ISDIR(inode->i_mode)) {
35 inode->i_op = &coda_dir_inode_operations;
36 inode->i_fop = &coda_dir_operations;
37 } else if (S_ISLNK(inode->i_mode)) {
38 inode->i_op = &coda_symlink_inode_operations;
39 inode->i_data.a_ops = &coda_symlink_aops;
40 inode->i_mapping = &inode->i_data;
41 } else
42 init_special_inode(inode, inode->i_mode, huge_decode_dev(attr->va_rdev));
45 static int coda_test_inode(struct inode *inode, void *data)
47 struct CodaFid *fid = (struct CodaFid *)data;
48 return coda_fideq(&(ITOC(inode)->c_fid), fid);
51 static int coda_set_inode(struct inode *inode, void *data)
53 struct CodaFid *fid = (struct CodaFid *)data;
54 ITOC(inode)->c_fid = *fid;
55 return 0;
58 static int coda_fail_inode(struct inode *inode, void *data)
60 return -1;
63 struct inode * coda_iget(struct super_block * sb, struct CodaFid * fid,
64 struct coda_vattr * attr)
66 struct inode *inode;
67 struct coda_inode_info *cii;
68 unsigned long hash = coda_f2i(fid);
70 inode = iget5_locked(sb, hash, coda_test_inode, coda_set_inode, fid);
72 if (!inode)
73 return ERR_PTR(-ENOMEM);
75 if (inode->i_state & I_NEW) {
76 cii = ITOC(inode);
77 /* we still need to set i_ino for things like stat(2) */
78 inode->i_ino = hash;
79 cii->c_mapcount = 0;
80 unlock_new_inode(inode);
83 /* always replace the attributes, type might have changed */
84 coda_fill_inode(inode, attr);
85 return inode;
88 /* this is effectively coda_iget:
89 - get attributes (might be cached)
90 - get the inode for the fid using vfs iget
91 - link the two up if this is needed
92 - fill in the attributes
94 int coda_cnode_make(struct inode **inode, struct CodaFid *fid, struct super_block *sb)
96 struct coda_vattr attr;
97 int error;
99 /* We get inode numbers from Venus -- see venus source */
100 error = venus_getattr(sb, fid, &attr);
101 if ( error ) {
102 *inode = NULL;
103 return error;
106 *inode = coda_iget(sb, fid, &attr);
107 if ( IS_ERR(*inode) ) {
108 printk("coda_cnode_make: coda_iget failed\n");
109 return PTR_ERR(*inode);
111 return 0;
115 void coda_replace_fid(struct inode *inode, struct CodaFid *oldfid,
116 struct CodaFid *newfid)
118 struct coda_inode_info *cii;
119 unsigned long hash = coda_f2i(newfid);
121 cii = ITOC(inode);
123 if (!coda_fideq(&cii->c_fid, oldfid))
124 BUG();
126 /* replace fid and rehash inode */
127 /* XXX we probably need to hold some lock here! */
128 remove_inode_hash(inode);
129 cii->c_fid = *newfid;
130 inode->i_ino = hash;
131 __insert_inode_hash(inode, hash);
134 /* convert a fid to an inode. */
135 struct inode *coda_fid_to_inode(struct CodaFid *fid, struct super_block *sb)
137 struct inode *inode;
138 unsigned long hash = coda_f2i(fid);
140 if ( !sb ) {
141 printk("coda_fid_to_inode: no sb!\n");
142 return NULL;
145 inode = iget5_locked(sb, hash, coda_test_inode, coda_fail_inode, fid);
146 if ( !inode )
147 return NULL;
149 /* we should never see newly created inodes because we intentionally
150 * fail in the initialization callback */
151 BUG_ON(inode->i_state & I_NEW);
153 return inode;
156 /* the CONTROL inode is made without asking attributes from Venus */
157 int coda_cnode_makectl(struct inode **inode, struct super_block *sb)
159 int error = -ENOMEM;
161 *inode = new_inode(sb);
162 if (*inode) {
163 (*inode)->i_ino = CTL_INO;
164 (*inode)->i_op = &coda_ioctl_inode_operations;
165 (*inode)->i_fop = &coda_ioctl_operations;
166 (*inode)->i_mode = 0444;
167 error = 0;
170 return error;