This commit was manufactured by cvs2svn to create branch 'vserver'.
[linux-2.6.git] / fs / ntfs / index.h
1 /*
2  * index.h - Defines for NTFS kernel index handling.  Part of the Linux-NTFS
3  *           project.
4  *
5  * Copyright (c) 2004 Anton Altaparmakov
6  *
7  * This program/include file is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License as published
9  * by the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program/include file is distributed in the hope that it will be
13  * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program (in the main directory of the Linux-NTFS
19  * distribution in the file COPYING); if not, write to the Free Software
20  * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
22
23 #ifndef _LINUX_NTFS_INDEX_H
24 #define _LINUX_NTFS_INDEX_H
25
26 #include <linux/fs.h>
27
28 #include "types.h"
29 #include "layout.h"
30 #include "inode.h"
31 #include "attrib.h"
32 #include "mft.h"
33
34 /**
35  * @idx_ni:     index inode containing the @entry described by this context
36  * @entry:      index entry (points into @ir or @ia)
37  * @data:       index entry data (points into @entry)
38  * @data_len:   length in bytes of @data
39  * @is_in_root: TRUE if @entry is in @ir and FALSE if it is in @ia
40  * @ir:         index root if @is_in_root and NULL otherwise
41  * @actx:       attribute search context if @is_in_root and NULL otherwise
42  * @base_ni:    base inode if @is_in_root and NULL otherwise
43  * @ia:         index block if @is_in_root is FALSE and NULL otherwise
44  * @page:       page if @is_in_root is FALSE and NULL otherwise
45  *
46  * @idx_ni is the index inode this context belongs to.
47  *
48  * @entry is the index entry described by this context.  @data and @data_len
49  * are the index entry data and its length in bytes, respectively.  @data
50  * simply points into @entry.  This is probably what the user is interested in.
51  *
52  * If @is_in_root is TRUE, @entry is in the index root attribute @ir described
53  * by the attribute search context @actx and the base inode @base_ni.  @ia and
54  * @page are NULL in this case.
55  *
56  * If @is_in_root is FALSE, @entry is in the index allocation attribute and @ia
57  * and @page point to the index allocation block and the mapped, locked page it
58  * is in, respectively.  @ir, @actx and @base_ni are NULL in this case.
59  *
60  * To obtain a context call ntfs_index_ctx_get().
61  *
62  * We use this context to allow ntfs_index_lookup() to return the found index
63  * @entry and its @data without having to allocate a buffer and copy the @entry
64  * and/or its @data into it.
65  *
66  * When finished with the @entry and its @data, call ntfs_index_ctx_put() to
67  * free the context and other associated resources.
68  *
69  * If the index entry was modified, call flush_dcache_index_entry_page()
70  * immediately after the modification and either ntfs_index_entry_mark_dirty()
71  * or ntfs_index_entry_write() before the call to ntfs_index_ctx_put() to
72  * ensure that the changes are written to disk.
73  */
74 typedef struct {
75         ntfs_inode *idx_ni;
76         INDEX_ENTRY *entry;
77         void *data;
78         u16 data_len;
79         BOOL is_in_root;
80         INDEX_ROOT *ir;
81         attr_search_context *actx;
82         ntfs_inode *base_ni;
83         INDEX_ALLOCATION *ia;
84         struct page *page;
85 } ntfs_index_context;
86
87 extern ntfs_index_context *ntfs_index_ctx_get(ntfs_inode *idx_ni);
88 extern void ntfs_index_ctx_put(ntfs_index_context *ictx);
89
90 extern int ntfs_index_lookup(const void *key, const int key_len,
91                 ntfs_index_context *ictx);
92
93 #ifdef NTFS_RW
94
95 /**
96  * ntfs_index_entry_flush_dcache_page - flush_dcache_page() for index entries
97  * @ictx:       ntfs index context describing the index entry
98  *
99  * Call flush_dcache_page() for the page in which an index entry resides.
100  *
101  * This must be called every time an index entry is modified, just after the
102  * modification.
103  *
104  * If the index entry is in the index root attribute, simply flush the page
105  * containing the mft record containing the index root attribute.
106  *
107  * If the index entry is in an index block belonging to the index allocation
108  * attribute, simply flush the page cache page containing the index block.
109  */
110 static inline void ntfs_index_entry_flush_dcache_page(ntfs_index_context *ictx)
111 {
112         if (ictx->is_in_root)
113                 flush_dcache_mft_record_page(ictx->actx->ntfs_ino);
114         else
115                 flush_dcache_page(ictx->page);
116 }
117
118 extern void __ntfs_index_entry_mark_dirty(ntfs_index_context *ictx);
119
120 /**
121  * ntfs_index_entry_mark_dirty - mark an index entry dirty
122  * @ictx:       ntfs index context describing the index entry
123  *
124  * Mark the index entry described by the index entry context @ictx dirty.
125  *
126  * If the index entry is in the index root attribute, simply mark the mft
127  * record containing the index root attribute dirty.  This ensures the mft
128  * record, and hence the index root attribute, will be written out to disk
129  * later.
130  *
131  * If the index entry is in an index block belonging to the index allocation
132  * attribute, mark the buffers belonging to the index record as well as the
133  * page cache page the index block is in dirty.  This automatically marks the
134  * VFS inode of the ntfs index inode to which the index entry belongs dirty,
135  * too (I_DIRTY_PAGES) and this in turn ensures the page buffers, and hence the
136  * dirty index block, will be written out to disk later.
137  */
138 static inline void ntfs_index_entry_mark_dirty(ntfs_index_context *ictx)
139 {
140         if (ictx->is_in_root)
141                 mark_mft_record_dirty(ictx->actx->ntfs_ino);
142         else
143                 __ntfs_index_entry_mark_dirty(ictx);
144 }
145
146 #endif /* NTFS_RW */
147
148 #endif /* _LINUX_NTFS_INDEX_H */