1 /* 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 - object location table support. 32 */ 33 #include <linux/fs.h> 34 #include <linux/buffer_head.h> 35 #include <linux/kernel.h> 36 37 #include "vxfs.h" 38 #include "vxfs_olt.h" 39 #include "vxfs_extern.h" 40 41 42 static inline void 43 vxfs_get_fshead(struct vxfs_oltfshead *fshp, struct vxfs_sb_info *infp) 44 { 45 if (infp->vsi_fshino) 46 BUG(); 47 infp->vsi_fshino = fshp->olt_fsino[0]; 48 } 49 50 static inline void 51 vxfs_get_ilist(struct vxfs_oltilist *ilistp, struct vxfs_sb_info *infp) 52 { 53 if (infp->vsi_iext) 54 BUG(); 55 infp->vsi_iext = ilistp->olt_iext[0]; 56 } 57 58 static inline u_long 59 vxfs_oblock(struct super_block *sbp, daddr_t block, u_long bsize) 60 { 61 if (sbp->s_blocksize % bsize) 62 BUG(); 63 return (block * (sbp->s_blocksize / bsize)); 64 } 65 66 67 /** 68 * vxfs_read_olt - read olt 69 * @sbp: superblock of the filesystem 70 * @bsize: blocksize of the filesystem 71 * 72 * Description: 73 * vxfs_read_olt reads the olt of the filesystem described by @sbp 74 * into main memory and does some basic setup. 75 * 76 * Returns: 77 * Zero on success, else a negative error code. 78 */ 79 int 80 vxfs_read_olt(struct super_block *sbp, u_long bsize) 81 { 82 struct vxfs_sb_info *infp = VXFS_SBI(sbp); 83 struct buffer_head *bp; 84 struct vxfs_olt *op; 85 char *oaddr, *eaddr; 86 87 88 bp = sb_bread(sbp, vxfs_oblock(sbp, infp->vsi_oltext, bsize)); 89 if (!bp || !bp->b_data) 90 goto fail; 91 92 op = (struct vxfs_olt *)bp->b_data; 93 if (op->olt_magic != VXFS_OLT_MAGIC) { 94 printk(KERN_NOTICE "vxfs: ivalid olt magic number\n"); 95 goto fail; 96 } 97 98 /* 99 * It is in theory possible that vsi_oltsize is > 1. 100 * I've not seen any such filesystem yet and I'm lazy.. --hch 101 */ 102 if (infp->vsi_oltsize > 1) { 103 printk(KERN_NOTICE "vxfs: oltsize > 1 detected.\n"); 104 printk(KERN_NOTICE "vxfs: please notify hch@infradead.org\n"); 105 goto fail; 106 } 107 108 oaddr = bp->b_data + op->olt_size; 109 eaddr = bp->b_data + (infp->vsi_oltsize * sbp->s_blocksize); 110 111 while (oaddr < eaddr) { 112 struct vxfs_oltcommon *ocp = 113 (struct vxfs_oltcommon *)oaddr; 114 115 switch (ocp->olt_type) { 116 case VXFS_OLT_FSHEAD: 117 vxfs_get_fshead((struct vxfs_oltfshead *)oaddr, infp); 118 break; 119 case VXFS_OLT_ILIST: 120 vxfs_get_ilist((struct vxfs_oltilist *)oaddr, infp); 121 break; 122 } 123 124 oaddr += ocp->olt_size; 125 } 126 127 brelse(bp); 128 return 0; 129 130 fail: 131 brelse(bp); 132 return -EINVAL; 133 } 134