index.h 5.5 KB

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