1*9663SMark.Logan@Sun.COM /* 2*9663SMark.Logan@Sun.COM * index.h - Defines for NTFS index handling. Part of the Linux-NTFS project. 3*9663SMark.Logan@Sun.COM * 4*9663SMark.Logan@Sun.COM * Copyright (c) 2004 Anton Altaparmakov 5*9663SMark.Logan@Sun.COM * Copyright (c) 2004-2005 Richard Russon 6*9663SMark.Logan@Sun.COM * Copyright (c) 2005-2006 Yura Pakhuchiy 7*9663SMark.Logan@Sun.COM * Copyright (c) 2006 Szabolcs Szakacsits 8*9663SMark.Logan@Sun.COM * 9*9663SMark.Logan@Sun.COM * This program/include file is free software; you can redistribute it and/or 10*9663SMark.Logan@Sun.COM * modify it under the terms of the GNU General Public License as published 11*9663SMark.Logan@Sun.COM * by the Free Software Foundation; either version 2 of the License, or 12*9663SMark.Logan@Sun.COM * (at your option) any later version. 13*9663SMark.Logan@Sun.COM * 14*9663SMark.Logan@Sun.COM * This program/include file is distributed in the hope that it will be 15*9663SMark.Logan@Sun.COM * useful, but WITHOUT ANY WARRANTY; without even the implied warranty 16*9663SMark.Logan@Sun.COM * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17*9663SMark.Logan@Sun.COM * GNU General Public License for more details. 18*9663SMark.Logan@Sun.COM * 19*9663SMark.Logan@Sun.COM * You should have received a copy of the GNU General Public License 20*9663SMark.Logan@Sun.COM * along with this program (in the main directory of the Linux-NTFS 21*9663SMark.Logan@Sun.COM * distribution in the file COPYING); if not, write to the Free Software 22*9663SMark.Logan@Sun.COM * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 23*9663SMark.Logan@Sun.COM */ 24*9663SMark.Logan@Sun.COM 25*9663SMark.Logan@Sun.COM #ifndef _NTFS_INDEX_H 26*9663SMark.Logan@Sun.COM #define _NTFS_INDEX_H 27*9663SMark.Logan@Sun.COM 28*9663SMark.Logan@Sun.COM #include "attrib.h" 29*9663SMark.Logan@Sun.COM #include "types.h" 30*9663SMark.Logan@Sun.COM #include "layout.h" 31*9663SMark.Logan@Sun.COM #include "inode.h" 32*9663SMark.Logan@Sun.COM #include "mft.h" 33*9663SMark.Logan@Sun.COM 34*9663SMark.Logan@Sun.COM #define VCN_INDEX_ROOT_PARENT ((VCN)-2) 35*9663SMark.Logan@Sun.COM 36*9663SMark.Logan@Sun.COM #define MAX_PARENT_VCN 32 37*9663SMark.Logan@Sun.COM 38*9663SMark.Logan@Sun.COM /** 39*9663SMark.Logan@Sun.COM * struct ntfs_index_context - 40*9663SMark.Logan@Sun.COM * @ni: inode containing the @entry described by this context 41*9663SMark.Logan@Sun.COM * @name: name of the index described by this context 42*9663SMark.Logan@Sun.COM * @name_len: length of the index name 43*9663SMark.Logan@Sun.COM * @entry: index entry (points into @ir or @ib) 44*9663SMark.Logan@Sun.COM * @data: index entry data (points into @entry) 45*9663SMark.Logan@Sun.COM * @data_len: length in bytes of @data 46*9663SMark.Logan@Sun.COM * @cr: 47*9663SMark.Logan@Sun.COM * @is_in_root: TRUE if @entry is in @ir or FALSE if it is in @ib 48*9663SMark.Logan@Sun.COM * @ir: index root if @is_in_root or NULL otherwise 49*9663SMark.Logan@Sun.COM * @actx: attribute search context if in root or NULL otherwise 50*9663SMark.Logan@Sun.COM * @ia_na: opened INDEX_ALLOCATION attribute 51*9663SMark.Logan@Sun.COM * @ib: index block if @is_in_root is FALSE or NULL otherwise 52*9663SMark.Logan@Sun.COM * @ib_vcn: VCN from which @ib where read from 53*9663SMark.Logan@Sun.COM * @ib_dirty: TRUE if index block was changed 54*9663SMark.Logan@Sun.COM * @parent_pos: parent entries' positions in the index block 55*9663SMark.Logan@Sun.COM * @parent_vcn: entry's parent nodes or VCN_INDEX_ROOT_PARENT for root 56*9663SMark.Logan@Sun.COM * @max_depth: number of the parent nodes 57*9663SMark.Logan@Sun.COM * @pindex: maximum it's the number of the parent nodes 58*9663SMark.Logan@Sun.COM * @block_size: index block size 59*9663SMark.Logan@Sun.COM * @vcn_size_bits: VCN size bits for this index block 60*9663SMark.Logan@Sun.COM * 61*9663SMark.Logan@Sun.COM * @ni is the inode this context belongs to. 62*9663SMark.Logan@Sun.COM * 63*9663SMark.Logan@Sun.COM * @entry is the index entry described by this context. @data and @data_len 64*9663SMark.Logan@Sun.COM * are the index entry data and its length in bytes, respectively. @data 65*9663SMark.Logan@Sun.COM * simply points into @entry. This is probably what the user is interested in. 66*9663SMark.Logan@Sun.COM * 67*9663SMark.Logan@Sun.COM * If @is_in_root is TRUE, @entry is in the index root attribute @ir described 68*9663SMark.Logan@Sun.COM * by the attribute search context @actx and inode @ni. @ib, @ib_vcn and 69*9663SMark.Logan@Sun.COM * @ib_dirty are undefined in this case. 70*9663SMark.Logan@Sun.COM * 71*9663SMark.Logan@Sun.COM * If @is_in_root is FALSE, @entry is in the index allocation attribute and @ib 72*9663SMark.Logan@Sun.COM * and @ib_vcn point to the index allocation block and VCN where it's placed, 73*9663SMark.Logan@Sun.COM * respectively. @ir and @actx are NULL in this case. @ia_na is opened 74*9663SMark.Logan@Sun.COM * INDEX_ALLOCATION attribute. @ib_dirty is TRUE if index block was changed and 75*9663SMark.Logan@Sun.COM * FALSE otherwise. 76*9663SMark.Logan@Sun.COM * 77*9663SMark.Logan@Sun.COM * To obtain a context call ntfs_index_ctx_get(). 78*9663SMark.Logan@Sun.COM * 79*9663SMark.Logan@Sun.COM * When finished with the @entry and its @data, call ntfs_index_ctx_put() to 80*9663SMark.Logan@Sun.COM * free the context and other associated resources. 81*9663SMark.Logan@Sun.COM * 82*9663SMark.Logan@Sun.COM * If the index entry was modified, call ntfs_index_entry_mark_dirty() before 83*9663SMark.Logan@Sun.COM * the call to ntfs_index_ctx_put() to ensure that the changes are written 84*9663SMark.Logan@Sun.COM * to disk. 85*9663SMark.Logan@Sun.COM */ 86*9663SMark.Logan@Sun.COM typedef struct { 87*9663SMark.Logan@Sun.COM ntfs_inode *ni; 88*9663SMark.Logan@Sun.COM ntfschar *name; 89*9663SMark.Logan@Sun.COM u32 name_len; 90*9663SMark.Logan@Sun.COM INDEX_ENTRY *entry; 91*9663SMark.Logan@Sun.COM void *data; 92*9663SMark.Logan@Sun.COM u16 data_len; 93*9663SMark.Logan@Sun.COM COLLATION_RULES cr; 94*9663SMark.Logan@Sun.COM BOOL is_in_root; 95*9663SMark.Logan@Sun.COM INDEX_ROOT *ir; 96*9663SMark.Logan@Sun.COM ntfs_attr_search_ctx *actx; 97*9663SMark.Logan@Sun.COM ntfs_attr *ia_na; 98*9663SMark.Logan@Sun.COM INDEX_BLOCK *ib; 99*9663SMark.Logan@Sun.COM VCN ib_vcn; 100*9663SMark.Logan@Sun.COM BOOL ib_dirty; 101*9663SMark.Logan@Sun.COM int parent_pos[MAX_PARENT_VCN]; 102*9663SMark.Logan@Sun.COM VCN parent_vcn[MAX_PARENT_VCN]; 103*9663SMark.Logan@Sun.COM int max_depth; 104*9663SMark.Logan@Sun.COM int pindex; 105*9663SMark.Logan@Sun.COM u32 block_size; 106*9663SMark.Logan@Sun.COM u8 vcn_size_bits; 107*9663SMark.Logan@Sun.COM } ntfs_index_context; 108*9663SMark.Logan@Sun.COM 109*9663SMark.Logan@Sun.COM extern ntfs_index_context *ntfs_index_ctx_get(ntfs_inode *ni, 110*9663SMark.Logan@Sun.COM ntfschar *name, u32 name_len); 111*9663SMark.Logan@Sun.COM extern void ntfs_index_ctx_put(ntfs_index_context *ictx); 112*9663SMark.Logan@Sun.COM extern void ntfs_index_ctx_reinit(ntfs_index_context *ictx); 113*9663SMark.Logan@Sun.COM 114*9663SMark.Logan@Sun.COM extern int ntfs_index_lookup(const void *key, const int key_len, 115*9663SMark.Logan@Sun.COM ntfs_index_context *ictx); 116*9663SMark.Logan@Sun.COM 117*9663SMark.Logan@Sun.COM extern int ntfs_index_add_filename(ntfs_inode *ni, FILE_NAME_ATTR *fn, 118*9663SMark.Logan@Sun.COM MFT_REF mref); 119*9663SMark.Logan@Sun.COM extern int ntfs_index_rm(ntfs_index_context *ictx); 120*9663SMark.Logan@Sun.COM 121*9663SMark.Logan@Sun.COM extern INDEX_ROOT *ntfs_index_root_get(ntfs_inode *ni, ATTR_RECORD *attr); 122*9663SMark.Logan@Sun.COM 123*9663SMark.Logan@Sun.COM extern VCN ntfs_ie_get_vcn(INDEX_ENTRY *ie); 124*9663SMark.Logan@Sun.COM 125*9663SMark.Logan@Sun.COM extern char *ntfs_ie_filename_get(INDEX_ENTRY *ie); 126*9663SMark.Logan@Sun.COM extern void ntfs_ie_filename_dump(INDEX_ENTRY *ie); 127*9663SMark.Logan@Sun.COM extern void ntfs_ih_filename_dump(INDEX_HEADER *ih); 128*9663SMark.Logan@Sun.COM 129*9663SMark.Logan@Sun.COM extern void ntfs_index_entry_mark_dirty(ntfs_index_context *ictx); 130*9663SMark.Logan@Sun.COM 131*9663SMark.Logan@Sun.COM #endif /* _NTFS_INDEX_H */ 132