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/kernel.h>
37#include <linux/slab.h>
38#include <linux/string.h>
39
40#include "vxfs.h"
41#include "vxfs_inode.h"
42#include "vxfs_extern.h"
43#include "vxfs_fshead.h"
44
45
46#ifdef DIAGNOSTIC
47static void
48vxfs_dumpfsh(struct vxfs_fsh *fhp)
49{
50 printk("\n\ndumping fileset header:\n");
51 printk("----------------------------\n");
52 printk("version: %u\n", fhp->fsh_version);
53 printk("fsindex: %u\n", fhp->fsh_fsindex);
54 printk("iauino: %u\tninodes:%u\n",
55 fhp->fsh_iauino, fhp->fsh_ninodes);
56 printk("maxinode: %u\tlctino: %u\n",
57 fhp->fsh_maxinode, fhp->fsh_lctino);
58 printk("nau: %u\n", fhp->fsh_nau);
59 printk("ilistino[0]: %u\tilistino[1]: %u\n",
60 fhp->fsh_ilistino[0], fhp->fsh_ilistino[1]);
61}
62#endif
63
64
65
66
67
68
69
70
71
72
73
74
75
76static struct vxfs_fsh *
77vxfs_getfsh(struct inode *ip, int which)
78{
79 struct buffer_head *bp;
80
81 bp = vxfs_bread(ip, which);
82 if (bp) {
83 struct vxfs_fsh *fhp;
84
85 if (!(fhp = kmalloc(sizeof(*fhp), GFP_KERNEL)))
86 goto out;
87 memcpy(fhp, bp->b_data, sizeof(*fhp));
88
89 put_bh(bp);
90 return (fhp);
91 }
92out:
93 brelse(bp);
94 return NULL;
95}
96
97
98
99
100
101
102
103
104
105
106
107int
108vxfs_read_fshead(struct super_block *sbp)
109{
110 struct vxfs_sb_info *infp = VXFS_SBI(sbp);
111 struct vxfs_fsh *pfp, *sfp;
112 struct vxfs_inode_info *vip;
113
114 infp->vsi_fship = vxfs_blkiget(sbp, infp->vsi_iext, infp->vsi_fshino);
115 if (!infp->vsi_fship) {
116 printk(KERN_ERR "vxfs: unable to read fsh inode\n");
117 return -EINVAL;
118 }
119
120 vip = VXFS_INO(infp->vsi_fship);
121 if (!VXFS_ISFSH(vip)) {
122 printk(KERN_ERR "vxfs: fsh list inode is of wrong type (%x)\n",
123 vip->vii_mode & VXFS_TYPE_MASK);
124 goto out_iput_fship;
125 }
126
127#ifdef DIAGNOSTIC
128 printk("vxfs: fsh inode dump:\n");
129 vxfs_dumpi(vip, infp->vsi_fshino);
130#endif
131
132 sfp = vxfs_getfsh(infp->vsi_fship, 0);
133 if (!sfp) {
134 printk(KERN_ERR "vxfs: unable to get structural fsh\n");
135 goto out_iput_fship;
136 }
137
138#ifdef DIAGNOSTIC
139 vxfs_dumpfsh(sfp);
140#endif
141
142 pfp = vxfs_getfsh(infp->vsi_fship, 1);
143 if (!pfp) {
144 printk(KERN_ERR "vxfs: unable to get primary fsh\n");
145 goto out_free_sfp;
146 }
147
148#ifdef DIAGNOSTIC
149 vxfs_dumpfsh(pfp);
150#endif
151
152 infp->vsi_stilist = vxfs_blkiget(sbp, infp->vsi_iext,
153 fs32_to_cpu(infp, sfp->fsh_ilistino[0]));
154 if (!infp->vsi_stilist) {
155 printk(KERN_ERR "vxfs: unable to get structural list inode\n");
156 goto out_free_pfp;
157 }
158 if (!VXFS_ISILT(VXFS_INO(infp->vsi_stilist))) {
159 printk(KERN_ERR "vxfs: structural list inode is of wrong type (%x)\n",
160 VXFS_INO(infp->vsi_stilist)->vii_mode & VXFS_TYPE_MASK);
161 goto out_iput_stilist;
162 }
163
164 infp->vsi_ilist = vxfs_stiget(sbp, fs32_to_cpu(infp, pfp->fsh_ilistino[0]));
165 if (!infp->vsi_ilist) {
166 printk(KERN_ERR "vxfs: unable to get inode list inode\n");
167 goto out_iput_stilist;
168 }
169 if (!VXFS_ISILT(VXFS_INO(infp->vsi_ilist))) {
170 printk(KERN_ERR "vxfs: inode list inode is of wrong type (%x)\n",
171 VXFS_INO(infp->vsi_ilist)->vii_mode & VXFS_TYPE_MASK);
172 goto out_iput_ilist;
173 }
174
175 kfree(pfp);
176 kfree(sfp);
177 return 0;
178
179 out_iput_ilist:
180 iput(infp->vsi_ilist);
181 out_iput_stilist:
182 iput(infp->vsi_stilist);
183 out_free_pfp:
184 kfree(pfp);
185 out_free_sfp:
186 kfree(sfp);
187 out_iput_fship:
188 iput(infp->vsi_fship);
189 return -EINVAL;
190}
191