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>
38 #include <linux/namei.h>
41 #include "vxfs_inode.h"
42 #include "vxfs_extern.h"
47 * Dump inode contents (partially).
50 vxfs_dumpi(struct vxfs_inode_info *vip, ino_t ino)
52 printk(KERN_DEBUG "\n\n");
54 printk(KERN_DEBUG "dumping vxfs inode %ld\n", ino);
56 printk(KERN_DEBUG "dumping unknown vxfs inode\n");
58 printk(KERN_DEBUG "---------------------------\n");
59 printk(KERN_DEBUG "mode is %x\n", vip->vii_mode);
60 printk(KERN_DEBUG "nlink:%u, uid:%u, gid:%u\n",
61 vip->vii_nlink, vip->vii_uid, vip->vii_gid);
62 printk(KERN_DEBUG "size:%Lx, blocks:%u\n",
63 vip->vii_size, vip->vii_blocks);
64 printk(KERN_DEBUG "orgtype:%u\n", vip->vii_orgtype);
69 * vxfs_transmod - mode for a VxFS inode
73 * vxfs_transmod returns a Linux mode_t for a given
74 * VxFS inode structure.
76 static __inline__ umode_t
77 vxfs_transmod(struct vxfs_inode_info *vip)
79 umode_t ret = vip->vii_mode & ~VXFS_TYPE_MASK;
99 static inline void dip2vip_cpy(struct vxfs_sb_info *sbi,
100 struct vxfs_inode_info *vip, struct vxfs_dinode *dip)
102 struct inode *inode = &vip->vfs_inode;
104 vip->vii_mode = fs32_to_cpu(sbi, dip->vdi_mode);
105 vip->vii_nlink = fs32_to_cpu(sbi, dip->vdi_nlink);
106 vip->vii_uid = fs32_to_cpu(sbi, dip->vdi_uid);
107 vip->vii_gid = fs32_to_cpu(sbi, dip->vdi_gid);
108 vip->vii_size = fs64_to_cpu(sbi, dip->vdi_size);
109 vip->vii_atime = fs32_to_cpu(sbi, dip->vdi_atime);
110 vip->vii_autime = fs32_to_cpu(sbi, dip->vdi_autime);
111 vip->vii_mtime = fs32_to_cpu(sbi, dip->vdi_mtime);
112 vip->vii_mutime = fs32_to_cpu(sbi, dip->vdi_mutime);
113 vip->vii_ctime = fs32_to_cpu(sbi, dip->vdi_ctime);
114 vip->vii_cutime = fs32_to_cpu(sbi, dip->vdi_cutime);
115 vip->vii_orgtype = dip->vdi_orgtype;
117 vip->vii_blocks = fs32_to_cpu(sbi, dip->vdi_blocks);
118 vip->vii_gen = fs32_to_cpu(sbi, dip->vdi_gen);
121 vip->vii_dotdot = fs32_to_cpu(sbi, dip->vdi_dotdot);
122 else if (!VXFS_ISREG(vip) && !VXFS_ISLNK(vip))
123 vip->vii_rdev = fs32_to_cpu(sbi, dip->vdi_rdev);
125 /* don't endian swap the fields that differ by orgtype */
126 memcpy(&vip->vii_org, &dip->vdi_org, sizeof(vip->vii_org));
128 inode->i_mode = vxfs_transmod(vip);
129 i_uid_write(inode, (uid_t)vip->vii_uid);
130 i_gid_write(inode, (gid_t)vip->vii_gid);
132 set_nlink(inode, vip->vii_nlink);
133 inode->i_size = vip->vii_size;
135 inode->i_atime.tv_sec = vip->vii_atime;
136 inode->i_ctime.tv_sec = vip->vii_ctime;
137 inode->i_mtime.tv_sec = vip->vii_mtime;
138 inode->i_atime.tv_nsec = 0;
139 inode->i_ctime.tv_nsec = 0;
140 inode->i_mtime.tv_nsec = 0;
142 inode->i_blocks = vip->vii_blocks;
143 inode->i_generation = vip->vii_gen;
147 * vxfs_blkiget - find inode based on extent #
148 * @sbp: superblock of the filesystem we search in
149 * @extent: number of the extent to search
150 * @ino: inode number to search
153 * vxfs_blkiget searches inode @ino in the filesystem described by
154 * @sbp in the extent @extent.
155 * Returns the matching VxFS inode on success, else a NULL pointer.
158 * While __vxfs_iget uses the pagecache vxfs_blkiget uses the
159 * buffercache. This function should not be used outside the
160 * read_super() method, otherwise the data may be incoherent.
163 vxfs_blkiget(struct super_block *sbp, u_long extent, ino_t ino)
165 struct buffer_head *bp;
167 u_long block, offset;
169 inode = new_inode(sbp);
172 inode->i_ino = get_next_ino();
174 block = extent + ((ino * VXFS_ISIZE) / sbp->s_blocksize);
175 offset = ((ino % (sbp->s_blocksize / VXFS_ISIZE)) * VXFS_ISIZE);
176 bp = sb_bread(sbp, block);
178 if (bp && buffer_mapped(bp)) {
179 struct vxfs_inode_info *vip = VXFS_INO(inode);
180 struct vxfs_dinode *dip;
182 dip = (struct vxfs_dinode *)(bp->b_data + offset);
183 dip2vip_cpy(VXFS_SBI(sbp), vip, dip);
184 vip->vfs_inode.i_mapping->a_ops = &vxfs_aops;
186 vxfs_dumpi(vip, ino);
192 printk(KERN_WARNING "vxfs: unable to read block %ld\n", block);
199 * __vxfs_iget - generic find inode facility
200 * @ilistp: inode list
201 * @vip: VxFS inode to fill in
205 * Search the for inode number @ino in the filesystem
206 * described by @sbp. Use the specified inode table (@ilistp).
207 * Returns the matching inode on success, else an error code.
210 __vxfs_iget(struct inode *ilistp, struct vxfs_inode_info *vip, ino_t ino)
215 offset = (ino % (PAGE_SIZE / VXFS_ISIZE)) * VXFS_ISIZE;
216 pp = vxfs_get_page(ilistp->i_mapping, ino * VXFS_ISIZE / PAGE_SIZE);
219 struct vxfs_dinode *dip;
220 caddr_t kaddr = (char *)page_address(pp);
222 dip = (struct vxfs_dinode *)(kaddr + offset);
223 dip2vip_cpy(VXFS_SBI(ilistp->i_sb), vip, dip);
224 vip->vfs_inode.i_mapping->a_ops = &vxfs_aops;
226 vxfs_dumpi(vip, ino);
232 printk(KERN_WARNING "vxfs: error on page 0x%p for inode %ld\n",
233 pp, (unsigned long)ino);
238 * vxfs_stiget - find inode using the structural inode list
239 * @sbp: VFS superblock
243 * Find inode @ino in the filesystem described by @sbp using
244 * the structural inode list.
245 * Returns the matching inode on success, else a NULL pointer.
248 vxfs_stiget(struct super_block *sbp, ino_t ino)
253 inode = new_inode(sbp);
256 inode->i_ino = get_next_ino();
258 error = __vxfs_iget(VXFS_SBI(sbp)->vsi_stilist, VXFS_INO(inode), ino);
268 * vxfs_iget - get an inode
269 * @sbp: the superblock to get the inode for
270 * @ino: the number of the inode to get
273 * vxfs_read_inode creates an inode, reads the disk inode for @ino and fills
274 * in all relevant fields in the new inode.
277 vxfs_iget(struct super_block *sbp, ino_t ino)
279 struct vxfs_inode_info *vip;
280 const struct address_space_operations *aops;
284 ip = iget_locked(sbp, ino);
286 return ERR_PTR(-ENOMEM);
287 if (!(ip->i_state & I_NEW))
291 error = __vxfs_iget(VXFS_SBI(sbp)->vsi_ilist, vip, ino);
294 return ERR_PTR(error);
297 if (VXFS_ISIMMED(vip))
298 aops = &vxfs_immed_aops;
302 if (S_ISREG(ip->i_mode)) {
303 ip->i_fop = &generic_ro_fops;
304 ip->i_mapping->a_ops = aops;
305 } else if (S_ISDIR(ip->i_mode)) {
306 ip->i_op = &vxfs_dir_inode_ops;
307 ip->i_fop = &vxfs_dir_operations;
308 ip->i_mapping->a_ops = aops;
309 } else if (S_ISLNK(ip->i_mode)) {
310 if (!VXFS_ISIMMED(vip)) {
311 ip->i_op = &page_symlink_inode_operations;
313 ip->i_mapping->a_ops = &vxfs_aops;
315 ip->i_op = &simple_symlink_inode_operations;
316 ip->i_link = vip->vii_immed.vi_immed;
317 nd_terminate_link(ip->i_link, ip->i_size,
318 sizeof(vip->vii_immed.vi_immed) - 1);
321 init_special_inode(ip, ip->i_mode, old_decode_dev(vip->vii_rdev));
323 unlock_new_inode(ip);
328 * vxfs_evict_inode - remove inode from main memory
329 * @ip: inode to discard.
332 * vxfs_evict_inode() is called on the final iput and frees the private
336 vxfs_evict_inode(struct inode *ip)
338 truncate_inode_pages_final(&ip->i_data);