• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 	/* Do not #include <sys/mount.h> here : conflicts with <linux/fs.h> */
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 "param.h"
48 #include "types.h"
49 #include "support.h"
50 #include "device.h"
51 #include "inode.h"
52 #include "attrib.h"
53 #include "index.h"
54 
55 /**
56  * enum ntfs_mount_flags -
57  *
58  * Flags for the ntfs_mount() function.
59  */
60 enum {
61 	NTFS_MNT_NONE                   = 0x00000000,
62 	NTFS_MNT_RDONLY                 = 0x00000001,
63 	NTFS_MNT_MAY_RDONLY             = 0x02000000, /* Allow fallback to ro */
64 	NTFS_MNT_FORENSIC               = 0x04000000, /* No modification during
65 	                                               * mount. */
66 	NTFS_MNT_EXCLUSIVE              = 0x08000000,
67 	NTFS_MNT_RECOVER                = 0x10000000,
68 	NTFS_MNT_IGNORE_HIBERFILE       = 0x20000000,
69 };
70 typedef unsigned long ntfs_mount_flags;
71 
72 /**
73  * enum ntfs_mounted_flags -
74  *
75  * Flags returned by the ntfs_check_if_mounted() function.
76  */
77 typedef enum {
78 	NTFS_MF_MOUNTED		= 1,	/* Device is mounted. */
79 	NTFS_MF_ISROOT		= 2,	/* Device is mounted as system root. */
80 	NTFS_MF_READONLY	= 4,	/* Device is mounted read-only. */
81 } ntfs_mounted_flags;
82 
83 extern int ntfs_check_if_mounted(const char *file, unsigned long *mnt_flags);
84 
85 typedef enum {
86 	NTFS_VOLUME_OK			= 0,
87 	NTFS_VOLUME_SYNTAX_ERROR	= 11,
88 	NTFS_VOLUME_NOT_NTFS		= 12,
89 	NTFS_VOLUME_CORRUPT		= 13,
90 	NTFS_VOLUME_HIBERNATED		= 14,
91 	NTFS_VOLUME_UNCLEAN_UNMOUNT	= 15,
92 	NTFS_VOLUME_LOCKED		= 16,
93 	NTFS_VOLUME_RAID		= 17,
94 	NTFS_VOLUME_UNKNOWN_REASON	= 18,
95 	NTFS_VOLUME_NO_PRIVILEGE	= 19,
96 	NTFS_VOLUME_OUT_OF_MEMORY	= 20,
97 	NTFS_VOLUME_FUSE_ERROR		= 21,
98 	NTFS_VOLUME_INSECURE		= 22
99 } ntfs_volume_status;
100 
101 typedef enum {
102 	NTFS_FILES_INTERIX,
103 	NTFS_FILES_WSL,
104 } ntfs_volume_special_files;
105 
106 /**
107  * enum ntfs_volume_state_bits -
108  *
109  * Defined bits for the state field in the ntfs_volume structure.
110  */
111 typedef enum {
112 	NV_ReadOnly,		/* 1: Volume is read-only. */
113 	NV_CaseSensitive,	/* 1: Volume is mounted case-sensitive. */
114 	NV_LogFileEmpty,	/* 1: $logFile journal is empty. */
115 	NV_ShowSysFiles,	/* 1: Show NTFS metafiles. */
116 	NV_ShowHidFiles,	/* 1: Show files marked hidden. */
117 	NV_HideDotFiles,	/* 1: Set hidden flag on dot files */
118 	NV_Compression,		/* 1: allow compression */
119 	NV_NoFixupWarn,		/* 1: Do not log fixup errors */
120 	NV_FreeSpaceKnown,	/* 1: The free space is now known */
121 } ntfs_volume_state_bits;
122 
123 #define  test_nvol_flag(nv, flag)	 test_bit(NV_##flag, (nv)->state)
124 #define   set_nvol_flag(nv, flag)	  set_bit(NV_##flag, (nv)->state)
125 #define clear_nvol_flag(nv, flag)	clear_bit(NV_##flag, (nv)->state)
126 
127 #define NVolReadOnly(nv)		 test_nvol_flag(nv, ReadOnly)
128 #define NVolSetReadOnly(nv)		  set_nvol_flag(nv, ReadOnly)
129 #define NVolClearReadOnly(nv)		clear_nvol_flag(nv, ReadOnly)
130 
131 #define NVolCaseSensitive(nv)		 test_nvol_flag(nv, CaseSensitive)
132 #define NVolSetCaseSensitive(nv)	  set_nvol_flag(nv, CaseSensitive)
133 #define NVolClearCaseSensitive(nv)	clear_nvol_flag(nv, CaseSensitive)
134 
135 #define NVolLogFileEmpty(nv)		 test_nvol_flag(nv, LogFileEmpty)
136 #define NVolSetLogFileEmpty(nv)		  set_nvol_flag(nv, LogFileEmpty)
137 #define NVolClearLogFileEmpty(nv)	clear_nvol_flag(nv, LogFileEmpty)
138 
139 #define NVolShowSysFiles(nv)		 test_nvol_flag(nv, ShowSysFiles)
140 #define NVolSetShowSysFiles(nv)		  set_nvol_flag(nv, ShowSysFiles)
141 #define NVolClearShowSysFiles(nv)	clear_nvol_flag(nv, ShowSysFiles)
142 
143 #define NVolShowHidFiles(nv)		 test_nvol_flag(nv, ShowHidFiles)
144 #define NVolSetShowHidFiles(nv)		  set_nvol_flag(nv, ShowHidFiles)
145 #define NVolClearShowHidFiles(nv)	clear_nvol_flag(nv, ShowHidFiles)
146 
147 #define NVolHideDotFiles(nv)		 test_nvol_flag(nv, HideDotFiles)
148 #define NVolSetHideDotFiles(nv)		  set_nvol_flag(nv, HideDotFiles)
149 #define NVolClearHideDotFiles(nv)	clear_nvol_flag(nv, HideDotFiles)
150 
151 #define NVolCompression(nv)		 test_nvol_flag(nv, Compression)
152 #define NVolSetCompression(nv)		  set_nvol_flag(nv, Compression)
153 #define NVolClearCompression(nv)	clear_nvol_flag(nv, Compression)
154 
155 #define NVolNoFixupWarn(nv)		 test_nvol_flag(nv, NoFixupWarn)
156 #define NVolSetNoFixupWarn(nv)		  set_nvol_flag(nv, NoFixupWarn)
157 #define NVolClearNoFixupWarn(nv)	clear_nvol_flag(nv, NoFixupWarn)
158 
159 #define NVolFreeSpaceKnown(nv)		 test_nvol_flag(nv, FreeSpaceKnown)
160 #define NVolSetFreeSpaceKnown(nv)	  set_nvol_flag(nv, FreeSpaceKnown)
161 #define NVolClearFreeSpaceKnown(nv)	clear_nvol_flag(nv, FreeSpaceKnown)
162 
163 /*
164  * NTFS version 1.1 and 1.2 are used by Windows NT4.
165  * NTFS version 2.x is used by Windows 2000 Beta
166  * NTFS version 3.0 is used by Windows 2000.
167  * NTFS version 3.1 is used by Windows XP, 2003 and Vista.
168  */
169 
170 #define NTFS_V1_1(major, minor) ((major) == 1 && (minor) == 1)
171 #define NTFS_V1_2(major, minor) ((major) == 1 && (minor) == 2)
172 #define NTFS_V2_X(major, minor) ((major) == 2)
173 #define NTFS_V3_0(major, minor) ((major) == 3 && (minor) == 0)
174 #define NTFS_V3_1(major, minor) ((major) == 3 && (minor) == 1)
175 
176 #define NTFS_BUF_SIZE 8192
177 
178 /**
179  * struct _ntfs_volume - structure describing an open volume in memory.
180  */
181 struct _ntfs_volume {
182 	union {
183 		struct ntfs_device *dev;	/* NTFS device associated with
184 						   the volume. */
185 		void *sb;	/* For kernel porting compatibility. */
186 	};
187 	char *vol_name;		/* Name of the volume. */
188 	unsigned long state;	/* NTFS specific flags describing this volume.
189 				   See ntfs_volume_state_bits above. */
190 
191 	ntfs_inode *vol_ni;	/* ntfs_inode structure for FILE_Volume. */
192 	u8 major_ver;		/* Ntfs major version of volume. */
193 	u8 minor_ver;		/* Ntfs minor version of volume. */
194 	le16 flags;		/* Bit array of VOLUME_* flags. */
195 
196 	u16 sector_size;	/* Byte size of a sector. */
197 	u8 sector_size_bits;	/* Log(2) of the byte size of a sector. */
198 	u32 cluster_size;	/* Byte size of a cluster. */
199 	u32 mft_record_size;	/* Byte size of a mft record. */
200 	u32 indx_record_size;	/* Byte size of a INDX record. */
201 	u8 cluster_size_bits;	/* Log(2) of the byte size of a cluster. */
202 	u8 mft_record_size_bits;/* Log(2) of the byte size of a mft record. */
203 	u8 indx_record_size_bits;/* Log(2) of the byte size of a INDX record. */
204 
205 	/* Variables used by the cluster and mft allocators. */
206 	u8 mft_zone_multiplier;	/* Initial mft zone multiplier. */
207 	u8 full_zones;		/* cluster zones which are full */
208 	s64 mft_data_pos;	/* Mft record number at which to allocate the
209 				   next mft record. */
210 	LCN mft_zone_start;	/* First cluster of the mft zone. */
211 	LCN mft_zone_end;	/* First cluster beyond the mft zone. */
212 	LCN mft_zone_pos;	/* Current position in the mft zone. */
213 	LCN data1_zone_pos;	/* Current position in the first data zone. */
214 	LCN data2_zone_pos;	/* Current position in the second data zone. */
215 
216 	s64 nr_clusters;	/* Volume size in clusters, hence also the
217 				   number of bits in lcn_bitmap. */
218 	ntfs_inode *lcnbmp_ni;	/* ntfs_inode structure for FILE_Bitmap. */
219 	ntfs_attr *lcnbmp_na;	/* ntfs_attr structure for the data attribute
220 				   of FILE_Bitmap. Each bit represents a
221 				   cluster on the volume, bit 0 representing
222 				   lcn 0 and so on. A set bit means that the
223 				   cluster and vice versa. */
224 
225 	LCN mft_lcn;		/* Logical cluster number of the data attribute
226 				   for FILE_MFT. */
227 	ntfs_inode *mft_ni;	/* ntfs_inode structure for FILE_MFT. */
228 	ntfs_attr *mft_na;	/* ntfs_attr structure for the data attribute
229 				   of FILE_MFT. */
230 	ntfs_attr *mftbmp_na;	/* ntfs_attr structure for the bitmap attribute
231 				   of FILE_MFT. Each bit represents an mft
232 				   record in the $DATA attribute, bit 0
233 				   representing mft record 0 and so on. A set
234 				   bit means that the mft record is in use and
235 				   vice versa. */
236 
237 	ntfs_inode *secure_ni;	/* ntfs_inode structure for FILE $Secure */
238 	ntfs_index_context *secure_xsii; /* index for using $Secure:$SII */
239 	ntfs_index_context *secure_xsdh; /* index for using $Secure:$SDH */
240 	int secure_reentry;  /* check for non-rentries */
241 	unsigned int secure_flags;  /* flags, see security.h for values */
242 
243 	int mftmirr_size;	/* Size of the FILE_MFTMirr in mft records. */
244 	LCN mftmirr_lcn;	/* Logical cluster number of the data attribute
245 				   for FILE_MFTMirr. */
246 	ntfs_inode *mftmirr_ni;	/* ntfs_inode structure for FILE_MFTMirr. */
247 	ntfs_attr *mftmirr_na;	/* ntfs_attr structure for the data attribute
248 				   of FILE_MFTMirr. */
249 
250 	ntfschar *upcase;	/* Upper case equivalents of all 65536 2-byte
251 				   Unicode characters. Obtained from
252 				   FILE_UpCase. */
253 	u32 upcase_len;		/* Length in Unicode characters of the upcase
254 				   table. */
255 	ntfschar *locase;	/* Lower case equivalents of all 65536 2-byte
256 				   Unicode characters. Only if option
257 				   case_ignore is set. */
258 
259 	ATTR_DEF *attrdef;	/* Attribute definitions. Obtained from
260 				   FILE_AttrDef. */
261 	s32 attrdef_len;	/* Size of the attribute definition table in
262 				   bytes. */
263 
264 	s64 free_clusters; 	/* Track the number of free clusters which
265 				   greatly improves statfs() performance */
266 	s64 free_mft_records; 	/* Same for free mft records (see above) */
267 	BOOL efs_raw;		/* volume is mounted for raw access to
268 				   efs-encrypted files */
269 	ntfs_volume_special_files special_files; /* Implementation of special files */
270 	const char *abs_mnt_point; /* Mount point */
271 #ifdef XATTR_MAPPINGS
272 	struct XATTRMAPPING *xattr_mapping;
273 #endif /* XATTR_MAPPINGS */
274 #if CACHE_INODE_SIZE
275 	struct CACHE_HEADER *xinode_cache;
276 #endif
277 #if CACHE_NIDATA_SIZE
278 	struct CACHE_HEADER *nidata_cache;
279 #endif
280 #if CACHE_LOOKUP_SIZE
281 	struct CACHE_HEADER *lookup_cache;
282 #endif
283 #if CACHE_SECURID_SIZE
284 	struct CACHE_HEADER *securid_cache;
285 #endif
286 #if CACHE_LEGACY_SIZE
287 	struct CACHE_HEADER *legacy_cache;
288 #endif
289 };
290 
291 extern const char *ntfs_home;
292 
293 extern ntfs_volume *ntfs_volume_alloc(void);
294 
295 extern ntfs_volume *ntfs_volume_startup(struct ntfs_device *dev,
296 		ntfs_mount_flags flags);
297 
298 extern ntfs_volume *ntfs_device_mount(struct ntfs_device *dev,
299 		ntfs_mount_flags flags);
300 
301 extern ntfs_volume *ntfs_mount(const char *name, ntfs_mount_flags flags);
302 extern int ntfs_umount(ntfs_volume *vol, const BOOL force);
303 
304 extern int ntfs_version_is_supported(ntfs_volume *vol);
305 extern int ntfs_volume_check_hiberfile(ntfs_volume *vol, int verbose);
306 extern int ntfs_logfile_reset(ntfs_volume *vol);
307 
308 extern int ntfs_volume_write_flags(ntfs_volume *vol, const le16 flags);
309 
310 extern int ntfs_volume_error(int err);
311 extern void ntfs_mount_error(const char *vol, const char *mntpoint, int err);
312 
313 extern int ntfs_volume_get_free_space(ntfs_volume *vol);
314 extern int ntfs_volume_rename(ntfs_volume *vol, const ntfschar *label,
315 		int label_len);
316 
317 extern int ntfs_set_shown_files(ntfs_volume *vol,
318 		BOOL show_sys_files, BOOL show_hid_files, BOOL hide_dot_files);
319 extern int ntfs_set_locale(void);
320 extern int ntfs_set_ignore_case(ntfs_volume *vol);
321 
322 #endif /* defined _NTFS_VOLUME_H */
323 
324