vxfs_fshead.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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 - fileset header routines.
  31. */
  32. #include <linux/fs.h>
  33. #include <linux/buffer_head.h>
  34. #include <linux/kernel.h>
  35. #include <linux/slab.h>
  36. #include <linux/string.h>
  37. #include "vxfs.h"
  38. #include "vxfs_inode.h"
  39. #include "vxfs_extern.h"
  40. #include "vxfs_fshead.h"
  41. #ifdef DIAGNOSTIC
  42. static void
  43. vxfs_dumpfsh(struct vxfs_fsh *fhp)
  44. {
  45. printk("\n\ndumping fileset header:\n");
  46. printk("----------------------------\n");
  47. printk("version: %u\n", fhp->fsh_version);
  48. printk("fsindex: %u\n", fhp->fsh_fsindex);
  49. printk("iauino: %u\tninodes:%u\n",
  50. fhp->fsh_iauino, fhp->fsh_ninodes);
  51. printk("maxinode: %u\tlctino: %u\n",
  52. fhp->fsh_maxinode, fhp->fsh_lctino);
  53. printk("nau: %u\n", fhp->fsh_nau);
  54. printk("ilistino[0]: %u\tilistino[1]: %u\n",
  55. fhp->fsh_ilistino[0], fhp->fsh_ilistino[1]);
  56. }
  57. #endif
  58. /**
  59. * vxfs_getfsh - read fileset header into memory
  60. * @ip: the (fake) fileset header inode
  61. * @which: 0 for the structural, 1 for the primary fsh.
  62. *
  63. * Description:
  64. * vxfs_getfsh reads either the structural or primary fileset header
  65. * described by @ip into memory.
  66. *
  67. * Returns:
  68. * The fileset header structure on success, else Zero.
  69. */
  70. static struct vxfs_fsh *
  71. vxfs_getfsh(struct inode *ip, int which)
  72. {
  73. struct buffer_head *bp;
  74. bp = vxfs_bread(ip, which);
  75. if (bp) {
  76. struct vxfs_fsh *fhp;
  77. if (!(fhp = kmalloc(sizeof(*fhp), GFP_KERNEL)))
  78. goto out;
  79. memcpy(fhp, bp->b_data, sizeof(*fhp));
  80. put_bh(bp);
  81. return (fhp);
  82. }
  83. out:
  84. brelse(bp);
  85. return NULL;
  86. }
  87. /**
  88. * vxfs_read_fshead - read the fileset headers
  89. * @sbp: superblock to which the fileset belongs
  90. *
  91. * Description:
  92. * vxfs_read_fshead will fill the inode and structural inode list in @sb.
  93. *
  94. * Returns:
  95. * Zero on success, else a negative error code (-EINVAL).
  96. */
  97. int
  98. vxfs_read_fshead(struct super_block *sbp)
  99. {
  100. struct vxfs_sb_info *infp = VXFS_SBI(sbp);
  101. struct vxfs_fsh *pfp, *sfp;
  102. struct vxfs_inode_info *vip, *tip;
  103. vip = vxfs_blkiget(sbp, infp->vsi_iext, infp->vsi_fshino);
  104. if (!vip) {
  105. printk(KERN_ERR "vxfs: unable to read fsh inode\n");
  106. return -EINVAL;
  107. }
  108. if (!VXFS_ISFSH(vip)) {
  109. printk(KERN_ERR "vxfs: fsh list inode is of wrong type (%x)\n",
  110. vip->vii_mode & VXFS_TYPE_MASK);
  111. goto out_free_fship;
  112. }
  113. #ifdef DIAGNOSTIC
  114. printk("vxfs: fsh inode dump:\n");
  115. vxfs_dumpi(vip, infp->vsi_fshino);
  116. #endif
  117. infp->vsi_fship = vxfs_get_fake_inode(sbp, vip);
  118. if (!infp->vsi_fship) {
  119. printk(KERN_ERR "vxfs: unable to get fsh inode\n");
  120. goto out_free_fship;
  121. }
  122. sfp = vxfs_getfsh(infp->vsi_fship, 0);
  123. if (!sfp) {
  124. printk(KERN_ERR "vxfs: unable to get structural fsh\n");
  125. goto out_iput_fship;
  126. }
  127. #ifdef DIAGNOSTIC
  128. vxfs_dumpfsh(sfp);
  129. #endif
  130. pfp = vxfs_getfsh(infp->vsi_fship, 1);
  131. if (!pfp) {
  132. printk(KERN_ERR "vxfs: unable to get primary fsh\n");
  133. goto out_free_sfp;
  134. }
  135. #ifdef DIAGNOSTIC
  136. vxfs_dumpfsh(pfp);
  137. #endif
  138. tip = vxfs_blkiget(sbp, infp->vsi_iext, sfp->fsh_ilistino[0]);
  139. if (!tip)
  140. goto out_free_pfp;
  141. infp->vsi_stilist = vxfs_get_fake_inode(sbp, tip);
  142. if (!infp->vsi_stilist) {
  143. printk(KERN_ERR "vxfs: unable to get structural list inode\n");
  144. kfree(tip);
  145. goto out_free_pfp;
  146. }
  147. if (!VXFS_ISILT(VXFS_INO(infp->vsi_stilist))) {
  148. printk(KERN_ERR "vxfs: structural list inode is of wrong type (%x)\n",
  149. VXFS_INO(infp->vsi_stilist)->vii_mode & VXFS_TYPE_MASK);
  150. goto out_iput_stilist;
  151. }
  152. tip = vxfs_stiget(sbp, pfp->fsh_ilistino[0]);
  153. if (!tip)
  154. goto out_iput_stilist;
  155. infp->vsi_ilist = vxfs_get_fake_inode(sbp, tip);
  156. if (!infp->vsi_ilist) {
  157. printk(KERN_ERR "vxfs: unable to get inode list inode\n");
  158. kfree(tip);
  159. goto out_iput_stilist;
  160. }
  161. if (!VXFS_ISILT(VXFS_INO(infp->vsi_ilist))) {
  162. printk(KERN_ERR "vxfs: inode list inode is of wrong type (%x)\n",
  163. VXFS_INO(infp->vsi_ilist)->vii_mode & VXFS_TYPE_MASK);
  164. goto out_iput_ilist;
  165. }
  166. return 0;
  167. out_iput_ilist:
  168. iput(infp->vsi_ilist);
  169. out_iput_stilist:
  170. iput(infp->vsi_stilist);
  171. out_free_pfp:
  172. kfree(pfp);
  173. out_free_sfp:
  174. kfree(sfp);
  175. out_iput_fship:
  176. iput(infp->vsi_fship);
  177. return -EINVAL;
  178. out_free_fship:
  179. kfree(vip);
  180. return -EINVAL;
  181. }