vxfs_fshead.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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 (buffer_mapped(bp)) {
  76. struct vxfs_fsh *fhp;
  77. if (!(fhp = kmalloc(sizeof(*fhp), SLAB_KERNEL)))
  78. return NULL;
  79. memcpy(fhp, bp->b_data, sizeof(*fhp));
  80. brelse(bp);
  81. return (fhp);
  82. }
  83. return NULL;
  84. }
  85. /**
  86. * vxfs_read_fshead - read the fileset headers
  87. * @sbp: superblock to which the fileset belongs
  88. *
  89. * Description:
  90. * vxfs_read_fshead will fill the inode and structural inode list in @sb.
  91. *
  92. * Returns:
  93. * Zero on success, else a negative error code (-EINVAL).
  94. */
  95. int
  96. vxfs_read_fshead(struct super_block *sbp)
  97. {
  98. struct vxfs_sb_info *infp = VXFS_SBI(sbp);
  99. struct vxfs_fsh *pfp, *sfp;
  100. struct vxfs_inode_info *vip, *tip;
  101. vip = vxfs_blkiget(sbp, infp->vsi_iext, infp->vsi_fshino);
  102. if (!vip) {
  103. printk(KERN_ERR "vxfs: unabled to read fsh inode\n");
  104. return -EINVAL;
  105. }
  106. if (!VXFS_ISFSH(vip)) {
  107. printk(KERN_ERR "vxfs: fsh list inode is of wrong type (%x)\n",
  108. vip->vii_mode & VXFS_TYPE_MASK);
  109. goto out_free_fship;
  110. }
  111. #ifdef DIAGNOSTIC
  112. printk("vxfs: fsh inode dump:\n");
  113. vxfs_dumpi(vip, infp->vsi_fshino);
  114. #endif
  115. infp->vsi_fship = vxfs_get_fake_inode(sbp, vip);
  116. if (!infp->vsi_fship) {
  117. printk(KERN_ERR "vxfs: unabled to get fsh inode\n");
  118. goto out_free_fship;
  119. }
  120. sfp = vxfs_getfsh(infp->vsi_fship, 0);
  121. if (!sfp) {
  122. printk(KERN_ERR "vxfs: unabled to get structural fsh\n");
  123. goto out_iput_fship;
  124. }
  125. #ifdef DIAGNOSTIC
  126. vxfs_dumpfsh(sfp);
  127. #endif
  128. pfp = vxfs_getfsh(infp->vsi_fship, 1);
  129. if (!pfp) {
  130. printk(KERN_ERR "vxfs: unabled to get primary fsh\n");
  131. goto out_free_sfp;
  132. }
  133. #ifdef DIAGNOSTIC
  134. vxfs_dumpfsh(pfp);
  135. #endif
  136. tip = vxfs_blkiget(sbp, infp->vsi_iext, sfp->fsh_ilistino[0]);
  137. if (!tip)
  138. goto out_free_pfp;
  139. infp->vsi_stilist = vxfs_get_fake_inode(sbp, tip);
  140. if (!infp->vsi_stilist) {
  141. printk(KERN_ERR "vxfs: unabled to get structual list inode\n");
  142. kfree(tip);
  143. goto out_free_pfp;
  144. }
  145. if (!VXFS_ISILT(VXFS_INO(infp->vsi_stilist))) {
  146. printk(KERN_ERR "vxfs: structual list inode is of wrong type (%x)\n",
  147. VXFS_INO(infp->vsi_stilist)->vii_mode & VXFS_TYPE_MASK);
  148. goto out_iput_stilist;
  149. }
  150. tip = vxfs_stiget(sbp, pfp->fsh_ilistino[0]);
  151. if (!tip)
  152. goto out_iput_stilist;
  153. infp->vsi_ilist = vxfs_get_fake_inode(sbp, tip);
  154. if (!infp->vsi_ilist) {
  155. printk(KERN_ERR "vxfs: unabled to get inode list inode\n");
  156. kfree(tip);
  157. goto out_iput_stilist;
  158. }
  159. if (!VXFS_ISILT(VXFS_INO(infp->vsi_ilist))) {
  160. printk(KERN_ERR "vxfs: inode list inode is of wrong type (%x)\n",
  161. VXFS_INO(infp->vsi_ilist)->vii_mode & VXFS_TYPE_MASK);
  162. goto out_iput_ilist;
  163. }
  164. return 0;
  165. out_iput_ilist:
  166. iput(infp->vsi_ilist);
  167. out_iput_stilist:
  168. iput(infp->vsi_stilist);
  169. out_free_pfp:
  170. kfree(pfp);
  171. out_free_sfp:
  172. kfree(sfp);
  173. out_iput_fship:
  174. iput(infp->vsi_fship);
  175. return -EINVAL;
  176. out_free_fship:
  177. kfree(vip);
  178. return -EINVAL;
  179. }