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