xref: /haiku/src/add-ons/kernel/file_systems/ntfs/libntfs/volume.h (revision 1c09002cbee8e797a0f8bbfc5678dfadd39ee1a7)
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  *
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_VOLUME_H
26 #define _NTFS_VOLUME_H
27 
28 #ifdef HAVE_CONFIG_H
29 #include "config.h"
30 #endif
31 
32 #ifdef HAVE_STDIO_H
33 #include <stdio.h>
34 #endif
35 #ifdef HAVE_SYS_PARAM_H
36 #include <sys/param.h>
37 #endif
38 #ifdef HAVE_SYS_MOUNT_H
39 #include <sys/mount.h>
40 #endif
41 #ifdef HAVE_MNTENT_H
42 #include <mntent.h>
43 #endif
44 
45 /*
46  * Under Cygwin, DJGPP and FreeBSD we do not have MS_RDONLY,
47  * so we define them ourselves.
48  */
49 #ifndef MS_RDONLY
50 #define MS_RDONLY 1
51 #endif
52 
53 #define MS_EXCLUSIVE 0x08000000
54 
55 #ifndef MS_RECOVER
56 #define MS_RECOVER   0x10000000
57 #endif
58 
59 #define MS_IGNORE_HIBERFILE   0x20000000
60 
61 /* Forward declaration */
62 typedef struct _ntfs_volume ntfs_volume;
63 
64 #include "param.h"
65 #include "types.h"
66 #include "support.h"
67 #include "device.h"
68 #include "inode.h"
69 #include "attrib.h"
70 #include "index.h"
71 
72 /**
73  * enum ntfs_mount_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_mount_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 /**
102  * enum ntfs_volume_state_bits -
103  *
104  * Defined bits for the state field in the ntfs_volume structure.
105  */
106 typedef enum {
107 	NV_ReadOnly,		/* 1: Volume is read-only. */
108 	NV_CaseSensitive,	/* 1: Volume is mounted case-sensitive. */
109 	NV_LogFileEmpty,	/* 1: $logFile journal is empty. */
110 	NV_ShowSysFiles,	/* 1: Show NTFS metafiles. */
111 	NV_ShowHidFiles,	/* 1: Show files marked hidden. */
112 	NV_HideDotFiles,	/* 1: Set hidden flag on dot files */
113 	NV_Compression,		/* 1: allow compression */
114 } ntfs_volume_state_bits;
115 
116 #define  test_nvol_flag(nv, flag)	 test_bit(NV_##flag, (nv)->state)
117 #define   set_nvol_flag(nv, flag)	  set_bit(NV_##flag, (nv)->state)
118 #define clear_nvol_flag(nv, flag)	clear_bit(NV_##flag, (nv)->state)
119 
120 #define NVolReadOnly(nv)		 test_nvol_flag(nv, ReadOnly)
121 #define NVolSetReadOnly(nv)		  set_nvol_flag(nv, ReadOnly)
122 #define NVolClearReadOnly(nv)		clear_nvol_flag(nv, ReadOnly)
123 
124 #define NVolCaseSensitive(nv)		 test_nvol_flag(nv, CaseSensitive)
125 #define NVolSetCaseSensitive(nv)	  set_nvol_flag(nv, CaseSensitive)
126 #define NVolClearCaseSensitive(nv)	clear_nvol_flag(nv, CaseSensitive)
127 
128 #define NVolLogFileEmpty(nv)		 test_nvol_flag(nv, LogFileEmpty)
129 #define NVolSetLogFileEmpty(nv)		  set_nvol_flag(nv, LogFileEmpty)
130 #define NVolClearLogFileEmpty(nv)	clear_nvol_flag(nv, LogFileEmpty)
131 
132 #define NVolShowSysFiles(nv)		 test_nvol_flag(nv, ShowSysFiles)
133 #define NVolSetShowSysFiles(nv)		  set_nvol_flag(nv, ShowSysFiles)
134 #define NVolClearShowSysFiles(nv)	clear_nvol_flag(nv, ShowSysFiles)
135 
136 #define NVolShowHidFiles(nv)		 test_nvol_flag(nv, ShowHidFiles)
137 #define NVolSetShowHidFiles(nv)		  set_nvol_flag(nv, ShowHidFiles)
138 #define NVolClearShowHidFiles(nv)	clear_nvol_flag(nv, ShowHidFiles)
139 
140 #define NVolHideDotFiles(nv)		 test_nvol_flag(nv, HideDotFiles)
141 #define NVolSetHideDotFiles(nv)		  set_nvol_flag(nv, HideDotFiles)
142 #define NVolClearHideDotFiles(nv)	clear_nvol_flag(nv, HideDotFiles)
143 
144 #define NVolCompression(nv)		 test_nvol_flag(nv, Compression)
145 #define NVolSetCompression(nv)		  set_nvol_flag(nv, Compression)
146 #define NVolClearCompression(nv)	clear_nvol_flag(nv, Compression)
147 
148 /*
149  * NTFS version 1.1 and 1.2 are used by Windows NT4.
150  * NTFS version 2.x is used by Windows 2000 Beta
151  * NTFS version 3.0 is used by Windows 2000.
152  * NTFS version 3.1 is used by Windows XP, 2003 and Vista.
153  */
154 
155 #define NTFS_V1_1(major, minor) ((major) == 1 && (minor) == 1)
156 #define NTFS_V1_2(major, minor) ((major) == 1 && (minor) == 2)
157 #define NTFS_V2_X(major, minor) ((major) == 2)
158 #define NTFS_V3_0(major, minor) ((major) == 3 && (minor) == 0)
159 #define NTFS_V3_1(major, minor) ((major) == 3 && (minor) == 1)
160 
161 #define NTFS_BUF_SIZE 8192
162 
163 /**
164  * struct _ntfs_volume - structure describing an open volume in memory.
165  */
166 struct _ntfs_volume {
167 	union {
168 		struct ntfs_device *dev;	/* NTFS device associated with
169 						   the volume. */
170 		void *sb;	/* For kernel porting compatibility. */
171 	};
172 	char *vol_name;		/* Name of the volume. */
173 	unsigned long state;	/* NTFS specific flags describing this volume.
174 				   See ntfs_volume_state_bits above. */
175 
176 	ntfs_inode *vol_ni;	/* ntfs_inode structure for FILE_Volume. */
177 	u8 major_ver;		/* Ntfs major version of volume. */
178 	u8 minor_ver;		/* Ntfs minor version of volume. */
179 	le16 flags;		/* Bit array of VOLUME_* flags. */
180 
181 	u16 sector_size;	/* Byte size of a sector. */
182 	u8 sector_size_bits;	/* Log(2) of the byte size of a sector. */
183 	u32 cluster_size;	/* Byte size of a cluster. */
184 	u32 mft_record_size;	/* Byte size of a mft record. */
185 	u32 indx_record_size;	/* Byte size of a INDX record. */
186 	u8 cluster_size_bits;	/* Log(2) of the byte size of a cluster. */
187 	u8 mft_record_size_bits;/* Log(2) of the byte size of a mft record. */
188 	u8 indx_record_size_bits;/* Log(2) of the byte size of a INDX record. */
189 
190 	/* Variables used by the cluster and mft allocators. */
191 	u8 mft_zone_multiplier;	/* Initial mft zone multiplier. */
192 	u8 full_zones;		/* cluster zones which are full */
193 	s64 mft_data_pos;	/* Mft record number at which to allocate the
194 				   next mft record. */
195 	LCN mft_zone_start;	/* First cluster of the mft zone. */
196 	LCN mft_zone_end;	/* First cluster beyond the mft zone. */
197 	LCN mft_zone_pos;	/* Current position in the mft zone. */
198 	LCN data1_zone_pos;	/* Current position in the first data zone. */
199 	LCN data2_zone_pos;	/* Current position in the second data zone. */
200 
201 	s64 nr_clusters;	/* Volume size in clusters, hence also the
202 				   number of bits in lcn_bitmap. */
203 	ntfs_inode *lcnbmp_ni;	/* ntfs_inode structure for FILE_Bitmap. */
204 	ntfs_attr *lcnbmp_na;	/* ntfs_attr structure for the data attribute
205 				   of FILE_Bitmap. Each bit represents a
206 				   cluster on the volume, bit 0 representing
207 				   lcn 0 and so on. A set bit means that the
208 				   cluster and vice versa. */
209 
210 	LCN mft_lcn;		/* Logical cluster number of the data attribute
211 				   for FILE_MFT. */
212 	ntfs_inode *mft_ni;	/* ntfs_inode structure for FILE_MFT. */
213 	ntfs_attr *mft_na;	/* ntfs_attr structure for the data attribute
214 				   of FILE_MFT. */
215 	ntfs_attr *mftbmp_na;	/* ntfs_attr structure for the bitmap attribute
216 				   of FILE_MFT. Each bit represents an mft
217 				   record in the $DATA attribute, bit 0
218 				   representing mft record 0 and so on. A set
219 				   bit means that the mft record is in use and
220 				   vice versa. */
221 
222 	ntfs_inode *secure_ni;	/* ntfs_inode structure for FILE $Secure */
223 	ntfs_index_context *secure_xsii; /* index for using $Secure:$SII */
224 	ntfs_index_context *secure_xsdh; /* index for using $Secure:$SDH */
225 	int secure_reentry;  /* check for non-rentries */
226 	unsigned int secure_flags;  /* flags, see security.h for values */
227 
228 	int mftmirr_size;	/* Size of the FILE_MFTMirr in mft records. */
229 	LCN mftmirr_lcn;	/* Logical cluster number of the data attribute
230 				   for FILE_MFTMirr. */
231 	ntfs_inode *mftmirr_ni;	/* ntfs_inode structure for FILE_MFTMirr. */
232 	ntfs_attr *mftmirr_na;	/* ntfs_attr structure for the data attribute
233 				   of FILE_MFTMirr. */
234 
235 	ntfschar *upcase;	/* Upper case equivalents of all 65536 2-byte
236 				   Unicode characters. Obtained from
237 				   FILE_UpCase. */
238 	u32 upcase_len;		/* Length in Unicode characters of the upcase
239 				   table. */
240 	ntfschar *locase;	/* Lower case equivalents of all 65536 2-byte
241 				   Unicode characters. Only if option
242 				   case_ignore is set. */
243 
244 	ATTR_DEF *attrdef;	/* Attribute definitions. Obtained from
245 				   FILE_AttrDef. */
246 	s32 attrdef_len;	/* Size of the attribute definition table in
247 				   bytes. */
248 
249 	s64 free_clusters; 	/* Track the number of free clusters which
250 				   greatly improves statfs() performance */
251 	s64 free_mft_records; 	/* Same for free mft records (see above) */
252 	BOOL efs_raw;		/* volume is mounted for raw access to
253 				   efs-encrypted files */
254 
255 #if CACHE_INODE_SIZE
256 	struct CACHE_HEADER *xinode_cache;
257 #endif
258 #if CACHE_NIDATA_SIZE
259 	struct CACHE_HEADER *nidata_cache;
260 #endif
261 #if CACHE_LOOKUP_SIZE
262 	struct CACHE_HEADER *lookup_cache;
263 #endif
264 #if CACHE_SECURID_SIZE
265 	struct CACHE_HEADER *securid_cache;
266 #endif
267 #if CACHE_LEGACY_SIZE
268 	struct CACHE_HEADER *legacy_cache;
269 #endif
270 
271 };
272 
273 extern const char *ntfs_home;
274 
275 extern ntfs_volume *ntfs_volume_alloc(void);
276 
277 extern ntfs_volume *ntfs_volume_startup(struct ntfs_device *dev,
278 		unsigned long flags);
279 
280 extern ntfs_volume *ntfs_device_mount(struct ntfs_device *dev,
281 		unsigned long flags);
282 
283 extern ntfs_volume *ntfs_mount(const char *name, unsigned long flags);
284 extern int ntfs_umount(ntfs_volume *vol, const BOOL force);
285 
286 extern int ntfs_version_is_supported(ntfs_volume *vol);
287 extern int ntfs_volume_check_hiberfile(ntfs_volume *vol, int verbose);
288 extern int ntfs_logfile_reset(ntfs_volume *vol);
289 
290 extern int ntfs_volume_write_flags(ntfs_volume *vol, const le16 flags);
291 
292 extern int ntfs_volume_error(int err);
293 extern void ntfs_mount_error(const char *vol, const char *mntpoint, int err);
294 
295 extern int ntfs_volume_get_free_space(ntfs_volume *vol);
296 
297 extern int ntfs_set_shown_files(ntfs_volume *vol,
298 		BOOL show_sys_files, BOOL show_hid_files, BOOL hide_dot_files);
299 extern int ntfs_set_locale(void);
300 extern int ntfs_set_ignore_case(ntfs_volume *vol);
301 
302 #endif /* defined _NTFS_VOLUME_H */
303 
304