1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 * index.h - Defines for NTFS kernel index handling. Part of the Linux-NTFS
6 * Copyright (c) 2004 Anton Altaparmakov
9 #ifndef _LINUX_NTFS_INDEX_H
10 #define _LINUX_NTFS_INDEX_H
22 * @idx_ni: index inode containing the @entry described by this context
23 * @entry: index entry (points into @ir or @ia)
24 * @data: index entry data (points into @entry)
25 * @data_len: length in bytes of @data
26 * @is_in_root: 'true' if @entry is in @ir and 'false' if it is in @ia
27 * @ir: index root if @is_in_root and NULL otherwise
28 * @actx: attribute search context if @is_in_root and NULL otherwise
29 * @base_ni: base inode if @is_in_root and NULL otherwise
30 * @ia: index block if @is_in_root is 'false' and NULL otherwise
31 * @page: page if @is_in_root is 'false' and NULL otherwise
33 * @idx_ni is the index inode this context belongs to.
35 * @entry is the index entry described by this context. @data and @data_len
36 * are the index entry data and its length in bytes, respectively. @data
37 * simply points into @entry. This is probably what the user is interested in.
39 * If @is_in_root is 'true', @entry is in the index root attribute @ir described
40 * by the attribute search context @actx and the base inode @base_ni. @ia and
41 * @page are NULL in this case.
43 * If @is_in_root is 'false', @entry is in the index allocation attribute and @ia
44 * and @page point to the index allocation block and the mapped, locked page it
45 * is in, respectively. @ir, @actx and @base_ni are NULL in this case.
47 * To obtain a context call ntfs_index_ctx_get().
49 * We use this context to allow ntfs_index_lookup() to return the found index
50 * @entry and its @data without having to allocate a buffer and copy the @entry
51 * and/or its @data into it.
53 * When finished with the @entry and its @data, call ntfs_index_ctx_put() to
54 * free the context and other associated resources.
56 * If the index entry was modified, call flush_dcache_index_entry_page()
57 * immediately after the modification and either ntfs_index_entry_mark_dirty()
58 * or ntfs_index_entry_write() before the call to ntfs_index_ctx_put() to
59 * ensure that the changes are written to disk.
68 ntfs_attr_search_ctx *actx;
74 extern ntfs_index_context *ntfs_index_ctx_get(ntfs_inode *idx_ni);
75 extern void ntfs_index_ctx_put(ntfs_index_context *ictx);
77 extern int ntfs_index_lookup(const void *key, const int key_len,
78 ntfs_index_context *ictx);
83 * ntfs_index_entry_flush_dcache_page - flush_dcache_page() for index entries
84 * @ictx: ntfs index context describing the index entry
86 * Call flush_dcache_page() for the page in which an index entry resides.
88 * This must be called every time an index entry is modified, just after the
91 * If the index entry is in the index root attribute, simply flush the page
92 * containing the mft record containing the index root attribute.
94 * If the index entry is in an index block belonging to the index allocation
95 * attribute, simply flush the page cache page containing the index block.
97 static inline void ntfs_index_entry_flush_dcache_page(ntfs_index_context *ictx)
100 flush_dcache_mft_record_page(ictx->actx->ntfs_ino);
102 flush_dcache_page(ictx->page);
106 * ntfs_index_entry_mark_dirty - mark an index entry dirty
107 * @ictx: ntfs index context describing the index entry
109 * Mark the index entry described by the index entry context @ictx dirty.
111 * If the index entry is in the index root attribute, simply mark the mft
112 * record containing the index root attribute dirty. This ensures the mft
113 * record, and hence the index root attribute, will be written out to disk
116 * If the index entry is in an index block belonging to the index allocation
117 * attribute, mark the buffers belonging to the index record as well as the
118 * page cache page the index block is in dirty. This automatically marks the
119 * VFS inode of the ntfs index inode to which the index entry belongs dirty,
120 * too (I_DIRTY_PAGES) and this in turn ensures the page buffers, and hence the
121 * dirty index block, will be written out to disk later.
123 static inline void ntfs_index_entry_mark_dirty(ntfs_index_context *ictx)
125 if (ictx->is_in_root)
126 mark_mft_record_dirty(ictx->actx->ntfs_ino);
128 mark_ntfs_record_dirty(ictx->page,
129 (u8*)ictx->ia - (u8*)page_address(ictx->page));
134 #endif /* _LINUX_NTFS_INDEX_H */