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