1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33#include <linux/fs.h>
34#include <linux/buffer_head.h>
35#include <linux/pagemap.h>
36#include <linux/kernel.h>
37#include <linux/slab.h>
38
39#include "vxfs.h"
40#include "vxfs_inode.h"
41#include "vxfs_extern.h"
42
43
44struct kmem_cache *vxfs_inode_cachep;
45
46
47#ifdef DIAGNOSTIC
48
49
50
51void
52vxfs_dumpi(struct vxfs_inode_info *vip, ino_t ino)
53{
54 printk(KERN_DEBUG "\n\n");
55 if (ino)
56 printk(KERN_DEBUG "dumping vxfs inode %ld\n", ino);
57 else
58 printk(KERN_DEBUG "dumping unknown vxfs inode\n");
59
60 printk(KERN_DEBUG "---------------------------\n");
61 printk(KERN_DEBUG "mode is %x\n", vip->vii_mode);
62 printk(KERN_DEBUG "nlink:%u, uid:%u, gid:%u\n",
63 vip->vii_nlink, vip->vii_uid, vip->vii_gid);
64 printk(KERN_DEBUG "size:%Lx, blocks:%u\n",
65 vip->vii_size, vip->vii_blocks);
66 printk(KERN_DEBUG "orgtype:%u\n", vip->vii_orgtype);
67}
68#endif
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87struct vxfs_inode_info *
88vxfs_blkiget(struct super_block *sbp, u_long extent, ino_t ino)
89{
90 struct buffer_head *bp;
91 u_long block, offset;
92
93 block = extent + ((ino * VXFS_ISIZE) / sbp->s_blocksize);
94 offset = ((ino % (sbp->s_blocksize / VXFS_ISIZE)) * VXFS_ISIZE);
95 bp = sb_bread(sbp, block);
96
97 if (bp && buffer_mapped(bp)) {
98 struct vxfs_inode_info *vip;
99 struct vxfs_dinode *dip;
100
101 if (!(vip = kmem_cache_alloc(vxfs_inode_cachep, GFP_KERNEL)))
102 goto fail;
103 dip = (struct vxfs_dinode *)(bp->b_data + offset);
104 memcpy(vip, dip, sizeof(*vip));
105#ifdef DIAGNOSTIC
106 vxfs_dumpi(vip, ino);
107#endif
108 brelse(bp);
109 return (vip);
110 }
111
112fail:
113 printk(KERN_WARNING "vxfs: unable to read block %ld\n", block);
114 brelse(bp);
115 return NULL;
116}
117
118
119
120
121
122
123
124
125
126
127
128
129static struct vxfs_inode_info *
130__vxfs_iget(ino_t ino, struct inode *ilistp)
131{
132 struct page *pp;
133 u_long offset;
134
135 offset = (ino % (PAGE_SIZE / VXFS_ISIZE)) * VXFS_ISIZE;
136 pp = vxfs_get_page(ilistp->i_mapping, ino * VXFS_ISIZE / PAGE_SIZE);
137
138 if (!IS_ERR(pp)) {
139 struct vxfs_inode_info *vip;
140 struct vxfs_dinode *dip;
141 caddr_t kaddr = (char *)page_address(pp);
142
143 if (!(vip = kmem_cache_alloc(vxfs_inode_cachep, GFP_KERNEL)))
144 goto fail;
145 dip = (struct vxfs_dinode *)(kaddr + offset);
146 memcpy(vip, dip, sizeof(*vip));
147#ifdef DIAGNOSTIC
148 vxfs_dumpi(vip, ino);
149#endif
150 vxfs_put_page(pp);
151 return (vip);
152 }
153
154 printk(KERN_WARNING "vxfs: error on page %p\n", pp);
155 return ERR_CAST(pp);
156
157fail:
158 printk(KERN_WARNING "vxfs: unable to read inode %ld\n", (unsigned long)ino);
159 vxfs_put_page(pp);
160 return ERR_PTR(-ENOMEM);
161}
162
163
164
165
166
167
168
169
170
171
172
173struct vxfs_inode_info *
174vxfs_stiget(struct super_block *sbp, ino_t ino)
175{
176 struct vxfs_inode_info *vip;
177
178 vip = __vxfs_iget(ino, VXFS_SBI(sbp)->vsi_stilist);
179 return IS_ERR(vip) ? NULL : vip;
180}
181
182
183
184
185
186
187
188
189
190static __inline__ mode_t
191vxfs_transmod(struct vxfs_inode_info *vip)
192{
193 mode_t ret = vip->vii_mode & ~VXFS_TYPE_MASK;
194
195 if (VXFS_ISFIFO(vip))
196 ret |= S_IFIFO;
197 if (VXFS_ISCHR(vip))
198 ret |= S_IFCHR;
199 if (VXFS_ISDIR(vip))
200 ret |= S_IFDIR;
201 if (VXFS_ISBLK(vip))
202 ret |= S_IFBLK;
203 if (VXFS_ISLNK(vip))
204 ret |= S_IFLNK;
205 if (VXFS_ISREG(vip))
206 ret |= S_IFREG;
207 if (VXFS_ISSOC(vip))
208 ret |= S_IFSOCK;
209
210 return (ret);
211}
212
213
214
215
216
217
218
219
220
221
222static void
223vxfs_iinit(struct inode *ip, struct vxfs_inode_info *vip)
224{
225
226 ip->i_mode = vxfs_transmod(vip);
227 ip->i_uid = (uid_t)vip->vii_uid;
228 ip->i_gid = (gid_t)vip->vii_gid;
229
230 ip->i_nlink = vip->vii_nlink;
231 ip->i_size = vip->vii_size;
232
233 ip->i_atime.tv_sec = vip->vii_atime;
234 ip->i_ctime.tv_sec = vip->vii_ctime;
235 ip->i_mtime.tv_sec = vip->vii_mtime;
236 ip->i_atime.tv_nsec = 0;
237 ip->i_ctime.tv_nsec = 0;
238 ip->i_mtime.tv_nsec = 0;
239
240 ip->i_blocks = vip->vii_blocks;
241 ip->i_generation = vip->vii_gen;
242
243 ip->i_private = vip;
244
245}
246
247
248
249
250
251
252
253
254
255
256
257struct inode *
258vxfs_get_fake_inode(struct super_block *sbp, struct vxfs_inode_info *vip)
259{
260 struct inode *ip = NULL;
261
262 if ((ip = new_inode(sbp))) {
263 vxfs_iinit(ip, vip);
264 ip->i_mapping->a_ops = &vxfs_aops;
265 }
266 return (ip);
267}
268
269
270
271
272
273
274
275
276void
277vxfs_put_fake_inode(struct inode *ip)
278{
279 iput(ip);
280}
281
282
283
284
285
286
287
288
289
290
291struct inode *
292vxfs_iget(struct super_block *sbp, ino_t ino)
293{
294 struct vxfs_inode_info *vip;
295 const struct address_space_operations *aops;
296 struct inode *ip;
297
298 ip = iget_locked(sbp, ino);
299 if (!ip)
300 return ERR_PTR(-ENOMEM);
301 if (!(ip->i_state & I_NEW))
302 return ip;
303
304 vip = __vxfs_iget(ino, VXFS_SBI(sbp)->vsi_ilist);
305 if (IS_ERR(vip)) {
306 iget_failed(ip);
307 return ERR_CAST(vip);
308 }
309
310 vxfs_iinit(ip, vip);
311
312 if (VXFS_ISIMMED(vip))
313 aops = &vxfs_immed_aops;
314 else
315 aops = &vxfs_aops;
316
317 if (S_ISREG(ip->i_mode)) {
318 ip->i_fop = &generic_ro_fops;
319 ip->i_mapping->a_ops = aops;
320 } else if (S_ISDIR(ip->i_mode)) {
321 ip->i_op = &vxfs_dir_inode_ops;
322 ip->i_fop = &vxfs_dir_operations;
323 ip->i_mapping->a_ops = aops;
324 } else if (S_ISLNK(ip->i_mode)) {
325 if (!VXFS_ISIMMED(vip)) {
326 ip->i_op = &page_symlink_inode_operations;
327 ip->i_mapping->a_ops = &vxfs_aops;
328 } else {
329 ip->i_op = &vxfs_immed_symlink_iops;
330 vip->vii_immed.vi_immed[ip->i_size] = '\0';
331 }
332 } else
333 init_special_inode(ip, ip->i_mode, old_decode_dev(vip->vii_rdev));
334
335 unlock_new_inode(ip);
336 return ip;
337}
338
339
340
341
342
343
344
345
346
347void
348vxfs_clear_inode(struct inode *ip)
349{
350 kmem_cache_free(vxfs_inode_cachep, ip->i_private);
351}
352