aops.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /**
  2. * aops.h - Defines for NTFS kernel address space operations and page cache
  3. * handling. Part of the Linux-NTFS project.
  4. *
  5. * Copyright (c) 2001-2004 Anton Altaparmakov
  6. * Copyright (c) 2002 Richard Russon
  7. *
  8. * This program/include file is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as published
  10. * by the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program/include file is distributed in the hope that it will be
  14. * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
  15. * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program (in the main directory of the Linux-NTFS
  20. * distribution in the file COPYING); if not, write to the Free Software
  21. * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  22. */
  23. #ifndef _LINUX_NTFS_AOPS_H
  24. #define _LINUX_NTFS_AOPS_H
  25. #include <linux/mm.h>
  26. #include <linux/highmem.h>
  27. #include <linux/pagemap.h>
  28. #include <linux/fs.h>
  29. #include "inode.h"
  30. /**
  31. * ntfs_unmap_page - release a page that was mapped using ntfs_map_page()
  32. * @page: the page to release
  33. *
  34. * Unpin, unmap and release a page that was obtained from ntfs_map_page().
  35. */
  36. static inline void ntfs_unmap_page(struct page *page)
  37. {
  38. kunmap(page);
  39. page_cache_release(page);
  40. }
  41. /**
  42. * ntfs_map_page - map a page into accessible memory, reading it if necessary
  43. * @mapping: address space for which to obtain the page
  44. * @index: index into the page cache for @mapping of the page to map
  45. *
  46. * Read a page from the page cache of the address space @mapping at position
  47. * @index, where @index is in units of PAGE_CACHE_SIZE, and not in bytes.
  48. *
  49. * If the page is not in memory it is loaded from disk first using the readpage
  50. * method defined in the address space operations of @mapping and the page is
  51. * added to the page cache of @mapping in the process.
  52. *
  53. * If the page belongs to an mst protected attribute and it is marked as such
  54. * in its ntfs inode (NInoMstProtected()) the mst fixups are applied but no
  55. * error checking is performed. This means the caller has to verify whether
  56. * the ntfs record(s) contained in the page are valid or not using one of the
  57. * ntfs_is_XXXX_record{,p}() macros, where XXXX is the record type you are
  58. * expecting to see. (For details of the macros, see fs/ntfs/layout.h.)
  59. *
  60. * If the page is in high memory it is mapped into memory directly addressible
  61. * by the kernel.
  62. *
  63. * Finally the page count is incremented, thus pinning the page into place.
  64. *
  65. * The above means that page_address(page) can be used on all pages obtained
  66. * with ntfs_map_page() to get the kernel virtual address of the page.
  67. *
  68. * When finished with the page, the caller has to call ntfs_unmap_page() to
  69. * unpin, unmap and release the page.
  70. *
  71. * Note this does not grant exclusive access. If such is desired, the caller
  72. * must provide it independently of the ntfs_{un}map_page() calls by using
  73. * a {rw_}semaphore or other means of serialization. A spin lock cannot be
  74. * used as ntfs_map_page() can block.
  75. *
  76. * The unlocked and uptodate page is returned on success or an encoded error
  77. * on failure. Caller has to test for error using the IS_ERR() macro on the
  78. * return value. If that evaluates to 'true', the negative error code can be
  79. * obtained using PTR_ERR() on the return value of ntfs_map_page().
  80. */
  81. static inline struct page *ntfs_map_page(struct address_space *mapping,
  82. unsigned long index)
  83. {
  84. struct page *page = read_mapping_page(mapping, index, NULL);
  85. if (!IS_ERR(page)) {
  86. kmap(page);
  87. if (!PageError(page))
  88. return page;
  89. ntfs_unmap_page(page);
  90. return ERR_PTR(-EIO);
  91. }
  92. return page;
  93. }
  94. #ifdef NTFS_RW
  95. extern void mark_ntfs_record_dirty(struct page *page, const unsigned int ofs);
  96. #endif /* NTFS_RW */
  97. #endif /* _LINUX_NTFS_AOPS_H */