[PATCH] x86-64 - new memory map handling
[linux-2.6/history.git] / fs / freevxfs / vxfs_fshead.c
blob5562a8c0e1ac49fdfe300002cff80667c929e6a9
1 /*
2 * Copyright (c) 2000-2001 Christoph Hellwig.
3 * All rights reserved.
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.
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
27 * SUCH DAMAGE.
30 #ident "$Id: vxfs_fshead.c,v 1.20 2002/01/02 22:02:12 hch Exp hch $"
33 * Veritas filesystem driver - fileset header routines.
35 #include <linux/fs.h>
36 #include <linux/buffer_head.h>
37 #include <linux/kernel.h>
38 #include <linux/slab.h>
40 #include "vxfs.h"
41 #include "vxfs_inode.h"
42 #include "vxfs_extern.h"
43 #include "vxfs_fshead.h"
46 #ifdef DIAGNOSTIC
47 static void
48 vxfs_dumpfsh(struct vxfs_fsh *fhp)
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]);
62 #endif
64 /**
65 * vxfs_getfsh - read fileset header into memory
66 * @ip: the (fake) fileset header inode
67 * @which: 0 for the structural, 1 for the primary fsh.
69 * Description:
70 * vxfs_getfsh reads either the structural or primary fileset header
71 * described by @ip into memory.
73 * Returns:
74 * The fileset header structure on success, else Zero.
76 static struct vxfs_fsh *
77 vxfs_getfsh(struct inode *ip, int which)
79 struct buffer_head *bp;
81 bp = vxfs_bread(ip, which);
82 if (buffer_mapped(bp)) {
83 struct vxfs_fsh *fhp;
85 if (!(fhp = kmalloc(sizeof(*fhp), SLAB_KERNEL)))
86 return NULL;
87 memcpy(fhp, bp->b_data, sizeof(*fhp));
89 brelse(bp);
90 return (fhp);
93 return NULL;
96 /**
97 * vxfs_read_fshead - read the fileset headers
98 * @sbp: superblock to which the fileset belongs
100 * Description:
101 * vxfs_read_fshead will fill the inode and structural inode list in @sb.
103 * Returns:
104 * Zero on success, else a negative error code (-EINVAL).
107 vxfs_read_fshead(struct super_block *sbp)
109 struct vxfs_sb_info *infp = VXFS_SBI(sbp);
110 struct vxfs_fsh *pfp, *sfp;
111 struct vxfs_inode_info *vip, *tip;
113 if (!(vip = vxfs_blkiget(sbp, infp->vsi_iext, infp->vsi_fshino))) {
114 printk(KERN_ERR "vxfs: unabled to read fsh inode\n");
115 return -EINVAL;
116 } else if (!VXFS_ISFSH(vip)) {
117 printk(KERN_ERR "vxfs: fsh list inode is of wrong type (%x)\n",
118 vip->vii_mode & VXFS_TYPE_MASK);
119 return -EINVAL;
123 #ifdef DIAGNOSTIC
124 printk("vxfs: fsh inode dump:\n");
125 vxfs_dumpi(vip, infp->vsi_fshino);
126 #endif
128 if (!(infp->vsi_fship = vxfs_get_fake_inode(sbp, vip))) {
129 printk(KERN_ERR "vxfs: unabled to get fsh inode\n");
130 return -EINVAL;
133 if (!(sfp = vxfs_getfsh(infp->vsi_fship, 0))) {
134 printk(KERN_ERR "vxfs: unabled to get structural fsh\n");
135 return -EINVAL;
138 #ifdef DIAGNOSTIC
139 vxfs_dumpfsh(sfp);
140 #endif
142 if (!(pfp = vxfs_getfsh(infp->vsi_fship, 1))) {
143 printk(KERN_ERR "vxfs: unabled to get primary fsh\n");
144 return -EINVAL;
147 #ifdef DIAGNOSTIC
148 vxfs_dumpfsh(pfp);
149 #endif
151 tip = vxfs_blkiget(sbp, infp->vsi_iext, sfp->fsh_ilistino[0]);
152 if (!tip || ((infp->vsi_stilist = vxfs_get_fake_inode(sbp, tip)) == NULL)) {
153 printk(KERN_ERR "vxfs: unabled to get structual list inode\n");
154 return -EINVAL;
155 } else if (!VXFS_ISILT(VXFS_INO(infp->vsi_stilist))) {
156 printk(KERN_ERR "vxfs: structual list inode is of wrong type (%x)\n",
157 VXFS_INO(infp->vsi_stilist)->vii_mode & VXFS_TYPE_MASK);
158 return -EINVAL;
161 tip = vxfs_stiget(sbp, pfp->fsh_ilistino[0]);
162 if (!tip || ((infp->vsi_ilist = vxfs_get_fake_inode(sbp, tip)) == NULL)) {
163 printk(KERN_ERR "vxfs: unabled to get inode list inode\n");
164 return -EINVAL;
165 } else if (!VXFS_ISILT(VXFS_INO(infp->vsi_ilist))) {
166 printk(KERN_ERR "vxfs: inode list inode is of wrong type (%x)\n",
167 VXFS_INO(infp->vsi_ilist)->vii_mode & VXFS_TYPE_MASK);
168 return -EINVAL;
171 return 0;