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