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 #include "aops.h" 34 35 /** 36 * @idx_ni: index inode containing the @entry described by this context 37 * @entry: index entry (points into @ir or @ia) 38 * @data: index entry data (points into @entry) 39 * @data_len: length in bytes of @data 40 * @is_in_root: 'true' if @entry is in @ir and 'false' if it is in @ia 41 * @ir: index root if @is_in_root and NULL otherwise 42 * @actx: attribute search context if @is_in_root and NULL otherwise 43 * @base_ni: base inode if @is_in_root and NULL otherwise 44 * @ia: index block if @is_in_root is 'false' and NULL otherwise 45 * @page: page if @is_in_root is 'false' and NULL otherwise 46 * 47 * @idx_ni is the index inode this context belongs to. 48 * 49 * @entry is the index entry described by this context. @data and @data_len 50 * are the index entry data and its length in bytes, respectively. @data 51 * simply points into @entry. This is probably what the user is interested in. 52 * 53 * If @is_in_root is 'true', @entry is in the index root attribute @ir described 54 * by the attribute search context @actx and the base inode @base_ni. @ia and 55 * @page are NULL in this case. 56 * 57 * If @is_in_root is 'false', @entry is in the index allocation attribute and @ia 58 * and @page point to the index allocation block and the mapped, locked page it 59 * is in, respectively. @ir, @actx and @base_ni are NULL in this case. 60 * 61 * To obtain a context call ntfs_index_ctx_get(). 62 * 63 * We use this context to allow ntfs_index_lookup() to return the found index 64 * @entry and its @data without having to allocate a buffer and copy the @entry 65 * and/or its @data into it. 66 * 67 * When finished with the @entry and its @data, call ntfs_index_ctx_put() to 68 * free the context and other associated resources. 69 * 70 * If the index entry was modified, call flush_dcache_index_entry_page() 71 * immediately after the modification and either ntfs_index_entry_mark_dirty() 72 * or ntfs_index_entry_write() before the call to ntfs_index_ctx_put() to 73 * ensure that the changes are written to disk. 74 */ 75 typedef struct { 76 ntfs_inode *idx_ni; 77 INDEX_ENTRY *entry; 78 void *data; 79 u16 data_len; 80 bool is_in_root; 81 INDEX_ROOT *ir; 82 ntfs_attr_search_ctx *actx; 83 ntfs_inode *base_ni; 84 INDEX_ALLOCATION *ia; 85 struct page *page; 86 } ntfs_index_context; 87 88 extern ntfs_index_context *ntfs_index_ctx_get(ntfs_inode *idx_ni); 89 extern void ntfs_index_ctx_put(ntfs_index_context *ictx); 90 91 extern int ntfs_index_lookup(const void *key, const int key_len, 92 ntfs_index_context *ictx); 93 94 #ifdef NTFS_RW 95 96 /** 97 * ntfs_index_entry_flush_dcache_page - flush_dcache_page() for index entries 98 * @ictx: ntfs index context describing the index entry 99 * 100 * Call flush_dcache_page() for the page in which an index entry resides. 101 * 102 * This must be called every time an index entry is modified, just after the 103 * modification. 104 * 105 * If the index entry is in the index root attribute, simply flush the page 106 * containing the mft record containing the index root attribute. 107 * 108 * If the index entry is in an index block belonging to the index allocation 109 * attribute, simply flush the page cache page containing the index block. 110 */ 111 static inline void ntfs_index_entry_flush_dcache_page(ntfs_index_context *ictx) 112 { 113 if (ictx->is_in_root) 114 flush_dcache_mft_record_page(ictx->actx->ntfs_ino); 115 else 116 flush_dcache_page(ictx->page); 117 } 118 119 /** 120 * ntfs_index_entry_mark_dirty - mark an index entry dirty 121 * @ictx: ntfs index context describing the index entry 122 * 123 * Mark the index entry described by the index entry context @ictx dirty. 124 * 125 * If the index entry is in the index root attribute, simply mark the mft 126 * record containing the index root attribute dirty. This ensures the mft 127 * record, and hence the index root attribute, will be written out to disk 128 * later. 129 * 130 * If the index entry is in an index block belonging to the index allocation 131 * attribute, mark the buffers belonging to the index record as well as the 132 * page cache page the index block is in dirty. This automatically marks the 133 * VFS inode of the ntfs index inode to which the index entry belongs dirty, 134 * too (I_DIRTY_PAGES) and this in turn ensures the page buffers, and hence the 135 * dirty index block, will be written out to disk later. 136 */ 137 static inline void ntfs_index_entry_mark_dirty(ntfs_index_context *ictx) 138 { 139 if (ictx->is_in_root) 140 mark_mft_record_dirty(ictx->actx->ntfs_ino); 141 else 142 mark_ntfs_record_dirty(ictx->page, 143 (u8*)ictx->ia - (u8*)page_address(ictx->page)); 144 } 145 146 #endif /* NTFS_RW */ 147 148 #endif /* _LINUX_NTFS_INDEX_H */ 149