vxfs_subr.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2000-2001 Christoph Hellwig.
  4. */
  5. /*
  6. * Veritas filesystem driver - shared subroutines.
  7. */
  8. #include <linux/fs.h>
  9. #include <linux/buffer_head.h>
  10. #include <linux/kernel.h>
  11. #include <linux/pagemap.h>
  12. #include "vxfs_extern.h"
  13. static int vxfs_read_folio(struct file *, struct folio *);
  14. static sector_t vxfs_bmap(struct address_space *, sector_t);
  15. const struct address_space_operations vxfs_aops = {
  16. .read_folio = vxfs_read_folio,
  17. .bmap = vxfs_bmap,
  18. };
  19. inline void
  20. vxfs_put_page(struct page *pp)
  21. {
  22. kunmap(pp);
  23. put_page(pp);
  24. }
  25. /**
  26. * vxfs_get_page - read a page into memory.
  27. * @ip: inode to read from
  28. * @n: page number
  29. *
  30. * Description:
  31. * vxfs_get_page reads the @n th page of @ip into the pagecache.
  32. *
  33. * Returns:
  34. * The wanted page on success, else a NULL pointer.
  35. */
  36. struct page *
  37. vxfs_get_page(struct address_space *mapping, u_long n)
  38. {
  39. struct page * pp;
  40. pp = read_mapping_page(mapping, n, NULL);
  41. if (!IS_ERR(pp)) {
  42. kmap(pp);
  43. /** if (!PageChecked(pp)) **/
  44. /** vxfs_check_page(pp); **/
  45. }
  46. return (pp);
  47. }
  48. /**
  49. * vxfs_bread - read buffer for a give inode,block tuple
  50. * @ip: inode
  51. * @block: logical block
  52. *
  53. * Description:
  54. * The vxfs_bread function reads block no @block of
  55. * @ip into the buffercache.
  56. *
  57. * Returns:
  58. * The resulting &struct buffer_head.
  59. */
  60. struct buffer_head *
  61. vxfs_bread(struct inode *ip, int block)
  62. {
  63. struct buffer_head *bp;
  64. daddr_t pblock;
  65. pblock = vxfs_bmap1(ip, block);
  66. bp = sb_bread(ip->i_sb, pblock);
  67. return (bp);
  68. }
  69. /**
  70. * vxfs_get_block - locate buffer for given inode,block tuple
  71. * @ip: inode
  72. * @iblock: logical block
  73. * @bp: buffer skeleton
  74. * @create: %TRUE if blocks may be newly allocated.
  75. *
  76. * Description:
  77. * The vxfs_get_block function fills @bp with the right physical
  78. * block and device number to perform a lowlevel read/write on
  79. * it.
  80. *
  81. * Returns:
  82. * Zero on success, else a negativ error code (-EIO).
  83. */
  84. static int
  85. vxfs_getblk(struct inode *ip, sector_t iblock,
  86. struct buffer_head *bp, int create)
  87. {
  88. daddr_t pblock;
  89. pblock = vxfs_bmap1(ip, iblock);
  90. if (pblock != 0) {
  91. map_bh(bp, ip->i_sb, pblock);
  92. return 0;
  93. }
  94. return -EIO;
  95. }
  96. /**
  97. * vxfs_read_folio - read one page synchronously into the pagecache
  98. * @file: file context (unused)
  99. * @folio: folio to fill in.
  100. *
  101. * Description:
  102. * The vxfs_read_folio routine reads @folio synchronously into the
  103. * pagecache.
  104. *
  105. * Returns:
  106. * Zero on success, else a negative error code.
  107. *
  108. * Locking status:
  109. * @folio is locked and will be unlocked.
  110. */
  111. static int vxfs_read_folio(struct file *file, struct folio *folio)
  112. {
  113. return block_read_full_folio(folio, vxfs_getblk);
  114. }
  115. /**
  116. * vxfs_bmap - perform logical to physical block mapping
  117. * @mapping: logical to physical mapping to use
  118. * @block: logical block (relative to @mapping).
  119. *
  120. * Description:
  121. * Vxfs_bmap find out the corresponding phsical block to the
  122. * @mapping, @block pair.
  123. *
  124. * Returns:
  125. * Physical block number on success, else Zero.
  126. *
  127. * Locking status:
  128. * We are under the bkl.
  129. */
  130. static sector_t
  131. vxfs_bmap(struct address_space *mapping, sector_t block)
  132. {
  133. return generic_block_bmap(mapping, block, vxfs_getblk);
  134. }