aops.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /**
  3. * aops.h - Defines for NTFS kernel address space operations and page cache
  4. * handling. Part of the Linux-NTFS project.
  5. *
  6. * Copyright (c) 2001-2004 Anton Altaparmakov
  7. * Copyright (c) 2002 Richard Russon
  8. */
  9. #ifndef _LINUX_NTFS_AOPS_H
  10. #define _LINUX_NTFS_AOPS_H
  11. #include <linux/mm.h>
  12. #include <linux/highmem.h>
  13. #include <linux/pagemap.h>
  14. #include <linux/fs.h>
  15. #include "inode.h"
  16. /**
  17. * ntfs_unmap_page - release a page that was mapped using ntfs_map_page()
  18. * @page: the page to release
  19. *
  20. * Unpin, unmap and release a page that was obtained from ntfs_map_page().
  21. */
  22. static inline void ntfs_unmap_page(struct page *page)
  23. {
  24. kunmap(page);
  25. put_page(page);
  26. }
  27. /**
  28. * ntfs_map_page - map a page into accessible memory, reading it if necessary
  29. * @mapping: address space for which to obtain the page
  30. * @index: index into the page cache for @mapping of the page to map
  31. *
  32. * Read a page from the page cache of the address space @mapping at position
  33. * @index, where @index is in units of PAGE_SIZE, and not in bytes.
  34. *
  35. * If the page is not in memory it is loaded from disk first using the readpage
  36. * method defined in the address space operations of @mapping and the page is
  37. * added to the page cache of @mapping in the process.
  38. *
  39. * If the page belongs to an mst protected attribute and it is marked as such
  40. * in its ntfs inode (NInoMstProtected()) the mst fixups are applied but no
  41. * error checking is performed. This means the caller has to verify whether
  42. * the ntfs record(s) contained in the page are valid or not using one of the
  43. * ntfs_is_XXXX_record{,p}() macros, where XXXX is the record type you are
  44. * expecting to see. (For details of the macros, see fs/ntfs/layout.h.)
  45. *
  46. * If the page is in high memory it is mapped into memory directly addressible
  47. * by the kernel.
  48. *
  49. * Finally the page count is incremented, thus pinning the page into place.
  50. *
  51. * The above means that page_address(page) can be used on all pages obtained
  52. * with ntfs_map_page() to get the kernel virtual address of the page.
  53. *
  54. * When finished with the page, the caller has to call ntfs_unmap_page() to
  55. * unpin, unmap and release the page.
  56. *
  57. * Note this does not grant exclusive access. If such is desired, the caller
  58. * must provide it independently of the ntfs_{un}map_page() calls by using
  59. * a {rw_}semaphore or other means of serialization. A spin lock cannot be
  60. * used as ntfs_map_page() can block.
  61. *
  62. * The unlocked and uptodate page is returned on success or an encoded error
  63. * on failure. Caller has to test for error using the IS_ERR() macro on the
  64. * return value. If that evaluates to 'true', the negative error code can be
  65. * obtained using PTR_ERR() on the return value of ntfs_map_page().
  66. */
  67. static inline struct page *ntfs_map_page(struct address_space *mapping,
  68. unsigned long index)
  69. {
  70. struct page *page = read_mapping_page(mapping, index, NULL);
  71. if (!IS_ERR(page)) {
  72. kmap(page);
  73. if (!PageError(page))
  74. return page;
  75. ntfs_unmap_page(page);
  76. return ERR_PTR(-EIO);
  77. }
  78. return page;
  79. }
  80. #ifdef NTFS_RW
  81. extern void mark_ntfs_record_dirty(struct page *page, const unsigned int ofs);
  82. #endif /* NTFS_RW */
  83. #endif /* _LINUX_NTFS_AOPS_H */