1 /* SPDX-License-Identifier: GPL-2.0-or-later */ 2 /* 3 * Defines for NTFS kernel index handling. 4 * 5 * Copyright (c) 2004 Anton Altaparmakov 6 */ 7 8 #ifndef _LINUX_NTFS_INDEX_H 9 #define _LINUX_NTFS_INDEX_H 10 11 #include <linux/fs.h> 12 13 #include "attrib.h" 14 #include "mft.h" 15 16 #define VCN_INDEX_ROOT_PARENT ((s64)-2) 17 18 #define MAX_PARENT_VCN 32 19 20 /* 21 * @idx_ni: index inode containing the @entry described by this context 22 * @name: Unicode name of the indexed attribute 23 * (usually $I30 for directories) 24 * @name_len: length of @name in Unicode characters 25 * @entry: index entry (points into @ir or @ia) 26 * @cr: creation time of the entry (for sorting/validation) 27 * @data: index entry data (points into @entry) 28 * @data_len: length in bytes of @data 29 * @is_in_root: 'true' if @entry is in @ir and 'false' if it is in @ia 30 * @ir: index root if @is_in_root and NULL otherwise 31 * @actx: attribute search context if @is_in_root and NULL otherwise 32 * @ib: index block header (valid when @is_in_root is 'false') 33 * @ia_ni: index allocation inode (extent inode) for @ia 34 * @parent_pos: array of parent entry positions in the B-tree nodes 35 * @parent_vcn: VCNs of parent index blocks in the B-tree traversal 36 * @pindex: current depth (number of parent nodes) in the traversal 37 * (maximum is MAX_PARENT_VCN) 38 * @ib_dirty: true if the current index block (@ia/@ib) was modified 39 * @block_size: size of index blocks in bytes (from $INDEX_ROOT or $Boot) 40 * @vcn_size_bits: log2(cluster size) 41 * @sync_write: true if synchronous writeback is requested for this context 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, ntfs_index_entry_mark_dirty() 67 * or ntfs_index_entry_write() before the call to ntfs_index_ctx_put() to 68 * ensure that the changes are written to disk. 69 */ 70 struct ntfs_index_context { 71 struct ntfs_inode *idx_ni; 72 __le16 *name; 73 u32 name_len; 74 struct index_entry *entry; 75 __le32 cr; 76 void *data; 77 u16 data_len; 78 bool is_in_root; 79 struct index_root *ir; 80 struct ntfs_attr_search_ctx *actx; 81 struct index_block *ib; 82 struct ntfs_inode *ia_ni; 83 int parent_pos[MAX_PARENT_VCN]; 84 s64 parent_vcn[MAX_PARENT_VCN]; 85 int pindex; 86 bool ib_dirty; 87 u32 block_size; 88 u8 vcn_size_bits; 89 bool sync_write; 90 }; 91 92 int ntfs_index_entry_inconsistent(struct ntfs_index_context *icx, struct ntfs_volume *vol, 93 const struct index_entry *ie, __le32 collation_rule, u64 inum); 94 struct ntfs_index_context *ntfs_index_ctx_get(struct ntfs_inode *ni, __le16 *name, 95 u32 name_len); 96 void ntfs_index_ctx_put(struct ntfs_index_context *ictx); 97 int ntfs_index_lookup(const void *key, const u32 key_len, 98 struct ntfs_index_context *ictx); 99 100 void ntfs_index_entry_mark_dirty(struct ntfs_index_context *ictx); 101 int ntfs_index_add_filename(struct ntfs_inode *ni, struct file_name_attr *fn, u64 mref); 102 int ntfs_index_remove(struct ntfs_inode *ni, const void *key, const u32 keylen); 103 struct ntfs_inode *ntfs_ia_open(struct ntfs_index_context *icx, struct ntfs_inode *ni); 104 struct index_entry *ntfs_index_walk_down(struct index_entry *ie, struct ntfs_index_context *ictx); 105 struct index_entry *ntfs_index_next(struct index_entry *ie, struct ntfs_index_context *ictx); 106 int ntfs_index_rm(struct ntfs_index_context *icx); 107 void ntfs_index_ctx_reinit(struct ntfs_index_context *icx); 108 int ntfs_ie_add(struct ntfs_index_context *icx, struct index_entry *ie); 109 int ntfs_icx_ib_sync_write(struct ntfs_index_context *icx); 110 111 #endif /* _LINUX_NTFS_INDEX_H */ 112