vxfs_subr.c 4.7 KB

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