blob: 2651b4238eb2bf75ed402908d3cd3287331940c7 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Copyright (c) 2000-2001 Christoph Hellwig.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
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.
13 *
14 * Alternatively, this software may be distributed under the terms of the
15 * GNU General Public License ("GPL").
16 *
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
27 * SUCH DAMAGE.
28 */
29
30/*
31 * Veritas filesystem driver - fileset header routines.
32 */
33#include <linux/fs.h>
34#include <linux/buffer_head.h>
35#include <linux/kernel.h>
36#include <linux/slab.h>
37#include <linux/string.h>
38
39#include "vxfs.h"
40#include "vxfs_inode.h"
41#include "vxfs_extern.h"
42#include "vxfs_fshead.h"
43
44
45#ifdef DIAGNOSTIC
46static void
47vxfs_dumpfsh(struct vxfs_fsh *fhp)
48{
49 printk("\n\ndumping fileset header:\n");
50 printk("----------------------------\n");
51 printk("version: %u\n", fhp->fsh_version);
52 printk("fsindex: %u\n", fhp->fsh_fsindex);
53 printk("iauino: %u\tninodes:%u\n",
54 fhp->fsh_iauino, fhp->fsh_ninodes);
55 printk("maxinode: %u\tlctino: %u\n",
56 fhp->fsh_maxinode, fhp->fsh_lctino);
57 printk("nau: %u\n", fhp->fsh_nau);
58 printk("ilistino[0]: %u\tilistino[1]: %u\n",
59 fhp->fsh_ilistino[0], fhp->fsh_ilistino[1]);
60}
61#endif
62
63/**
64 * vxfs_getfsh - read fileset header into memory
65 * @ip: the (fake) fileset header inode
66 * @which: 0 for the structural, 1 for the primary fsh.
67 *
68 * Description:
69 * vxfs_getfsh reads either the structural or primary fileset header
70 * described by @ip into memory.
71 *
72 * Returns:
73 * The fileset header structure on success, else Zero.
74 */
75static struct vxfs_fsh *
76vxfs_getfsh(struct inode *ip, int which)
77{
78 struct buffer_head *bp;
79
80 bp = vxfs_bread(ip, which);
Pekka Enbergba03bda2005-06-30 02:59:04 -070081 if (bp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 struct vxfs_fsh *fhp;
83
Pekka Enbergba03bda2005-06-30 02:59:04 -070084 if (!(fhp = kmalloc(sizeof(*fhp), GFP_KERNEL)))
85 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 memcpy(fhp, bp->b_data, sizeof(*fhp));
87
Pekka Enbergba03bda2005-06-30 02:59:04 -070088 put_bh(bp);
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 return (fhp);
90 }
Pekka Enbergba03bda2005-06-30 02:59:04 -070091out:
92 brelse(bp);
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 return NULL;
94}
95
96/**
97 * vxfs_read_fshead - read the fileset headers
98 * @sbp: superblock to which the fileset belongs
99 *
100 * Description:
101 * vxfs_read_fshead will fill the inode and structural inode list in @sb.
102 *
103 * Returns:
104 * Zero on success, else a negative error code (-EINVAL).
105 */
106int
107vxfs_read_fshead(struct super_block *sbp)
108{
109 struct vxfs_sb_info *infp = VXFS_SBI(sbp);
110 struct vxfs_fsh *pfp, *sfp;
Krzysztof Błaszkowski8985f532016-06-01 08:56:04 +0200111 struct vxfs_inode_info *vip;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112
Krzysztof Błaszkowski8985f532016-06-01 08:56:04 +0200113 infp->vsi_fship = vxfs_blkiget(sbp, infp->vsi_iext, infp->vsi_fshino);
114 if (!infp->vsi_fship) {
Cliff Wickman552c0342006-06-25 05:47:16 -0700115 printk(KERN_ERR "vxfs: unable to read fsh inode\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 return -EINVAL;
117 }
Krzysztof Błaszkowski8985f532016-06-01 08:56:04 +0200118
119 vip = VXFS_INO(infp->vsi_fship);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 if (!VXFS_ISFSH(vip)) {
121 printk(KERN_ERR "vxfs: fsh list inode is of wrong type (%x)\n",
122 vip->vii_mode & VXFS_TYPE_MASK);
Krzysztof Błaszkowski8985f532016-06-01 08:56:04 +0200123 goto out_iput_fship;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 }
125
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126#ifdef DIAGNOSTIC
127 printk("vxfs: fsh inode dump:\n");
128 vxfs_dumpi(vip, infp->vsi_fshino);
129#endif
130
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 sfp = vxfs_getfsh(infp->vsi_fship, 0);
132 if (!sfp) {
Cliff Wickman552c0342006-06-25 05:47:16 -0700133 printk(KERN_ERR "vxfs: unable to get structural fsh\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 goto out_iput_fship;
135 }
136
137#ifdef DIAGNOSTIC
138 vxfs_dumpfsh(sfp);
139#endif
140
141 pfp = vxfs_getfsh(infp->vsi_fship, 1);
142 if (!pfp) {
Cliff Wickman552c0342006-06-25 05:47:16 -0700143 printk(KERN_ERR "vxfs: unable to get primary fsh\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 goto out_free_sfp;
145 }
146
147#ifdef DIAGNOSTIC
148 vxfs_dumpfsh(pfp);
149#endif
150
Krzysztof Błaszkowski8985f532016-06-01 08:56:04 +0200151 infp->vsi_stilist = vxfs_blkiget(sbp, infp->vsi_iext,
Krzysztof Błaszkowski0d83f7f2016-05-31 08:45:13 +0200152 fs32_to_cpu(infp, sfp->fsh_ilistino[0]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 if (!infp->vsi_stilist) {
Cliff Wickman552c0342006-06-25 05:47:16 -0700154 printk(KERN_ERR "vxfs: unable to get structural list inode\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 goto out_free_pfp;
156 }
157 if (!VXFS_ISILT(VXFS_INO(infp->vsi_stilist))) {
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300158 printk(KERN_ERR "vxfs: structural list inode is of wrong type (%x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 VXFS_INO(infp->vsi_stilist)->vii_mode & VXFS_TYPE_MASK);
160 goto out_iput_stilist;
161 }
162
Krzysztof Błaszkowski8985f532016-06-01 08:56:04 +0200163 infp->vsi_ilist = vxfs_stiget(sbp, fs32_to_cpu(infp, pfp->fsh_ilistino[0]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 if (!infp->vsi_ilist) {
Cliff Wickman552c0342006-06-25 05:47:16 -0700165 printk(KERN_ERR "vxfs: unable to get inode list inode\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 goto out_iput_stilist;
167 }
168 if (!VXFS_ISILT(VXFS_INO(infp->vsi_ilist))) {
169 printk(KERN_ERR "vxfs: inode list inode is of wrong type (%x)\n",
170 VXFS_INO(infp->vsi_ilist)->vii_mode & VXFS_TYPE_MASK);
171 goto out_iput_ilist;
172 }
173
174 return 0;
175
176 out_iput_ilist:
177 iput(infp->vsi_ilist);
178 out_iput_stilist:
179 iput(infp->vsi_stilist);
180 out_free_pfp:
181 kfree(pfp);
182 out_free_sfp:
183 kfree(sfp);
184 out_iput_fship:
185 iput(infp->vsi_fship);
186 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187}