18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * Copyright (c) 2000-2001 Christoph Hellwig. 38c2ecf20Sopenharmony_ci * All rights reserved. 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Redistribution and use in source and binary forms, with or without 68c2ecf20Sopenharmony_ci * modification, are permitted provided that the following conditions 78c2ecf20Sopenharmony_ci * are met: 88c2ecf20Sopenharmony_ci * 1. Redistributions of source code must retain the above copyright 98c2ecf20Sopenharmony_ci * notice, this list of conditions, and the following disclaimer, 108c2ecf20Sopenharmony_ci * without modification. 118c2ecf20Sopenharmony_ci * 2. The name of the author may not be used to endorse or promote products 128c2ecf20Sopenharmony_ci * derived from this software without specific prior written permission. 138c2ecf20Sopenharmony_ci * 148c2ecf20Sopenharmony_ci * Alternatively, this software may be distributed under the terms of the 158c2ecf20Sopenharmony_ci * GNU General Public License ("GPL"). 168c2ecf20Sopenharmony_ci * 178c2ecf20Sopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 188c2ecf20Sopenharmony_ci * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 198c2ecf20Sopenharmony_ci * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 208c2ecf20Sopenharmony_ci * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR 218c2ecf20Sopenharmony_ci * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 228c2ecf20Sopenharmony_ci * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 238c2ecf20Sopenharmony_ci * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 248c2ecf20Sopenharmony_ci * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 258c2ecf20Sopenharmony_ci * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 268c2ecf20Sopenharmony_ci * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 278c2ecf20Sopenharmony_ci * SUCH DAMAGE. 288c2ecf20Sopenharmony_ci */ 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_ci/* 318c2ecf20Sopenharmony_ci * Veritas filesystem driver - object location table support. 328c2ecf20Sopenharmony_ci */ 338c2ecf20Sopenharmony_ci#include <linux/fs.h> 348c2ecf20Sopenharmony_ci#include <linux/buffer_head.h> 358c2ecf20Sopenharmony_ci#include <linux/kernel.h> 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_ci#include "vxfs.h" 388c2ecf20Sopenharmony_ci#include "vxfs_olt.h" 398c2ecf20Sopenharmony_ci#include "vxfs_extern.h" 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_cistatic inline void 438c2ecf20Sopenharmony_civxfs_get_fshead(struct vxfs_oltfshead *fshp, struct vxfs_sb_info *infp) 448c2ecf20Sopenharmony_ci{ 458c2ecf20Sopenharmony_ci BUG_ON(infp->vsi_fshino); 468c2ecf20Sopenharmony_ci infp->vsi_fshino = fs32_to_cpu(infp, fshp->olt_fsino[0]); 478c2ecf20Sopenharmony_ci} 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_cistatic inline void 508c2ecf20Sopenharmony_civxfs_get_ilist(struct vxfs_oltilist *ilistp, struct vxfs_sb_info *infp) 518c2ecf20Sopenharmony_ci{ 528c2ecf20Sopenharmony_ci BUG_ON(infp->vsi_iext); 538c2ecf20Sopenharmony_ci infp->vsi_iext = fs32_to_cpu(infp, ilistp->olt_iext[0]); 548c2ecf20Sopenharmony_ci} 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_cistatic inline u_long 578c2ecf20Sopenharmony_civxfs_oblock(struct super_block *sbp, daddr_t block, u_long bsize) 588c2ecf20Sopenharmony_ci{ 598c2ecf20Sopenharmony_ci BUG_ON(sbp->s_blocksize % bsize); 608c2ecf20Sopenharmony_ci return (block * (sbp->s_blocksize / bsize)); 618c2ecf20Sopenharmony_ci} 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_ci 648c2ecf20Sopenharmony_ci/** 658c2ecf20Sopenharmony_ci * vxfs_read_olt - read olt 668c2ecf20Sopenharmony_ci * @sbp: superblock of the filesystem 678c2ecf20Sopenharmony_ci * @bsize: blocksize of the filesystem 688c2ecf20Sopenharmony_ci * 698c2ecf20Sopenharmony_ci * Description: 708c2ecf20Sopenharmony_ci * vxfs_read_olt reads the olt of the filesystem described by @sbp 718c2ecf20Sopenharmony_ci * into main memory and does some basic setup. 728c2ecf20Sopenharmony_ci * 738c2ecf20Sopenharmony_ci * Returns: 748c2ecf20Sopenharmony_ci * Zero on success, else a negative error code. 758c2ecf20Sopenharmony_ci */ 768c2ecf20Sopenharmony_ciint 778c2ecf20Sopenharmony_civxfs_read_olt(struct super_block *sbp, u_long bsize) 788c2ecf20Sopenharmony_ci{ 798c2ecf20Sopenharmony_ci struct vxfs_sb_info *infp = VXFS_SBI(sbp); 808c2ecf20Sopenharmony_ci struct buffer_head *bp; 818c2ecf20Sopenharmony_ci struct vxfs_olt *op; 828c2ecf20Sopenharmony_ci char *oaddr, *eaddr; 838c2ecf20Sopenharmony_ci 848c2ecf20Sopenharmony_ci bp = sb_bread(sbp, vxfs_oblock(sbp, infp->vsi_oltext, bsize)); 858c2ecf20Sopenharmony_ci if (!bp || !bp->b_data) 868c2ecf20Sopenharmony_ci goto fail; 878c2ecf20Sopenharmony_ci 888c2ecf20Sopenharmony_ci op = (struct vxfs_olt *)bp->b_data; 898c2ecf20Sopenharmony_ci if (fs32_to_cpu(infp, op->olt_magic) != VXFS_OLT_MAGIC) { 908c2ecf20Sopenharmony_ci printk(KERN_NOTICE "vxfs: ivalid olt magic number\n"); 918c2ecf20Sopenharmony_ci goto fail; 928c2ecf20Sopenharmony_ci } 938c2ecf20Sopenharmony_ci 948c2ecf20Sopenharmony_ci /* 958c2ecf20Sopenharmony_ci * It is in theory possible that vsi_oltsize is > 1. 968c2ecf20Sopenharmony_ci * I've not seen any such filesystem yet and I'm lazy.. --hch 978c2ecf20Sopenharmony_ci */ 988c2ecf20Sopenharmony_ci if (infp->vsi_oltsize > 1) { 998c2ecf20Sopenharmony_ci printk(KERN_NOTICE "vxfs: oltsize > 1 detected.\n"); 1008c2ecf20Sopenharmony_ci printk(KERN_NOTICE "vxfs: please notify hch@infradead.org\n"); 1018c2ecf20Sopenharmony_ci goto fail; 1028c2ecf20Sopenharmony_ci } 1038c2ecf20Sopenharmony_ci 1048c2ecf20Sopenharmony_ci oaddr = bp->b_data + fs32_to_cpu(infp, op->olt_size); 1058c2ecf20Sopenharmony_ci eaddr = bp->b_data + (infp->vsi_oltsize * sbp->s_blocksize); 1068c2ecf20Sopenharmony_ci 1078c2ecf20Sopenharmony_ci while (oaddr < eaddr) { 1088c2ecf20Sopenharmony_ci struct vxfs_oltcommon *ocp = 1098c2ecf20Sopenharmony_ci (struct vxfs_oltcommon *)oaddr; 1108c2ecf20Sopenharmony_ci 1118c2ecf20Sopenharmony_ci switch (fs32_to_cpu(infp, ocp->olt_type)) { 1128c2ecf20Sopenharmony_ci case VXFS_OLT_FSHEAD: 1138c2ecf20Sopenharmony_ci vxfs_get_fshead((struct vxfs_oltfshead *)oaddr, infp); 1148c2ecf20Sopenharmony_ci break; 1158c2ecf20Sopenharmony_ci case VXFS_OLT_ILIST: 1168c2ecf20Sopenharmony_ci vxfs_get_ilist((struct vxfs_oltilist *)oaddr, infp); 1178c2ecf20Sopenharmony_ci break; 1188c2ecf20Sopenharmony_ci } 1198c2ecf20Sopenharmony_ci 1208c2ecf20Sopenharmony_ci oaddr += fs32_to_cpu(infp, ocp->olt_size); 1218c2ecf20Sopenharmony_ci } 1228c2ecf20Sopenharmony_ci 1238c2ecf20Sopenharmony_ci brelse(bp); 1248c2ecf20Sopenharmony_ci return (infp->vsi_fshino && infp->vsi_iext) ? 0 : -EINVAL; 1258c2ecf20Sopenharmony_ci 1268c2ecf20Sopenharmony_cifail: 1278c2ecf20Sopenharmony_ci brelse(bp); 1288c2ecf20Sopenharmony_ci return -EINVAL; 1298c2ecf20Sopenharmony_ci} 130