1 /* 2 * volume.h - Exports for NTFS volume handling. Originated from the Linux-NTFS project. 3 * 4 * Copyright (c) 2000-2004 Anton Altaparmakov 5 * Copyright (c) 2004-2005 Richard Russon 6 * Copyright (c) 2005-2006 Yura Pakhuchiy 7 * Copyright (c) 2005-2009 Szabolcs Szakacsits 8 * Copyright (c) 2010 Jean-Pierre Andre 9 * 10 * This program/include file is free software; you can redistribute it and/or 11 * modify it under the terms of the GNU General Public License as published 12 * by the Free Software Foundation; either version 2 of the License, or 13 * (at your option) any later version. 14 * 15 * This program/include file is distributed in the hope that it will be 16 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty 17 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU General Public License for more details. 19 * 20 * You should have received a copy of the GNU General Public License 21 * along with this program (in the main directory of the NTFS-3G 22 * distribution in the file COPYING); if not, write to the Free Software 23 * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 24 */ 25 26 #ifndef _NTFS_VOLUME_H 27 #define _NTFS_VOLUME_H 28 29 #ifdef HAVE_CONFIG_H 30 #include "config.h" 31 #endif 32 33 #ifdef HAVE_STDIO_H 34 #include <stdio.h> 35 #endif 36 #ifdef HAVE_SYS_PARAM_H 37 #include <sys/param.h> 38 #endif 39 #ifdef HAVE_SYS_MOUNT_H 40 #include <sys/mount.h> 41 #endif 42 #ifdef HAVE_MNTENT_H 43 #include <mntent.h> 44 #endif 45 46 /* 47 * Under Cygwin, DJGPP and FreeBSD we do not have MS_RDONLY, 48 * so we define them ourselves. 49 */ 50 #ifndef MS_RDONLY 51 #define MS_RDONLY 1 52 #endif 53 54 #define MS_EXCLUSIVE 0x08000000 55 56 #ifndef MS_RECOVER 57 #define MS_RECOVER 0x10000000 58 #endif 59 60 #define MS_IGNORE_HIBERFILE 0x20000000 61 #define MS_FORENSIC 0x04000000 /* No modification during mount */ 62 63 /* Forward declaration */ 64 typedef struct _ntfs_volume ntfs_volume; 65 66 #include "param.h" 67 #include "types.h" 68 #include "support.h" 69 #include "device.h" 70 #include "inode.h" 71 #include "attrib.h" 72 #include "index.h" 73 74 /** 75 * enum ntfs_mount_flags - 76 * 77 * Flags returned by the ntfs_check_if_mounted() function. 78 */ 79 typedef enum { 80 NTFS_MF_MOUNTED = 1, /* Device is mounted. */ 81 NTFS_MF_ISROOT = 2, /* Device is mounted as system root. */ 82 NTFS_MF_READONLY = 4, /* Device is mounted read-only. */ 83 } ntfs_mount_flags; 84 85 extern int ntfs_check_if_mounted(const char *file, unsigned long *mnt_flags); 86 87 typedef enum { 88 NTFS_VOLUME_OK = 0, 89 NTFS_VOLUME_SYNTAX_ERROR = 11, 90 NTFS_VOLUME_NOT_NTFS = 12, 91 NTFS_VOLUME_CORRUPT = 13, 92 NTFS_VOLUME_HIBERNATED = 14, 93 NTFS_VOLUME_UNCLEAN_UNMOUNT = 15, 94 NTFS_VOLUME_LOCKED = 16, 95 NTFS_VOLUME_RAID = 17, 96 NTFS_VOLUME_UNKNOWN_REASON = 18, 97 NTFS_VOLUME_NO_PRIVILEGE = 19, 98 NTFS_VOLUME_OUT_OF_MEMORY = 20, 99 NTFS_VOLUME_FUSE_ERROR = 21, 100 NTFS_VOLUME_INSECURE = 22 101 } ntfs_volume_status; 102 103 /** 104 * enum ntfs_volume_state_bits - 105 * 106 * Defined bits for the state field in the ntfs_volume structure. 107 */ 108 typedef enum { 109 NV_ReadOnly, /* 1: Volume is read-only. */ 110 NV_CaseSensitive, /* 1: Volume is mounted case-sensitive. */ 111 NV_LogFileEmpty, /* 1: $logFile journal is empty. */ 112 NV_ShowSysFiles, /* 1: Show NTFS metafiles. */ 113 NV_ShowHidFiles, /* 1: Show files marked hidden. */ 114 NV_HideDotFiles, /* 1: Set hidden flag on dot files */ 115 NV_Compression, /* 1: allow compression */ 116 NV_NoFixupWarn, /* 1: Do not log fixup errors */ 117 } ntfs_volume_state_bits; 118 119 #define test_nvol_flag(nv, flag) test_bit(NV_##flag, (nv)->state) 120 #define set_nvol_flag(nv, flag) set_bit(NV_##flag, (nv)->state) 121 #define clear_nvol_flag(nv, flag) clear_bit(NV_##flag, (nv)->state) 122 123 #define NVolReadOnly(nv) test_nvol_flag(nv, ReadOnly) 124 #define NVolSetReadOnly(nv) set_nvol_flag(nv, ReadOnly) 125 #define NVolClearReadOnly(nv) clear_nvol_flag(nv, ReadOnly) 126 127 #define NVolCaseSensitive(nv) test_nvol_flag(nv, CaseSensitive) 128 #define NVolSetCaseSensitive(nv) set_nvol_flag(nv, CaseSensitive) 129 #define NVolClearCaseSensitive(nv) clear_nvol_flag(nv, CaseSensitive) 130 131 #define NVolLogFileEmpty(nv) test_nvol_flag(nv, LogFileEmpty) 132 #define NVolSetLogFileEmpty(nv) set_nvol_flag(nv, LogFileEmpty) 133 #define NVolClearLogFileEmpty(nv) clear_nvol_flag(nv, LogFileEmpty) 134 135 #define NVolShowSysFiles(nv) test_nvol_flag(nv, ShowSysFiles) 136 #define NVolSetShowSysFiles(nv) set_nvol_flag(nv, ShowSysFiles) 137 #define NVolClearShowSysFiles(nv) clear_nvol_flag(nv, ShowSysFiles) 138 139 #define NVolShowHidFiles(nv) test_nvol_flag(nv, ShowHidFiles) 140 #define NVolSetShowHidFiles(nv) set_nvol_flag(nv, ShowHidFiles) 141 #define NVolClearShowHidFiles(nv) clear_nvol_flag(nv, ShowHidFiles) 142 143 #define NVolHideDotFiles(nv) test_nvol_flag(nv, HideDotFiles) 144 #define NVolSetHideDotFiles(nv) set_nvol_flag(nv, HideDotFiles) 145 #define NVolClearHideDotFiles(nv) clear_nvol_flag(nv, HideDotFiles) 146 147 #define NVolCompression(nv) test_nvol_flag(nv, Compression) 148 #define NVolSetCompression(nv) set_nvol_flag(nv, Compression) 149 #define NVolClearCompression(nv) clear_nvol_flag(nv, Compression) 150 151 #define NVolNoFixupWarn(nv) test_nvol_flag(nv, NoFixupWarn) 152 #define NVolSetNoFixupWarn(nv) set_nvol_flag(nv, NoFixupWarn) 153 #define NVolClearNoFixupWarn(nv) clear_nvol_flag(nv, NoFixupWarn) 154 155 /* 156 * NTFS version 1.1 and 1.2 are used by Windows NT4. 157 * NTFS version 2.x is used by Windows 2000 Beta 158 * NTFS version 3.0 is used by Windows 2000. 159 * NTFS version 3.1 is used by Windows XP, 2003 and Vista. 160 */ 161 162 #define NTFS_V1_1(major, minor) ((major) == 1 && (minor) == 1) 163 #define NTFS_V1_2(major, minor) ((major) == 1 && (minor) == 2) 164 #define NTFS_V2_X(major, minor) ((major) == 2) 165 #define NTFS_V3_0(major, minor) ((major) == 3 && (minor) == 0) 166 #define NTFS_V3_1(major, minor) ((major) == 3 && (minor) == 1) 167 168 #define NTFS_BUF_SIZE 8192 169 170 /** 171 * struct _ntfs_volume - structure describing an open volume in memory. 172 */ 173 struct _ntfs_volume { 174 union { 175 struct ntfs_device *dev; /* NTFS device associated with 176 the volume. */ 177 void *sb; /* For kernel porting compatibility. */ 178 }; 179 char *vol_name; /* Name of the volume. */ 180 unsigned long state; /* NTFS specific flags describing this volume. 181 See ntfs_volume_state_bits above. */ 182 183 ntfs_inode *vol_ni; /* ntfs_inode structure for FILE_Volume. */ 184 u8 major_ver; /* Ntfs major version of volume. */ 185 u8 minor_ver; /* Ntfs minor version of volume. */ 186 le16 flags; /* Bit array of VOLUME_* flags. */ 187 188 u16 sector_size; /* Byte size of a sector. */ 189 u8 sector_size_bits; /* Log(2) of the byte size of a sector. */ 190 u32 cluster_size; /* Byte size of a cluster. */ 191 u32 mft_record_size; /* Byte size of a mft record. */ 192 u32 indx_record_size; /* Byte size of a INDX record. */ 193 u8 cluster_size_bits; /* Log(2) of the byte size of a cluster. */ 194 u8 mft_record_size_bits;/* Log(2) of the byte size of a mft record. */ 195 u8 indx_record_size_bits;/* Log(2) of the byte size of a INDX record. */ 196 197 /* Variables used by the cluster and mft allocators. */ 198 u8 mft_zone_multiplier; /* Initial mft zone multiplier. */ 199 u8 full_zones; /* cluster zones which are full */ 200 s64 mft_data_pos; /* Mft record number at which to allocate the 201 next mft record. */ 202 LCN mft_zone_start; /* First cluster of the mft zone. */ 203 LCN mft_zone_end; /* First cluster beyond the mft zone. */ 204 LCN mft_zone_pos; /* Current position in the mft zone. */ 205 LCN data1_zone_pos; /* Current position in the first data zone. */ 206 LCN data2_zone_pos; /* Current position in the second data zone. */ 207 208 s64 nr_clusters; /* Volume size in clusters, hence also the 209 number of bits in lcn_bitmap. */ 210 ntfs_inode *lcnbmp_ni; /* ntfs_inode structure for FILE_Bitmap. */ 211 ntfs_attr *lcnbmp_na; /* ntfs_attr structure for the data attribute 212 of FILE_Bitmap. Each bit represents a 213 cluster on the volume, bit 0 representing 214 lcn 0 and so on. A set bit means that the 215 cluster and vice versa. */ 216 217 LCN mft_lcn; /* Logical cluster number of the data attribute 218 for FILE_MFT. */ 219 ntfs_inode *mft_ni; /* ntfs_inode structure for FILE_MFT. */ 220 ntfs_attr *mft_na; /* ntfs_attr structure for the data attribute 221 of FILE_MFT. */ 222 ntfs_attr *mftbmp_na; /* ntfs_attr structure for the bitmap attribute 223 of FILE_MFT. Each bit represents an mft 224 record in the $DATA attribute, bit 0 225 representing mft record 0 and so on. A set 226 bit means that the mft record is in use and 227 vice versa. */ 228 229 ntfs_inode *secure_ni; /* ntfs_inode structure for FILE $Secure */ 230 ntfs_index_context *secure_xsii; /* index for using $Secure:$SII */ 231 ntfs_index_context *secure_xsdh; /* index for using $Secure:$SDH */ 232 int secure_reentry; /* check for non-rentries */ 233 unsigned int secure_flags; /* flags, see security.h for values */ 234 235 int mftmirr_size; /* Size of the FILE_MFTMirr in mft records. */ 236 LCN mftmirr_lcn; /* Logical cluster number of the data attribute 237 for FILE_MFTMirr. */ 238 ntfs_inode *mftmirr_ni; /* ntfs_inode structure for FILE_MFTMirr. */ 239 ntfs_attr *mftmirr_na; /* ntfs_attr structure for the data attribute 240 of FILE_MFTMirr. */ 241 242 ntfschar *upcase; /* Upper case equivalents of all 65536 2-byte 243 Unicode characters. Obtained from 244 FILE_UpCase. */ 245 u32 upcase_len; /* Length in Unicode characters of the upcase 246 table. */ 247 ntfschar *locase; /* Lower case equivalents of all 65536 2-byte 248 Unicode characters. Only if option 249 case_ignore is set. */ 250 251 ATTR_DEF *attrdef; /* Attribute definitions. Obtained from 252 FILE_AttrDef. */ 253 s32 attrdef_len; /* Size of the attribute definition table in 254 bytes. */ 255 256 s64 free_clusters; /* Track the number of free clusters which 257 greatly improves statfs() performance */ 258 s64 free_mft_records; /* Same for free mft records (see above) */ 259 BOOL efs_raw; /* volume is mounted for raw access to 260 efs-encrypted files */ 261 #ifdef XATTR_MAPPINGS 262 struct XATTRMAPPING *xattr_mapping; 263 #endif /* XATTR_MAPPINGS */ 264 #if CACHE_INODE_SIZE 265 struct CACHE_HEADER *xinode_cache; 266 #endif 267 #if CACHE_NIDATA_SIZE 268 struct CACHE_HEADER *nidata_cache; 269 #endif 270 #if CACHE_LOOKUP_SIZE 271 struct CACHE_HEADER *lookup_cache; 272 #endif 273 #if CACHE_SECURID_SIZE 274 struct CACHE_HEADER *securid_cache; 275 #endif 276 #if CACHE_LEGACY_SIZE 277 struct CACHE_HEADER *legacy_cache; 278 #endif 279 280 }; 281 282 extern const char *ntfs_home; 283 284 extern ntfs_volume *ntfs_volume_alloc(void); 285 286 extern ntfs_volume *ntfs_volume_startup(struct ntfs_device *dev, 287 unsigned long flags); 288 289 extern ntfs_volume *ntfs_device_mount(struct ntfs_device *dev, 290 unsigned long flags); 291 292 extern ntfs_volume *ntfs_mount(const char *name, unsigned long flags); 293 extern int ntfs_umount(ntfs_volume *vol, const BOOL force); 294 295 extern int ntfs_version_is_supported(ntfs_volume *vol); 296 extern int ntfs_volume_check_hiberfile(ntfs_volume *vol, int verbose); 297 extern int ntfs_logfile_reset(ntfs_volume *vol); 298 299 extern int ntfs_volume_write_flags(ntfs_volume *vol, const le16 flags); 300 301 extern int ntfs_volume_error(int err); 302 extern void ntfs_mount_error(const char *vol, const char *mntpoint, int err); 303 304 extern int ntfs_volume_get_free_space(ntfs_volume *vol); 305 extern int ntfs_volume_rename(ntfs_volume *vol, ntfschar *label, int label_len); 306 307 extern int ntfs_set_shown_files(ntfs_volume *vol, 308 BOOL show_sys_files, BOOL show_hid_files, BOOL hide_dot_files); 309 extern int ntfs_set_locale(void); 310 extern int ntfs_set_ignore_case(ntfs_volume *vol); 311 312 #endif /* defined _NTFS_VOLUME_H */ 313 314