vxfs_olt.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:4k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

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