2 * Copyright (c) 2000-2001 Christoph Hellwig.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions, and the following disclaimer,
10 * without modification.
11 * 2. The name of the author may not be used to endorse or promote products
12 * derived from this software without specific prior written permission.
14 * Alternatively, this software may be distributed under the terms of the
15 * GNU General Public License ("GPL").
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
21 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * Veritas filesystem driver - inode routines.
34 #include <linux/buffer_head.h>
35 #include <linux/pagemap.h>
36 #include <linux/kernel.h>
37 #include <linux/slab.h>
40 #include "vxfs_inode.h"
41 #include "vxfs_extern.h"
44 struct kmem_cache
*vxfs_inode_cachep
;
49 * Dump inode contents (partially).
52 vxfs_dumpi(struct vxfs_inode_info
*vip
, ino_t ino
)
54 printk(KERN_DEBUG
"\n\n");
56 printk(KERN_DEBUG
"dumping vxfs inode %ld\n", ino
);
58 printk(KERN_DEBUG
"dumping unknown vxfs inode\n");
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
);
72 * vxfs_blkiget - find inode based on extent #
73 * @sbp: superblock of the filesystem we search in
74 * @extent: number of the extent to search
75 * @ino: inode number to search
78 * vxfs_blkiget searches inode @ino in the filesystem described by
79 * @sbp in the extent @extent.
80 * Returns the matching VxFS inode on success, else a NULL pointer.
83 * While __vxfs_iget uses the pagecache vxfs_blkiget uses the
84 * buffercache. This function should not be used outside the
85 * read_super() method, otherwise the data may be incoherent.
87 struct vxfs_inode_info
*
88 vxfs_blkiget(struct super_block
*sbp
, u_long extent
, ino_t ino
)
90 struct buffer_head
*bp
;
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
);
97 if (bp
&& buffer_mapped(bp
)) {
98 struct vxfs_inode_info
*vip
;
99 struct vxfs_dinode
*dip
;
101 if (!(vip
= kmem_cache_alloc(vxfs_inode_cachep
, GFP_KERNEL
)))
103 dip
= (struct vxfs_dinode
*)(bp
->b_data
+ offset
);
104 memcpy(vip
, dip
, sizeof(*vip
));
106 vxfs_dumpi(vip
, ino
);
113 printk(KERN_WARNING
"vxfs: unable to read block %ld\n", block
);
119 * __vxfs_iget - generic find inode facility
120 * @sbp: VFS superblock
122 * @ilistp: inode list
125 * Search the for inode number @ino in the filesystem
126 * described by @sbp. Use the specified inode table (@ilistp).
127 * Returns the matching VxFS inode on success, else an error code.
129 static struct vxfs_inode_info
*
130 __vxfs_iget(ino_t ino
, struct inode
*ilistp
)
135 offset
= (ino
% (PAGE_SIZE
/ VXFS_ISIZE
)) * VXFS_ISIZE
;
136 pp
= vxfs_get_page(ilistp
->i_mapping
, ino
* VXFS_ISIZE
/ PAGE_SIZE
);
139 struct vxfs_inode_info
*vip
;
140 struct vxfs_dinode
*dip
;
141 caddr_t kaddr
= (char *)page_address(pp
);
143 if (!(vip
= kmem_cache_alloc(vxfs_inode_cachep
, GFP_KERNEL
)))
145 dip
= (struct vxfs_dinode
*)(kaddr
+ offset
);
146 memcpy(vip
, dip
, sizeof(*vip
));
148 vxfs_dumpi(vip
, ino
);
154 printk(KERN_WARNING
"vxfs: error on page %p\n", pp
);
158 printk(KERN_WARNING
"vxfs: unable to read inode %ld\n", (unsigned long)ino
);
160 return ERR_PTR(-ENOMEM
);
164 * vxfs_stiget - find inode using the structural inode list
165 * @sbp: VFS superblock
169 * Find inode @ino in the filesystem described by @sbp using
170 * the structural inode list.
171 * Returns the matching VxFS inode on success, else a NULL pointer.
173 struct vxfs_inode_info
*
174 vxfs_stiget(struct super_block
*sbp
, ino_t ino
)
176 struct vxfs_inode_info
*vip
;
178 vip
= __vxfs_iget(ino
, VXFS_SBI(sbp
)->vsi_stilist
);
179 return IS_ERR(vip
) ? NULL
: vip
;
183 * vxfs_transmod - mode for a VxFS inode
187 * vxfs_transmod returns a Linux mode_t for a given
188 * VxFS inode structure.
190 static __inline__ mode_t
191 vxfs_transmod(struct vxfs_inode_info
*vip
)
193 mode_t ret
= vip
->vii_mode
& ~VXFS_TYPE_MASK
;
195 if (VXFS_ISFIFO(vip
))
214 * vxfs_iinit- helper to fill inode fields
219 * vxfs_instino is a helper function to fill in all relevant
220 * fields in @ip from @vip.
223 vxfs_iinit(struct inode
*ip
, struct vxfs_inode_info
*vip
)
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
;
230 set_nlink(ip
, vip
->vii_nlink
);
231 ip
->i_size
= vip
->vii_size
;
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;
240 ip
->i_blocks
= vip
->vii_blocks
;
241 ip
->i_generation
= vip
->vii_gen
;
248 * vxfs_get_fake_inode - get fake inode structure
249 * @sbp: filesystem superblock
253 * vxfs_fake_inode gets a fake inode (not in the inode hash) for a
254 * superblock, vxfs_inode pair.
255 * Returns the filled VFS inode.
258 vxfs_get_fake_inode(struct super_block
*sbp
, struct vxfs_inode_info
*vip
)
260 struct inode
*ip
= NULL
;
262 if ((ip
= new_inode(sbp
))) {
263 ip
->i_ino
= get_next_ino();
265 ip
->i_mapping
->a_ops
= &vxfs_aops
;
271 * vxfs_put_fake_inode - free faked inode
275 * vxfs_put_fake_inode frees all data associated with @ip.
278 vxfs_put_fake_inode(struct inode
*ip
)
284 * vxfs_iget - get an inode
285 * @sbp: the superblock to get the inode for
286 * @ino: the number of the inode to get
289 * vxfs_read_inode creates an inode, reads the disk inode for @ino and fills
290 * in all relevant fields in the new inode.
293 vxfs_iget(struct super_block
*sbp
, ino_t ino
)
295 struct vxfs_inode_info
*vip
;
296 const struct address_space_operations
*aops
;
299 ip
= iget_locked(sbp
, ino
);
301 return ERR_PTR(-ENOMEM
);
302 if (!(ip
->i_state
& I_NEW
))
305 vip
= __vxfs_iget(ino
, VXFS_SBI(sbp
)->vsi_ilist
);
308 return ERR_CAST(vip
);
313 if (VXFS_ISIMMED(vip
))
314 aops
= &vxfs_immed_aops
;
318 if (S_ISREG(ip
->i_mode
)) {
319 ip
->i_fop
= &generic_ro_fops
;
320 ip
->i_mapping
->a_ops
= aops
;
321 } else if (S_ISDIR(ip
->i_mode
)) {
322 ip
->i_op
= &vxfs_dir_inode_ops
;
323 ip
->i_fop
= &vxfs_dir_operations
;
324 ip
->i_mapping
->a_ops
= aops
;
325 } else if (S_ISLNK(ip
->i_mode
)) {
326 if (!VXFS_ISIMMED(vip
)) {
327 ip
->i_op
= &page_symlink_inode_operations
;
328 ip
->i_mapping
->a_ops
= &vxfs_aops
;
330 ip
->i_op
= &vxfs_immed_symlink_iops
;
331 vip
->vii_immed
.vi_immed
[ip
->i_size
] = '\0';
334 init_special_inode(ip
, ip
->i_mode
, old_decode_dev(vip
->vii_rdev
));
336 unlock_new_inode(ip
);
340 static void vxfs_i_callback(struct rcu_head
*head
)
342 struct inode
*inode
= container_of(head
, struct inode
, i_rcu
);
343 INIT_LIST_HEAD(&inode
->i_dentry
);
344 kmem_cache_free(vxfs_inode_cachep
, inode
->i_private
);
348 * vxfs_evict_inode - remove inode from main memory
349 * @ip: inode to discard.
352 * vxfs_evict_inode() is called on the final iput and frees the private
356 vxfs_evict_inode(struct inode
*ip
)
358 truncate_inode_pages(&ip
->i_data
, 0);
360 call_rcu(&ip
->i_rcu
, vxfs_i_callback
);