1/* 2 * inode.h - Defines for NTFS inode handling. Originated from the Linux-NTFS project. 3 * 4 * Copyright (c) 2001-2004 Anton Altaparmakov 5 * Copyright (c) 2004-2007 Yura Pakhuchiy 6 * Copyright (c) 2004-2005 Richard Russon 7 * Copyright (c) 2006-2008 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 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 23 */ 24 25#ifndef _NTFS_INODE_H 26#define _NTFS_INODE_H 27 28/* Forward declaration */ 29typedef struct _ntfs_inode ntfs_inode; 30 31#include "types.h" 32#include "layout.h" 33#include "support.h" 34#include "volume.h" 35 36/** 37 * enum ntfs_inode_state_bits - 38 * 39 * Defined bits for the state field in the ntfs_inode structure. 40 * (f) = files only, (d) = directories only 41 */ 42typedef enum { 43 NI_Dirty, /* 1: Mft record needs to be written to disk. */ 44 45 /* The NI_AttrList* tests only make sense for base inodes. */ 46 NI_AttrList, /* 1: Mft record contains an attribute list. */ 47 NI_AttrListDirty, /* 1: Attribute list needs to be written to the 48 mft record and then to disk. */ 49 NI_FileNameDirty, /* 1: FILE_NAME attributes need to be updated 50 in the index. */ 51} ntfs_inode_state_bits; 52 53#define test_nino_flag(ni, flag) test_bit(NI_##flag, (ni)->state) 54#define set_nino_flag(ni, flag) set_bit(NI_##flag, (ni)->state) 55#define clear_nino_flag(ni, flag) clear_bit(NI_##flag, (ni)->state) 56 57#define test_and_set_nino_flag(ni, flag) \ 58 test_and_set_bit(NI_##flag, (ni)->state) 59#define test_and_clear_nino_flag(ni, flag) \ 60 test_and_clear_bit(NI_##flag, (ni)->state) 61 62#define NInoDirty(ni) test_nino_flag(ni, Dirty) 63#define NInoSetDirty(ni) set_nino_flag(ni, Dirty) 64#define NInoClearDirty(ni) clear_nino_flag(ni, Dirty) 65#define NInoTestAndSetDirty(ni) test_and_set_nino_flag(ni, Dirty) 66#define NInoTestAndClearDirty(ni) test_and_clear_nino_flag(ni, Dirty) 67 68#define NInoAttrList(ni) test_nino_flag(ni, AttrList) 69#define NInoSetAttrList(ni) set_nino_flag(ni, AttrList) 70#define NInoClearAttrList(ni) clear_nino_flag(ni, AttrList) 71 72 73#define test_nino_al_flag(ni, flag) test_nino_flag(ni, AttrList##flag) 74#define set_nino_al_flag(ni, flag) set_nino_flag(ni, AttrList##flag) 75#define clear_nino_al_flag(ni, flag) clear_nino_flag(ni, AttrList##flag) 76 77#define test_and_set_nino_al_flag(ni, flag) \ 78 test_and_set_nino_flag(ni, AttrList##flag) 79#define test_and_clear_nino_al_flag(ni, flag) \ 80 test_and_clear_nino_flag(ni, AttrList##flag) 81 82#define NInoAttrListDirty(ni) test_nino_al_flag(ni, Dirty) 83#define NInoAttrListSetDirty(ni) set_nino_al_flag(ni, Dirty) 84#define NInoAttrListClearDirty(ni) clear_nino_al_flag(ni, Dirty) 85#define NInoAttrListTestAndSetDirty(ni) test_and_set_nino_al_flag(ni, Dirty) 86#define NInoAttrListTestAndClearDirty(ni) test_and_clear_nino_al_flag(ni, Dirty) 87 88#define NInoFileNameDirty(ni) test_nino_flag(ni, FileNameDirty) 89#define NInoFileNameSetDirty(ni) set_nino_flag(ni, FileNameDirty) 90#define NInoFileNameClearDirty(ni) clear_nino_flag(ni, FileNameDirty) 91#define NInoFileNameTestAndSetDirty(ni) \ 92 test_and_set_nino_flag(ni, FileNameDirty) 93#define NInoFileNameTestAndClearDirty(ni) \ 94 test_and_clear_nino_flag(ni, FileNameDirty) 95 96/** 97 * struct _ntfs_inode - The NTFS in-memory inode structure. 98 * 99 * It is just used as an extension to the fields already provided in the VFS 100 * inode. 101 */ 102struct _ntfs_inode { 103 u64 mft_no; /* Inode / mft record number. */ 104 MFT_RECORD *mrec; /* The actual mft record of the inode. */ 105 ntfs_volume *vol; /* Pointer to the ntfs volume of this inode. */ 106 unsigned long state; /* NTFS specific flags describing this inode. 107 See ntfs_inode_state_bits above. */ 108 FILE_ATTR_FLAGS flags; /* Flags describing the file. 109 (Copy from STANDARD_INFORMATION) */ 110 /* 111 * Attribute list support (for use by the attribute lookup functions). 112 * Setup during ntfs_open_inode() for all inodes with attribute lists. 113 * Only valid if NI_AttrList is set in state. 114 */ 115 u32 attr_list_size; /* Length of attribute list value in bytes. */ 116 u8 *attr_list; /* Attribute list value itself. */ 117 /* Below fields are always valid. */ 118 s32 nr_extents; /* For a base mft record, the number of 119 attached extent inodes (0 if none), for 120 extent records this is -1. */ 121 union { /* This union is only used if nr_extents != 0. */ 122 ntfs_inode **extent_nis;/* For nr_extents > 0, array of the 123 ntfs inodes of the extent mft 124 records belonging to this base 125 inode which have been loaded. */ 126 ntfs_inode *base_ni; /* For nr_extents == -1, the ntfs 127 inode of the base mft record. */ 128 }; 129 130 /* Below fields are valid only for base inode. */ 131 132 /* 133 * These two fields are used to sync filename index and guaranteed to be 134 * correct, however value in index itself maybe wrong (windows itself 135 * do not update them properly). 136 */ 137 s64 data_size; /* Data size of unnamed DATA attribute. */ 138 s64 allocated_size; /* Allocated size stored in the filename 139 index. (NOTE: Equal to allocated size of 140 the unnamed data attribute for normal or 141 encrypted files and to compressed size 142 of the unnamed data attribute for sparse or 143 compressed files.) */ 144 145 /* 146 * These four fields are copy of relevant fields from 147 * STANDARD_INFORMATION attribute and used to sync it and FILE_NAME 148 * attribute in the index. 149 */ 150 time_t creation_time; 151 time_t last_data_change_time; 152 time_t last_mft_change_time; 153 time_t last_access_time; 154}; 155 156typedef enum { 157 NTFS_UPDATE_ATIME = 1 << 0, 158 NTFS_UPDATE_MTIME = 1 << 1, 159 NTFS_UPDATE_CTIME = 1 << 2, 160} ntfs_time_update_flags; 161 162#define NTFS_UPDATE_MCTIME (NTFS_UPDATE_MTIME | NTFS_UPDATE_CTIME) 163#define NTFS_UPDATE_AMCTIME (NTFS_UPDATE_ATIME | NTFS_UPDATE_MCTIME) 164 165extern ntfs_inode *ntfs_inode_base(ntfs_inode *ni); 166 167extern ntfs_inode *ntfs_inode_allocate(ntfs_volume *vol); 168 169extern ntfs_inode *ntfs_inode_open(ntfs_volume *vol, const MFT_REF mref); 170 171extern int ntfs_inode_close(ntfs_inode *ni); 172 173extern ntfs_inode *ntfs_extent_inode_open(ntfs_inode *base_ni, 174 const MFT_REF mref); 175 176extern int ntfs_inode_attach_all_extents(ntfs_inode *ni); 177 178extern void ntfs_inode_mark_dirty(ntfs_inode *ni); 179 180extern void ntfs_inode_update_times(ntfs_inode *ni, ntfs_time_update_flags mask); 181 182extern int ntfs_inode_sync(ntfs_inode *ni); 183 184extern int ntfs_inode_add_attrlist(ntfs_inode *ni); 185 186extern int ntfs_inode_free_space(ntfs_inode *ni, int size); 187 188extern int ntfs_inode_badclus_bad(u64 mft_no, ATTR_RECORD *a); 189 190#endif /* defined _NTFS_INODE_H */ 191