Fixed a constant string concatenation
[ntfs-3g.git] / include / ntfs-3g / index.h
blob036b742fb5e9c7744954bbb80df762bead051da7
1 /*
2 * index.h - Defines for NTFS index handling. Originated from the Linux-NTFS project.
4 * Copyright (c) 2004 Anton Altaparmakov
5 * Copyright (c) 2004-2005 Richard Russon
6 * Copyright (c) 2005 Yura Pakhuchiy
7 * Copyright (c) 2006-2008 Szabolcs Szakacsits
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.
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.
19 * You should have received a copy of the GNU General Public License
20 * along with this program (in the main directory of the NTFS-3G
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
25 #ifndef _NTFS_INDEX_H
26 #define _NTFS_INDEX_H
28 /* Convenience macros to test the versions of gcc.
29 * Use them like this:
30 * #if __GNUC_PREREQ (2,8)
31 * ... code requiring gcc 2.8 or later ...
32 * #endif
33 * Note - they won't work for gcc1 or glibc1, since the _MINOR macros
34 * were not defined then.
37 #ifndef __GNUC_PREREQ
38 # if defined __GNUC__ && defined __GNUC_MINOR__
39 # define __GNUC_PREREQ(maj, min) \
40 ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
41 # else
42 # define __GNUC_PREREQ(maj, min) 0
43 # endif
44 #endif
46 /* allows us to warn about unused results of certain function calls */
47 #ifndef __attribute_warn_unused_result__
48 # if __GNUC_PREREQ (3,4)
49 # define __attribute_warn_unused_result__ \
50 __attribute__ ((__warn_unused_result__))
51 # else
52 # define __attribute_warn_unused_result__ /* empty */
53 # endif
54 #endif
56 #include "attrib.h"
57 #include "types.h"
58 #include "layout.h"
59 #include "inode.h"
60 #include "mft.h"
62 #define VCN_INDEX_ROOT_PARENT ((VCN)-2)
64 #define MAX_PARENT_VCN 32
66 typedef int (*COLLATE)(ntfs_volume *vol, const void *data1, int len1,
67 const void *data2, int len2);
69 /**
70 * struct ntfs_index_context -
71 * @ni: inode containing the @entry described by this context
72 * @name: name of the index described by this context
73 * @name_len: length of the index name
74 * @entry: index entry (points into @ir or @ia)
75 * @data: index entry data (points into @entry)
76 * @data_len: length in bytes of @data
77 * @is_in_root: TRUE if @entry is in @ir or FALSE if it is in @ia
78 * @ir: index root if @is_in_root or NULL otherwise
79 * @actx: attribute search context if in root or NULL otherwise
80 * @ia: index block if @is_in_root is FALSE or NULL otherwise
81 * @ia_na: opened INDEX_ALLOCATION attribute
82 * @parent_pos: parent entries' positions in the index block
83 * @parent_vcn: entry's parent node or VCN_INDEX_ROOT_PARENT
84 * @new_vcn: new VCN if we need to create a new index block
85 * @median: move to the parent if splitting index blocks
86 * @ib_dirty: TRUE if index block was changed
87 * @block_size: index block size
88 * @vcn_size_bits: VCN size bits for this index block
90 * @ni is the inode this context belongs to.
92 * @entry is the index entry described by this context. @data and @data_len
93 * are the index entry data and its length in bytes, respectively. @data
94 * simply points into @entry. This is probably what the user is interested in.
96 * If @is_in_root is TRUE, @entry is in the index root attribute @ir described
97 * by the attribute search context @actx and inode @ni. @ia and
98 * @ib_dirty are undefined in this case.
100 * If @is_in_root is FALSE, @entry is in the index allocation attribute and @ia
101 * point to the index allocation block and VCN where it's placed,
102 * respectively. @ir and @actx are NULL in this case. @ia_na is opened
103 * INDEX_ALLOCATION attribute. @ib_dirty is TRUE if index block was changed and
104 * FALSE otherwise.
106 * To obtain a context call ntfs_index_ctx_get().
108 * When finished with the @entry and its @data, call ntfs_index_ctx_put() to
109 * free the context and other associated resources.
111 * If the index entry was modified, call ntfs_index_entry_mark_dirty() before
112 * the call to ntfs_index_ctx_put() to ensure that the changes are written
113 * to disk.
115 typedef struct {
116 ntfs_inode *ni;
117 ntfschar *name;
118 u32 name_len;
119 INDEX_ENTRY *entry;
120 void *data;
121 u16 data_len;
122 COLLATE collate;
123 BOOL is_in_root;
124 INDEX_ROOT *ir;
125 ntfs_attr_search_ctx *actx;
126 INDEX_BLOCK *ib;
127 ntfs_attr *ia_na;
128 int parent_pos[MAX_PARENT_VCN]; /* parent entries' positions */
129 VCN parent_vcn[MAX_PARENT_VCN]; /* entry's parent nodes */
130 int pindex; /* maximum it's the number of the parent nodes */
131 BOOL ib_dirty;
132 BOOL bad_index;
133 u32 block_size;
134 u8 vcn_size_bits;
135 } ntfs_index_context;
137 extern ntfs_index_context *ntfs_index_ctx_get(ntfs_inode *ni,
138 ntfschar *name, u32 name_len);
139 extern void ntfs_index_ctx_put(ntfs_index_context *ictx);
140 extern void ntfs_index_ctx_reinit(ntfs_index_context *ictx);
142 extern int ntfs_index_lookup(const void *key, const int key_len,
143 ntfs_index_context *ictx) __attribute_warn_unused_result__;
145 extern INDEX_ENTRY *ntfs_index_next(INDEX_ENTRY *ie,
146 ntfs_index_context *ictx);
148 extern int ntfs_index_add_filename(ntfs_inode *ni, FILE_NAME_ATTR *fn,
149 MFT_REF mref);
150 extern int ntfs_index_remove(ntfs_inode *dir_ni, ntfs_inode *ni,
151 const void *key, const int keylen);
153 extern INDEX_ROOT *ntfs_index_root_get(ntfs_inode *ni, ATTR_RECORD *attr);
155 extern VCN ntfs_ie_get_vcn(INDEX_ENTRY *ie);
157 extern void ntfs_index_entry_mark_dirty(ntfs_index_context *ictx);
159 extern char *ntfs_ie_filename_get(INDEX_ENTRY *ie);
160 extern void ntfs_ie_filename_dump(INDEX_ENTRY *ie);
161 extern void ntfs_ih_filename_dump(INDEX_HEADER *ih);
163 /* the following was added by JPA for use in security.c */
164 extern int ntfs_ie_add(ntfs_index_context *icx, INDEX_ENTRY *ie);
165 extern int ntfs_index_rm(ntfs_index_context *icx);
167 #endif /* _NTFS_INDEX_H */