MOXA linux-2.6.x / linux-2.6.9-uc0 from sdlinux-moxaart.tgz
[linux-2.6.9-moxart.git] / fs / ntfs / index.h
blob159442dfa90a1eb46b13b58bbbd8b2ee74531968
1 /*
2 * index.h - Defines for NTFS kernel index handling. Part of the Linux-NTFS
3 * project.
5 * Copyright (c) 2004 Anton Altaparmakov
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.
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.
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
23 #ifndef _LINUX_NTFS_INDEX_H
24 #define _LINUX_NTFS_INDEX_H
26 #include <linux/fs.h>
28 #include "types.h"
29 #include "layout.h"
30 #include "inode.h"
31 #include "attrib.h"
32 #include "mft.h"
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
46 * @idx_ni is the index inode this context belongs to.
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.
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.
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.
60 * To obtain a context call ntfs_index_ctx_get().
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.
66 * When finished with the @entry and its @data, call ntfs_index_ctx_put() to
67 * free the context and other associated resources.
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.
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 ntfs_attr_search_ctx *actx;
82 ntfs_inode *base_ni;
83 INDEX_ALLOCATION *ia;
84 struct page *page;
85 } ntfs_index_context;
87 extern ntfs_index_context *ntfs_index_ctx_get(ntfs_inode *idx_ni);
88 extern void ntfs_index_ctx_put(ntfs_index_context *ictx);
90 extern int ntfs_index_lookup(const void *key, const int key_len,
91 ntfs_index_context *ictx);
93 #ifdef NTFS_RW
95 /**
96 * ntfs_index_entry_flush_dcache_page - flush_dcache_page() for index entries
97 * @ictx: ntfs index context describing the index entry
99 * Call flush_dcache_page() for the page in which an index entry resides.
101 * This must be called every time an index entry is modified, just after the
102 * modification.
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.
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.
110 static inline void ntfs_index_entry_flush_dcache_page(ntfs_index_context *ictx)
112 if (ictx->is_in_root)
113 flush_dcache_mft_record_page(ictx->actx->ntfs_ino);
114 else
115 flush_dcache_page(ictx->page);
118 extern void __ntfs_index_entry_mark_dirty(ntfs_index_context *ictx);
121 * ntfs_index_entry_mark_dirty - mark an index entry dirty
122 * @ictx: ntfs index context describing the index entry
124 * Mark the index entry described by the index entry context @ictx dirty.
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.
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.
138 static inline void ntfs_index_entry_mark_dirty(ntfs_index_context *ictx)
140 if (ictx->is_in_root)
141 mark_mft_record_dirty(ictx->actx->ntfs_ino);
142 else
143 __ntfs_index_entry_mark_dirty(ictx);
146 #endif /* NTFS_RW */
148 #endif /* _LINUX_NTFS_INDEX_H */