xref: /linux/fs/ntfs/index.h (revision cdd4dc3aebeab43a72ce0bc2b5bab6f0a80b97a5)
11e9ea7e0SNamjae Jeon /* SPDX-License-Identifier: GPL-2.0-or-later */
21e9ea7e0SNamjae Jeon /*
3*40796051SNamjae Jeon  * Defines for NTFS kernel index handling.
41e9ea7e0SNamjae Jeon  *
51e9ea7e0SNamjae Jeon  * Copyright (c) 2004 Anton Altaparmakov
61e9ea7e0SNamjae Jeon  */
71e9ea7e0SNamjae Jeon 
81e9ea7e0SNamjae Jeon #ifndef _LINUX_NTFS_INDEX_H
91e9ea7e0SNamjae Jeon #define _LINUX_NTFS_INDEX_H
101e9ea7e0SNamjae Jeon 
111e9ea7e0SNamjae Jeon #include <linux/fs.h>
121e9ea7e0SNamjae Jeon 
131e9ea7e0SNamjae Jeon #include "attrib.h"
141e9ea7e0SNamjae Jeon #include "mft.h"
151e9ea7e0SNamjae Jeon 
16*40796051SNamjae Jeon #define  VCN_INDEX_ROOT_PARENT  ((s64)-2)
17*40796051SNamjae Jeon 
18*40796051SNamjae Jeon #define MAX_PARENT_VCN	32
19*40796051SNamjae Jeon 
20*40796051SNamjae Jeon /*
211e9ea7e0SNamjae Jeon  * @idx_ni:	index inode containing the @entry described by this context
22*40796051SNamjae Jeon  * @name:	Unicode name of the indexed attribute
23*40796051SNamjae Jeon  *		(usually $I30 for directories)
24*40796051SNamjae Jeon  * @name_len:	length of @name in Unicode characters
251e9ea7e0SNamjae Jeon  * @entry:	index entry (points into @ir or @ia)
26*40796051SNamjae Jeon  * @cr:		creation time of the entry (for sorting/validation)
271e9ea7e0SNamjae Jeon  * @data:	index entry data (points into @entry)
281e9ea7e0SNamjae Jeon  * @data_len:	length in bytes of @data
291e9ea7e0SNamjae Jeon  * @is_in_root:	'true' if @entry is in @ir and 'false' if it is in @ia
301e9ea7e0SNamjae Jeon  * @ir:		index root if @is_in_root and NULL otherwise
311e9ea7e0SNamjae Jeon  * @actx:	attribute search context if @is_in_root and NULL otherwise
32*40796051SNamjae Jeon  * @ib:		index block header (valid when @is_in_root is 'false')
33*40796051SNamjae Jeon  * @ia_ni:	index allocation inode (extent inode) for @ia
34*40796051SNamjae Jeon  * @parent_pos:	array of parent entry positions in the B-tree nodes
35*40796051SNamjae Jeon  * @parent_vcn:	VCNs of parent index blocks in the B-tree traversal
36*40796051SNamjae Jeon  * @pindex:	current depth (number of parent nodes) in the traversal
37*40796051SNamjae Jeon  *		(maximum is MAX_PARENT_VCN)
38*40796051SNamjae Jeon  * @ib_dirty:	true if the current index block (@ia/@ib) was modified
39*40796051SNamjae Jeon  * @block_size:	size of index blocks in bytes (from $INDEX_ROOT or $Boot)
40*40796051SNamjae Jeon  * @vcn_size_bits: log2(cluster size)
41*40796051SNamjae Jeon  * @sync_write:	true if synchronous writeback is requested for this context
421e9ea7e0SNamjae Jeon  *
431e9ea7e0SNamjae Jeon  * @idx_ni is the index inode this context belongs to.
441e9ea7e0SNamjae Jeon  *
451e9ea7e0SNamjae Jeon  * @entry is the index entry described by this context.  @data and @data_len
461e9ea7e0SNamjae Jeon  * are the index entry data and its length in bytes, respectively.  @data
471e9ea7e0SNamjae Jeon  * simply points into @entry.  This is probably what the user is interested in.
481e9ea7e0SNamjae Jeon  *
491e9ea7e0SNamjae Jeon  * If @is_in_root is 'true', @entry is in the index root attribute @ir described
501e9ea7e0SNamjae Jeon  * by the attribute search context @actx and the base inode @base_ni.  @ia and
511e9ea7e0SNamjae Jeon  * @page are NULL in this case.
521e9ea7e0SNamjae Jeon  *
531e9ea7e0SNamjae Jeon  * If @is_in_root is 'false', @entry is in the index allocation attribute and @ia
541e9ea7e0SNamjae Jeon  * and @page point to the index allocation block and the mapped, locked page it
551e9ea7e0SNamjae Jeon  * is in, respectively.  @ir, @actx and @base_ni are NULL in this case.
561e9ea7e0SNamjae Jeon  *
571e9ea7e0SNamjae Jeon  * To obtain a context call ntfs_index_ctx_get().
581e9ea7e0SNamjae Jeon  *
591e9ea7e0SNamjae Jeon  * We use this context to allow ntfs_index_lookup() to return the found index
601e9ea7e0SNamjae Jeon  * @entry and its @data without having to allocate a buffer and copy the @entry
611e9ea7e0SNamjae Jeon  * and/or its @data into it.
621e9ea7e0SNamjae Jeon  *
631e9ea7e0SNamjae Jeon  * When finished with the @entry and its @data, call ntfs_index_ctx_put() to
641e9ea7e0SNamjae Jeon  * free the context and other associated resources.
651e9ea7e0SNamjae Jeon  *
66*40796051SNamjae Jeon  * If the index entry was modified, ntfs_index_entry_mark_dirty()
671e9ea7e0SNamjae Jeon  * or ntfs_index_entry_write() before the call to ntfs_index_ctx_put() to
681e9ea7e0SNamjae Jeon  * ensure that the changes are written to disk.
691e9ea7e0SNamjae Jeon  */
70*40796051SNamjae Jeon struct ntfs_index_context {
71*40796051SNamjae Jeon 	struct ntfs_inode *idx_ni;
72*40796051SNamjae Jeon 	__le16 *name;
73*40796051SNamjae Jeon 	u32 name_len;
74*40796051SNamjae Jeon 	struct index_entry *entry;
75*40796051SNamjae Jeon 	__le32 cr;
761e9ea7e0SNamjae Jeon 	void *data;
771e9ea7e0SNamjae Jeon 	u16 data_len;
781e9ea7e0SNamjae Jeon 	bool is_in_root;
79*40796051SNamjae Jeon 	struct index_root *ir;
80*40796051SNamjae Jeon 	struct ntfs_attr_search_ctx *actx;
81*40796051SNamjae Jeon 	struct index_block *ib;
82*40796051SNamjae Jeon 	struct ntfs_inode *ia_ni;
83*40796051SNamjae Jeon 	int parent_pos[MAX_PARENT_VCN];
84*40796051SNamjae Jeon 	s64 parent_vcn[MAX_PARENT_VCN];
85*40796051SNamjae Jeon 	int pindex;
86*40796051SNamjae Jeon 	bool ib_dirty;
87*40796051SNamjae Jeon 	u32 block_size;
88*40796051SNamjae Jeon 	u8 vcn_size_bits;
89*40796051SNamjae Jeon 	bool sync_write;
90*40796051SNamjae Jeon };
911e9ea7e0SNamjae Jeon 
92*40796051SNamjae Jeon int ntfs_index_entry_inconsistent(struct ntfs_index_context *icx, struct ntfs_volume *vol,
93*40796051SNamjae Jeon 		const struct index_entry *ie, __le32 collation_rule, u64 inum);
94*40796051SNamjae Jeon struct ntfs_index_context *ntfs_index_ctx_get(struct ntfs_inode *ni, __le16 *name,
95*40796051SNamjae Jeon 		u32 name_len);
96*40796051SNamjae Jeon void ntfs_index_ctx_put(struct ntfs_index_context *ictx);
97*40796051SNamjae Jeon int ntfs_index_lookup(const void *key, const u32 key_len,
98*40796051SNamjae Jeon 		struct ntfs_index_context *ictx);
991e9ea7e0SNamjae Jeon 
100*40796051SNamjae Jeon void ntfs_index_entry_mark_dirty(struct ntfs_index_context *ictx);
101*40796051SNamjae Jeon int ntfs_index_add_filename(struct ntfs_inode *ni, struct file_name_attr *fn, u64 mref);
102*40796051SNamjae Jeon int ntfs_index_remove(struct ntfs_inode *ni, const void *key, const u32 keylen);
103*40796051SNamjae Jeon struct ntfs_inode *ntfs_ia_open(struct ntfs_index_context *icx, struct ntfs_inode *ni);
104*40796051SNamjae Jeon struct index_entry *ntfs_index_walk_down(struct index_entry *ie, struct ntfs_index_context *ictx);
105*40796051SNamjae Jeon struct index_entry *ntfs_index_next(struct index_entry *ie, struct ntfs_index_context *ictx);
106*40796051SNamjae Jeon int ntfs_index_rm(struct ntfs_index_context *icx);
107*40796051SNamjae Jeon void ntfs_index_ctx_reinit(struct ntfs_index_context *icx);
108*40796051SNamjae Jeon int ntfs_ie_add(struct ntfs_index_context *icx, struct index_entry *ie);
109*40796051SNamjae Jeon int ntfs_icx_ib_sync_write(struct ntfs_index_context *icx);
1101e9ea7e0SNamjae Jeon 
1111e9ea7e0SNamjae Jeon #endif /* _LINUX_NTFS_INDEX_H */
112