vxfs_olt.c 3.8 KB

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