vxfs_olt.c 3.6 KB

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