vxfs_fshead.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /*
  2. * Copyright (c) 2000-2001 Christoph Hellwig.
  3. * Copyright (c) 2016 Krzysztof Blaszkowski
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions, and the following disclaimer,
  11. * without modification.
  12. * 2. The name of the author may not be used to endorse or promote products
  13. * derived from this software without specific prior written permission.
  14. *
  15. * Alternatively, this software may be distributed under the terms of the
  16. * GNU General Public License ("GPL").
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  19. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  20. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  21. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
  22. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  23. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  24. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  25. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  26. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  27. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  28. * SUCH DAMAGE.
  29. */
  30. /*
  31. * Veritas filesystem driver - fileset header routines.
  32. */
  33. #include <linux/fs.h>
  34. #include <linux/buffer_head.h>
  35. #include <linux/kernel.h>
  36. #include <linux/slab.h>
  37. #include <linux/string.h>
  38. #include "vxfs.h"
  39. #include "vxfs_inode.h"
  40. #include "vxfs_extern.h"
  41. #include "vxfs_fshead.h"
  42. #ifdef DIAGNOSTIC
  43. static void
  44. vxfs_dumpfsh(struct vxfs_fsh *fhp)
  45. {
  46. printk("\n\ndumping fileset header:\n");
  47. printk("----------------------------\n");
  48. printk("version: %u\n", fhp->fsh_version);
  49. printk("fsindex: %u\n", fhp->fsh_fsindex);
  50. printk("iauino: %u\tninodes:%u\n",
  51. fhp->fsh_iauino, fhp->fsh_ninodes);
  52. printk("maxinode: %u\tlctino: %u\n",
  53. fhp->fsh_maxinode, fhp->fsh_lctino);
  54. printk("nau: %u\n", fhp->fsh_nau);
  55. printk("ilistino[0]: %u\tilistino[1]: %u\n",
  56. fhp->fsh_ilistino[0], fhp->fsh_ilistino[1]);
  57. }
  58. #endif
  59. /**
  60. * vxfs_getfsh - read fileset header into memory
  61. * @ip: the (fake) fileset header inode
  62. * @which: 0 for the structural, 1 for the primary fsh.
  63. *
  64. * Description:
  65. * vxfs_getfsh reads either the structural or primary fileset header
  66. * described by @ip into memory.
  67. *
  68. * Returns:
  69. * The fileset header structure on success, else Zero.
  70. */
  71. static struct vxfs_fsh *
  72. vxfs_getfsh(struct inode *ip, int which)
  73. {
  74. struct buffer_head *bp;
  75. bp = vxfs_bread(ip, which);
  76. if (bp) {
  77. struct vxfs_fsh *fhp;
  78. if (!(fhp = kmalloc(sizeof(*fhp), GFP_KERNEL)))
  79. goto out;
  80. memcpy(fhp, bp->b_data, sizeof(*fhp));
  81. put_bh(bp);
  82. return (fhp);
  83. }
  84. out:
  85. brelse(bp);
  86. return NULL;
  87. }
  88. /**
  89. * vxfs_read_fshead - read the fileset headers
  90. * @sbp: superblock to which the fileset belongs
  91. *
  92. * Description:
  93. * vxfs_read_fshead will fill the inode and structural inode list in @sb.
  94. *
  95. * Returns:
  96. * Zero on success, else a negative error code (-EINVAL).
  97. */
  98. int
  99. vxfs_read_fshead(struct super_block *sbp)
  100. {
  101. struct vxfs_sb_info *infp = VXFS_SBI(sbp);
  102. struct vxfs_fsh *pfp, *sfp;
  103. struct vxfs_inode_info *vip;
  104. infp->vsi_fship = vxfs_blkiget(sbp, infp->vsi_iext, infp->vsi_fshino);
  105. if (!infp->vsi_fship) {
  106. printk(KERN_ERR "vxfs: unable to read fsh inode\n");
  107. return -EINVAL;
  108. }
  109. vip = VXFS_INO(infp->vsi_fship);
  110. if (!VXFS_ISFSH(vip)) {
  111. printk(KERN_ERR "vxfs: fsh list inode is of wrong type (%x)\n",
  112. vip->vii_mode & VXFS_TYPE_MASK);
  113. goto out_iput_fship;
  114. }
  115. #ifdef DIAGNOSTIC
  116. printk("vxfs: fsh inode dump:\n");
  117. vxfs_dumpi(vip, infp->vsi_fshino);
  118. #endif
  119. sfp = vxfs_getfsh(infp->vsi_fship, 0);
  120. if (!sfp) {
  121. printk(KERN_ERR "vxfs: unable to get structural fsh\n");
  122. goto out_iput_fship;
  123. }
  124. #ifdef DIAGNOSTIC
  125. vxfs_dumpfsh(sfp);
  126. #endif
  127. pfp = vxfs_getfsh(infp->vsi_fship, 1);
  128. if (!pfp) {
  129. printk(KERN_ERR "vxfs: unable to get primary fsh\n");
  130. goto out_free_sfp;
  131. }
  132. #ifdef DIAGNOSTIC
  133. vxfs_dumpfsh(pfp);
  134. #endif
  135. infp->vsi_stilist = vxfs_blkiget(sbp, infp->vsi_iext,
  136. fs32_to_cpu(infp, sfp->fsh_ilistino[0]));
  137. if (!infp->vsi_stilist) {
  138. printk(KERN_ERR "vxfs: unable to get structural list inode\n");
  139. goto out_free_pfp;
  140. }
  141. if (!VXFS_ISILT(VXFS_INO(infp->vsi_stilist))) {
  142. printk(KERN_ERR "vxfs: structural list inode is of wrong type (%x)\n",
  143. VXFS_INO(infp->vsi_stilist)->vii_mode & VXFS_TYPE_MASK);
  144. goto out_iput_stilist;
  145. }
  146. infp->vsi_ilist = vxfs_stiget(sbp, fs32_to_cpu(infp, pfp->fsh_ilistino[0]));
  147. if (!infp->vsi_ilist) {
  148. printk(KERN_ERR "vxfs: unable to get inode list inode\n");
  149. goto out_iput_stilist;
  150. }
  151. if (!VXFS_ISILT(VXFS_INO(infp->vsi_ilist))) {
  152. printk(KERN_ERR "vxfs: inode list inode is of wrong type (%x)\n",
  153. VXFS_INO(infp->vsi_ilist)->vii_mode & VXFS_TYPE_MASK);
  154. goto out_iput_ilist;
  155. }
  156. kfree(pfp);
  157. kfree(sfp);
  158. return 0;
  159. out_iput_ilist:
  160. iput(infp->vsi_ilist);
  161. out_iput_stilist:
  162. iput(infp->vsi_stilist);
  163. out_free_pfp:
  164. kfree(pfp);
  165. out_free_sfp:
  166. kfree(sfp);
  167. out_iput_fship:
  168. iput(infp->vsi_fship);
  169. return -EINVAL;
  170. }