vxfs_fshead.c
上传用户:lgb322
上传日期:2013-02-24
资源大小:30529k
文件大小:5k
源码类别:

嵌入式Linux

开发平台:

Unix_Linux

  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. #ident "$Id: vxfs_fshead.c,v 1.20 2002/01/02 22:02:12 hch Exp hch $"
  30. /*
  31.  * Veritas filesystem driver - fileset header routines.
  32.  */
  33. #include <linux/fs.h>
  34. #include <linux/kernel.h>
  35. #include <linux/slab.h>
  36. #include "vxfs.h"
  37. #include "vxfs_inode.h"
  38. #include "vxfs_extern.h"
  39. #include "vxfs_fshead.h"
  40. #ifdef DIAGNOSTIC
  41. static void
  42. vxfs_dumpfsh(struct vxfs_fsh *fhp)
  43. {
  44. printk("nndumping fileset header:n");
  45. printk("----------------------------n");
  46. printk("version: %un", fhp->fsh_version);
  47. printk("fsindex: %un", fhp->fsh_fsindex);
  48. printk("iauino: %utninodes:%un",
  49. fhp->fsh_iauino, fhp->fsh_ninodes);
  50. printk("maxinode: %utlctino: %un",
  51. fhp->fsh_maxinode, fhp->fsh_lctino);
  52. printk("nau: %un", fhp->fsh_nau);
  53. printk("ilistino[0]: %utilistino[1]: %un",
  54. fhp->fsh_ilistino[0], fhp->fsh_ilistino[1]);
  55. }
  56. #endif
  57. /**
  58.  * vxfs_getfsh - read fileset header into memory
  59.  * @ip: the (fake) fileset header inode
  60.  * @which: 0 for the structural, 1 for the primary fsh.
  61.  *
  62.  * Description:
  63.  *   vxfs_getfsh reads either the structural or primary fileset header
  64.  *   described by @ip into memory.
  65.  *
  66.  * Returns:
  67.  *   The fileset header structure on success, else Zero.
  68.  */
  69. static struct vxfs_fsh *
  70. vxfs_getfsh(struct inode *ip, int which)
  71. {
  72. struct buffer_head *bp;
  73. bp = vxfs_bread(ip, which);
  74. if (buffer_mapped(bp)) {
  75. struct vxfs_fsh *fhp;
  76. if (!(fhp = kmalloc(sizeof(*fhp), SLAB_KERNEL)))
  77. return NULL;
  78. memcpy(fhp, bp->b_data, sizeof(*fhp));
  79. brelse(bp);
  80. return (fhp);
  81. }
  82. return NULL;
  83. }
  84. /**
  85.  * vxfs_read_fshead - read the fileset headers
  86.  * @sbp: superblock to which the fileset belongs
  87.  *
  88.  * Description:
  89.  *   vxfs_read_fshead will fill the inode and structural inode list in @sb.
  90.  *
  91.  * Returns:
  92.  *   Zero on success, else a negative error code (-EINVAL).
  93.  */
  94. int
  95. vxfs_read_fshead(struct super_block *sbp)
  96. {
  97. struct vxfs_sb_info *infp = VXFS_SBI(sbp);
  98. struct vxfs_fsh *pfp, *sfp;
  99. struct vxfs_inode_info *vip, *tip;
  100. if (!(vip = vxfs_blkiget(sbp, infp->vsi_iext, infp->vsi_fshino))) {
  101. printk(KERN_ERR "vxfs: unabled to read fsh inoden");
  102. return -EINVAL;
  103. } else if (!VXFS_ISFSH(vip)) {
  104. printk(KERN_ERR "vxfs: fsh list inode is of wrong type (%x)n",
  105. vip->vii_mode & VXFS_TYPE_MASK); 
  106. return -EINVAL;
  107. }
  108. #ifdef DIAGNOSTIC
  109. printk("vxfs: fsh inode dump:n");
  110. vxfs_dumpi(vip, infp->vsi_fshino);
  111. #endif
  112. if (!(infp->vsi_fship = vxfs_get_fake_inode(sbp, vip))) {
  113. printk(KERN_ERR "vxfs: unabled to get fsh inoden");
  114. return -EINVAL;
  115. }
  116. if (!(sfp = vxfs_getfsh(infp->vsi_fship, 0))) {
  117. printk(KERN_ERR "vxfs: unabled to get structural fshn");
  118. return -EINVAL;
  119. #ifdef DIAGNOSTIC
  120. vxfs_dumpfsh(sfp);
  121. #endif
  122. if (!(pfp = vxfs_getfsh(infp->vsi_fship, 1))) {
  123. printk(KERN_ERR "vxfs: unabled to get primary fshn");
  124. return -EINVAL;
  125. }
  126. #ifdef DIAGNOSTIC
  127. vxfs_dumpfsh(pfp);
  128. #endif
  129. tip = vxfs_blkiget(sbp, infp->vsi_iext, sfp->fsh_ilistino[0]);
  130. if (!tip || ((infp->vsi_stilist = vxfs_get_fake_inode(sbp, tip)) == NULL)) {
  131. printk(KERN_ERR "vxfs: unabled to get structual list inoden");
  132. return -EINVAL;
  133. } else if (!VXFS_ISILT(VXFS_INO(infp->vsi_stilist))) {
  134. printk(KERN_ERR "vxfs: structual list inode is of wrong type (%x)n",
  135. VXFS_INO(infp->vsi_stilist)->vii_mode & VXFS_TYPE_MASK); 
  136. return -EINVAL;
  137. }
  138. tip = vxfs_stiget(sbp, pfp->fsh_ilistino[0]);
  139. if (!tip || ((infp->vsi_ilist = vxfs_get_fake_inode(sbp, tip)) == NULL)) {
  140. printk(KERN_ERR "vxfs: unabled to get inode list inoden");
  141. return -EINVAL;
  142. } else if (!VXFS_ISILT(VXFS_INO(infp->vsi_ilist))) {
  143. printk(KERN_ERR "vxfs: inode list inode is of wrong type (%x)n",
  144. VXFS_INO(infp->vsi_ilist)->vii_mode & VXFS_TYPE_MASK);
  145. return -EINVAL;
  146. }
  147. return 0;
  148. }