1 /* 2 * volume.h - Exports for NTFS volume handling. Part of the Linux-NTFS project. 3 * 4 * Copyright (c) 2000-2004 Anton Altaparmakov 5 * Copyright (c) 2005-2007 Yura Pakhuchiy 6 * Copyright (c) 2004-2005 Richard Russon 7 * 8 * This program/include file is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU General Public License as published 10 * by the Free Software Foundation; either version 2 of the License, or 11 * (at your option) any later version. 12 * 13 * This program/include file is distributed in the hope that it will be 14 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty 15 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program (in the main directory of the Linux-NTFS 20 * distribution in the file COPYING); if not, write to the Free Software 21 * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 */ 23 24 #ifndef _NTFS_VOLUME_H 25 #define _NTFS_VOLUME_H 26 27 #ifdef HAVE_CONFIG_H 28 #include "config.h" 29 #endif 30 31 #ifdef HAVE_STDIO_H 32 #include <stdio.h> 33 #endif 34 #ifdef HAVE_SYS_PARAM_H 35 #include <sys/param.h> 36 #endif 37 #ifdef HAVE_SYS_MOUNT_H 38 #include <sys/mount.h> 39 #endif 40 #ifdef HAVE_MNTENT_H 41 #include <mntent.h> 42 #endif 43 44 /* Forward declaration */ 45 typedef struct _ntfs_volume ntfs_volume; 46 47 #include "list.h" 48 #include "types.h" 49 #include "support.h" 50 #include "device.h" 51 #include "inode.h" 52 #include "attrib.h" 53 54 /** 55 * enum ntfs_mount_flags - 56 * 57 * Flags for the ntfs_mount() function. 58 */ 59 typedef enum { 60 NTFS_MNT_RDONLY = 1, 61 NTFS_MNT_FORENSIC = 2, 62 NTFS_MNT_CASE_SENSITIVE = 4, 63 NTFS_MNT_NOT_EXCLUSIVE = 8, 64 NTFS_MNT_FORCE = 16, 65 NTFS_MNT_INTERIX = 32, 66 } ntfs_mount_flags; 67 68 /** 69 * enum ntfs_mounted_flags - 70 * 71 * Flags returned by the ntfs_check_if_mounted() function. 72 */ 73 typedef enum { 74 NTFS_MF_MOUNTED = 1, /* Device is mounted. */ 75 NTFS_MF_ISROOT = 2, /* Device is mounted as system root. */ 76 NTFS_MF_READONLY = 4, /* Device is mounted read-only. */ 77 } ntfs_mounted_flags; 78 79 extern int ntfs_check_if_mounted(const char *file, unsigned long *mnt_flags); 80 81 /** 82 * enum ntfs_volume_state_bits - 83 * 84 * Defined bits for the state field in the ntfs_volume structure. 85 */ 86 typedef enum { 87 NV_ReadOnly, /* 1: Volume is read-only. */ 88 NV_CaseSensitive, /* 1: Volume is mounted case-sensitive. */ 89 NV_LogFileEmpty, /* 1: $logFile journal is empty. */ 90 NV_NoATime, /* 1: Do not update access time. */ 91 NV_WasDirty, /* 1: Volume was marked dirty before we mounted 92 it. */ 93 NV_ForensicMount, /* 1: Mount is forensic, i.e. no modifications 94 are to be done by mount/umount. */ 95 NV_Interix, /* 1: Make libntfs recognize Interix special 96 files. */ 97 } ntfs_volume_state_bits; 98 99 #define test_nvol_flag(nv, flag) test_bit(NV_##flag, (nv)->state) 100 #define set_nvol_flag(nv, flag) set_bit(NV_##flag, (nv)->state) 101 #define clear_nvol_flag(nv, flag) clear_bit(NV_##flag, (nv)->state) 102 103 #define NVolReadOnly(nv) test_nvol_flag(nv, ReadOnly) 104 #define NVolSetReadOnly(nv) set_nvol_flag(nv, ReadOnly) 105 #define NVolClearReadOnly(nv) clear_nvol_flag(nv, ReadOnly) 106 107 #define NVolCaseSensitive(nv) test_nvol_flag(nv, CaseSensitive) 108 #define NVolSetCaseSensitive(nv) set_nvol_flag(nv, CaseSensitive) 109 #define NVolClearCaseSensitive(nv) clear_nvol_flag(nv, CaseSensitive) 110 111 #define NVolLogFileEmpty(nv) test_nvol_flag(nv, LogFileEmpty) 112 #define NVolSetLogFileEmpty(nv) set_nvol_flag(nv, LogFileEmpty) 113 #define NVolClearLogFileEmpty(nv) clear_nvol_flag(nv, LogFileEmpty) 114 115 #define NVolWasDirty(nv) test_nvol_flag(nv, WasDirty) 116 #define NVolSetWasDirty(nv) set_nvol_flag(nv, WasDirty) 117 #define NVolClearWasDirty(nv) clear_nvol_flag(nv, WasDirty) 118 119 #define NVolForensicMount(nv) test_nvol_flag(nv, ForensicMount) 120 #define NVolSetForensicMount(nv) set_nvol_flag(nv, ForensicMount) 121 #define NVolClearForensicMount(nv) clear_nvol_flag(nv, ForensicMount) 122 123 #define NVolInterix(nv) test_nvol_flag(nv, Interix) 124 #define NVolSetInterix(nv) set_nvol_flag(nv, Interix) 125 #define NVolClearInterix(nv) clear_nvol_flag(nv, Interix) 126 127 /* 128 * NTFS version 1.1 and 1.2 are used by Windows NT4. 129 * NTFS version 2.x is used by Windows 2000 Beta 130 * NTFS version 3.0 is used by Windows 2000. 131 * NTFS version 3.1 is used by Windows XP, 2003 and Vista. 132 */ 133 134 #define NTFS_V1_1(major, minor) ((major) == 1 && (minor) == 1) 135 #define NTFS_V1_2(major, minor) ((major) == 1 && (minor) == 2) 136 #define NTFS_V2_X(major, minor) ((major) == 2) 137 #define NTFS_V3_0(major, minor) ((major) == 3 && (minor) == 0) 138 #define NTFS_V3_1(major, minor) ((major) == 3 && (minor) == 1) 139 140 #define NTFS_BUF_SIZE 8192 141 142 #define NTFS_INODE_CACHE_SIZE 512 /* WARNING: This should be power of 2. */ 143 #define NTFS_INODE_CACHE_SIZE_BITS (NTFS_INODE_CACHE_SIZE - 1) 144 145 /** 146 * struct _ntfs_volume - structure describing an open volume in memory. 147 */ 148 struct _ntfs_volume { 149 union { 150 struct ntfs_device *dev; /* NTFS device associated with 151 the volume. */ 152 void *sb; /* For kernel porting compatibility. */ 153 } u; 154 char *vol_name; /* Name of the volume. */ 155 unsigned long state; /* NTFS specific flags describing this volume. 156 See ntfs_volume_state_bits above. */ 157 158 ntfs_inode *vol_ni; /* ntfs_inode structure for FILE_Volume. */ 159 u8 major_ver; /* Ntfs major version of volume. */ 160 u8 minor_ver; /* Ntfs minor version of volume. */ 161 le16 flags; /* Bit array of VOLUME_* flags. */ 162 GUID guid; /* The volume guid if present (otherwise it is 163 a NULL guid). */ 164 165 u16 sector_size; /* Byte size of a sector. */ 166 u8 sector_size_bits; /* Log(2) of the byte size of a sector. */ 167 u32 cluster_size; /* Byte size of a cluster. */ 168 u32 mft_record_size; /* Byte size of a mft record. */ 169 u32 indx_record_size; /* Byte size of a INDX record. */ 170 u8 cluster_size_bits; /* Log(2) of the byte size of a cluster. */ 171 u8 mft_record_size_bits;/* Log(2) of the byte size of a mft record. */ 172 u8 indx_record_size_bits;/* Log(2) of the byte size of a INDX record. */ 173 174 /* Variables used by the cluster and mft allocators. */ 175 u8 mft_zone_multiplier; /* Initial mft zone multiplier. */ 176 s64 mft_data_pos; /* Mft record number at which to allocate the 177 next mft record. */ 178 LCN mft_zone_start; /* First cluster of the mft zone. */ 179 LCN mft_zone_end; /* First cluster beyond the mft zone. */ 180 LCN mft_zone_pos; /* Current position in the mft zone. */ 181 LCN data1_zone_pos; /* Current position in the first data zone. */ 182 LCN data2_zone_pos; /* Current position in the second data zone. */ 183 184 s64 nr_clusters; /* Volume size in clusters, hence also the 185 number of bits in lcn_bitmap. */ 186 ntfs_inode *lcnbmp_ni; /* ntfs_inode structure for FILE_Bitmap. */ 187 ntfs_attr *lcnbmp_na; /* ntfs_attr structure for the data attribute 188 of FILE_Bitmap. Each bit represents a 189 cluster on the volume, bit 0 representing 190 lcn 0 and so on. A set bit means that the 191 cluster and vice versa. */ 192 193 LCN mft_lcn; /* Logical cluster number of the data attribute 194 for FILE_MFT. */ 195 ntfs_inode *mft_ni; /* ntfs_inode structure for FILE_MFT. */ 196 ntfs_attr *mft_na; /* ntfs_attr structure for the data attribute 197 of FILE_MFT. */ 198 ntfs_attr *mftbmp_na; /* ntfs_attr structure for the bitmap attribute 199 of FILE_MFT. Each bit represents an mft 200 record in the $DATA attribute, bit 0 201 representing mft record 0 and so on. A set 202 bit means that the mft record is in use and 203 vice versa. */ 204 205 int mftmirr_size; /* Size of the FILE_MFTMirr in mft records. */ 206 LCN mftmirr_lcn; /* Logical cluster number of the data attribute 207 for FILE_MFTMirr. */ 208 ntfs_inode *mftmirr_ni; /* ntfs_inode structure for FILE_MFTMirr. */ 209 ntfs_attr *mftmirr_na; /* ntfs_attr structure for the data attribute 210 of FILE_MFTMirr. */ 211 212 ntfschar *upcase; /* Upper case equivalents of all 65536 2-byte 213 Unicode characters. Obtained from 214 FILE_UpCase. */ 215 u32 upcase_len; /* Length in Unicode characters of the upcase 216 table. */ 217 218 ATTR_DEF *attrdef; /* Attribute definitions. Obtained from 219 FILE_AttrDef. */ 220 s32 attrdef_len; /* Size of the attribute definition table in 221 bytes. */ 222 223 long nr_free_clusters; /* This two are self explaining. */ 224 long nr_free_mft_records; 225 226 struct list_head inode_cache[NTFS_INODE_CACHE_SIZE]; /* List of opened 227 inodes. */ 228 }; 229 230 extern ntfs_volume *ntfs_volume_alloc(void); 231 232 extern ntfs_volume *ntfs_volume_startup(struct ntfs_device *dev, 233 ntfs_mount_flags flags); 234 235 extern ntfs_volume *ntfs_device_mount(struct ntfs_device *dev, 236 ntfs_mount_flags flags); 237 extern int ntfs_device_umount(ntfs_volume *vol, const BOOL force); 238 239 extern ntfs_volume *ntfs_mount(const char *name, ntfs_mount_flags flags); 240 extern int ntfs_umount(ntfs_volume *vol, const BOOL force); 241 242 extern int ntfs_version_is_supported(ntfs_volume *vol); 243 extern int ntfs_logfile_reset(ntfs_volume *vol); 244 245 extern int ntfs_volume_write_flags(ntfs_volume *vol, const le16 flags); 246 247 #endif /* defined _NTFS_VOLUME_H */