index.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * index.h - Defines for NTFS kernel index handling. Part of the Linux-NTFS
  4. * project.
  5. *
  6. * Copyright (c) 2004 Anton Altaparmakov
  7. */
  8. #ifndef _LINUX_NTFS_INDEX_H
  9. #define _LINUX_NTFS_INDEX_H
  10. #include <linux/fs.h>
  11. #include "types.h"
  12. #include "layout.h"
  13. #include "inode.h"
  14. #include "attrib.h"
  15. #include "mft.h"
  16. #include "aops.h"
  17. /**
  18. * @idx_ni: index inode containing the @entry described by this context
  19. * @entry: index entry (points into @ir or @ia)
  20. * @data: index entry data (points into @entry)
  21. * @data_len: length in bytes of @data
  22. * @is_in_root: 'true' if @entry is in @ir and 'false' if it is in @ia
  23. * @ir: index root if @is_in_root and NULL otherwise
  24. * @actx: attribute search context if @is_in_root and NULL otherwise
  25. * @base_ni: base inode if @is_in_root and NULL otherwise
  26. * @ia: index block if @is_in_root is 'false' and NULL otherwise
  27. * @page: page if @is_in_root is 'false' and NULL otherwise
  28. *
  29. * @idx_ni is the index inode this context belongs to.
  30. *
  31. * @entry is the index entry described by this context. @data and @data_len
  32. * are the index entry data and its length in bytes, respectively. @data
  33. * simply points into @entry. This is probably what the user is interested in.
  34. *
  35. * If @is_in_root is 'true', @entry is in the index root attribute @ir described
  36. * by the attribute search context @actx and the base inode @base_ni. @ia and
  37. * @page are NULL in this case.
  38. *
  39. * If @is_in_root is 'false', @entry is in the index allocation attribute and @ia
  40. * and @page point to the index allocation block and the mapped, locked page it
  41. * is in, respectively. @ir, @actx and @base_ni are NULL in this case.
  42. *
  43. * To obtain a context call ntfs_index_ctx_get().
  44. *
  45. * We use this context to allow ntfs_index_lookup() to return the found index
  46. * @entry and its @data without having to allocate a buffer and copy the @entry
  47. * and/or its @data into it.
  48. *
  49. * When finished with the @entry and its @data, call ntfs_index_ctx_put() to
  50. * free the context and other associated resources.
  51. *
  52. * If the index entry was modified, call flush_dcache_index_entry_page()
  53. * immediately after the modification and either ntfs_index_entry_mark_dirty()
  54. * or ntfs_index_entry_write() before the call to ntfs_index_ctx_put() to
  55. * ensure that the changes are written to disk.
  56. */
  57. typedef struct {
  58. ntfs_inode *idx_ni;
  59. INDEX_ENTRY *entry;
  60. void *data;
  61. u16 data_len;
  62. bool is_in_root;
  63. INDEX_ROOT *ir;
  64. ntfs_attr_search_ctx *actx;
  65. ntfs_inode *base_ni;
  66. INDEX_ALLOCATION *ia;
  67. struct page *page;
  68. } ntfs_index_context;
  69. extern ntfs_index_context *ntfs_index_ctx_get(ntfs_inode *idx_ni);
  70. extern void ntfs_index_ctx_put(ntfs_index_context *ictx);
  71. extern int ntfs_index_lookup(const void *key, const int key_len,
  72. ntfs_index_context *ictx);
  73. #ifdef NTFS_RW
  74. /**
  75. * ntfs_index_entry_flush_dcache_page - flush_dcache_page() for index entries
  76. * @ictx: ntfs index context describing the index entry
  77. *
  78. * Call flush_dcache_page() for the page in which an index entry resides.
  79. *
  80. * This must be called every time an index entry is modified, just after the
  81. * modification.
  82. *
  83. * If the index entry is in the index root attribute, simply flush the page
  84. * containing the mft record containing the index root attribute.
  85. *
  86. * If the index entry is in an index block belonging to the index allocation
  87. * attribute, simply flush the page cache page containing the index block.
  88. */
  89. static inline void ntfs_index_entry_flush_dcache_page(ntfs_index_context *ictx)
  90. {
  91. if (ictx->is_in_root)
  92. flush_dcache_mft_record_page(ictx->actx->ntfs_ino);
  93. else
  94. flush_dcache_page(ictx->page);
  95. }
  96. /**
  97. * ntfs_index_entry_mark_dirty - mark an index entry dirty
  98. * @ictx: ntfs index context describing the index entry
  99. *
  100. * Mark the index entry described by the index entry context @ictx dirty.
  101. *
  102. * If the index entry is in the index root attribute, simply mark the mft
  103. * record containing the index root attribute dirty. This ensures the mft
  104. * record, and hence the index root attribute, will be written out to disk
  105. * later.
  106. *
  107. * If the index entry is in an index block belonging to the index allocation
  108. * attribute, mark the buffers belonging to the index record as well as the
  109. * page cache page the index block is in dirty. This automatically marks the
  110. * VFS inode of the ntfs index inode to which the index entry belongs dirty,
  111. * too (I_DIRTY_PAGES) and this in turn ensures the page buffers, and hence the
  112. * dirty index block, will be written out to disk later.
  113. */
  114. static inline void ntfs_index_entry_mark_dirty(ntfs_index_context *ictx)
  115. {
  116. if (ictx->is_in_root)
  117. mark_mft_record_dirty(ictx->actx->ntfs_ino);
  118. else
  119. mark_ntfs_record_dirty(ictx->page,
  120. (u8*)ictx->ia - (u8*)page_address(ictx->page));
  121. }
  122. #endif /* NTFS_RW */
  123. #endif /* _LINUX_NTFS_INDEX_H */