vxfs_subr.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:5k
源码类别:

Linux/Unix编程

开发平台:

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_subr.c,v 1.8 2001/12/28 20:50:47 hch Exp hch $"
  30. /*
  31.  * Veritas filesystem driver - shared subroutines.
  32.  */
  33. #include <linux/fs.h>
  34. #include <linux/kernel.h>
  35. #include <linux/slab.h>
  36. #include <linux/pagemap.h>
  37. #include "vxfs_kcompat.h"
  38. #include "vxfs_extern.h"
  39. static int vxfs_readpage(struct file *, struct page *);
  40. static int vxfs_bmap(struct address_space *, long);
  41. struct address_space_operations vxfs_aops = {
  42. .readpage = vxfs_readpage,
  43. .bmap = vxfs_bmap,
  44. .sync_page = block_sync_page,
  45. };
  46. /**
  47.  * vxfs_get_page - read a page into memory.
  48.  * @ip: inode to read from
  49.  * @n: page number
  50.  *
  51.  * Description:
  52.  *   vxfs_get_page reads the @n th page of @ip into the pagecache.
  53.  *
  54.  * Returns:
  55.  *   The wanted page on success, else a NULL pointer.
  56.  */
  57. struct page *
  58. vxfs_get_page(struct address_space *mapping, u_long n)
  59. {
  60. struct page * pp;
  61. pp = read_cache_page(mapping, n,
  62. (filler_t*)mapping->a_ops->readpage, NULL);
  63. if (!IS_ERR(pp)) {
  64. wait_on_page(pp);
  65. kmap(pp);
  66. if (!Page_Uptodate(pp))
  67. goto fail;
  68. /** if (!PageChecked(pp)) **/
  69. /** vxfs_check_page(pp); **/
  70. if (PageError(pp))
  71. goto fail;
  72. }
  73. return (pp);
  74.  
  75. fail:
  76. vxfs_put_page(pp);
  77. return ERR_PTR(-EIO);
  78. }
  79. __inline__ void
  80. vxfs_put_page(struct page *pp)
  81. {
  82. kunmap(pp);
  83. page_cache_release(pp);
  84. }
  85. /**
  86.  * vxfs_bread - read buffer for a give inode,block tuple
  87.  * @ip: inode
  88.  * @block: logical block
  89.  *
  90.  * Description:
  91.  *   The vxfs_bread function reads block no @block  of
  92.  *   @ip into the buffercache.
  93.  *
  94.  * Returns:
  95.  *   The resulting &struct buffer_head.
  96.  */
  97. struct buffer_head *
  98. vxfs_bread(struct inode *ip, int block)
  99. {
  100. struct buffer_head *bp;
  101. daddr_t pblock;
  102. pblock = vxfs_bmap1(ip, block);
  103. bp = sb_bread(ip->i_sb, pblock);
  104. return (bp);
  105. }
  106. /**
  107.  * vxfs_get_block - locate buffer for given inode,block tuple 
  108.  * @ip: inode
  109.  * @iblock: logical block
  110.  * @bp: buffer skeleton
  111.  * @create: %TRUE if blocks may be newly allocated.
  112.  *
  113.  * Description:
  114.  *   The vxfs_get_block function fills @bp with the right physical
  115.  *   block and device number to perform a lowlevel read/write on
  116.  *   it.
  117.  *
  118.  * Returns:
  119.  *   Zero on success, else a negativ error code (-EIO).
  120.  */
  121. static int
  122. vxfs_getblk(struct inode *ip, sector_t iblock,
  123.     struct buffer_head *bp, int create)
  124. {
  125. daddr_t pblock;
  126. pblock = vxfs_bmap1(ip, iblock);
  127. if (pblock != 0) {
  128. map_bh(bp, ip->i_sb, pblock);
  129. return 0;
  130. }
  131. return -EIO;
  132. }
  133. /**
  134.  * vxfs_readpage - read one page synchronously into the pagecache
  135.  * @file: file context (unused)
  136.  * @page: page frame to fill in.
  137.  *
  138.  * Description:
  139.  *   The vxfs_readpage routine reads @page synchronously into the
  140.  *   pagecache.
  141.  *
  142.  * Returns:
  143.  *   Zero on success, else a negative error code.
  144.  *
  145.  * Locking status:
  146.  *   @page is locked and will be unlocked.
  147.  */
  148. static int
  149. vxfs_readpage(struct file *file, struct page *page)
  150. {
  151. return block_read_full_page(page, vxfs_getblk);
  152. }
  153.  
  154. /**
  155.  * vxfs_bmap - perform logical to physical block mapping
  156.  * @mapping: logical to physical mapping to use
  157.  * @block: logical block (relative to @mapping).
  158.  *
  159.  * Description:
  160.  *   Vxfs_bmap find out the corresponding phsical block to the
  161.  *   @mapping, @block pair.
  162.  *
  163.  * Returns:
  164.  *   Physical block number on success, else Zero.
  165.  *
  166.  * Locking status:
  167.  *   We are under the bkl.
  168.  */
  169. static int
  170. vxfs_bmap(struct address_space *mapping, long block)
  171. {
  172. return generic_block_bmap(mapping, block, vxfs_getblk);
  173. }