blob: 253e482b8972d8dc209853258351202b80ba7efb
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 | } ntfs_volume_state_bits; |
111 | |
112 | #define test_nvol_flag(nv, flag) test_bit(NV_##flag, (nv)->state) |
113 | #define set_nvol_flag(nv, flag) set_bit(NV_##flag, (nv)->state) |
114 | #define clear_nvol_flag(nv, flag) clear_bit(NV_##flag, (nv)->state) |
115 | |
116 | #define NVolReadOnly(nv) test_nvol_flag(nv, ReadOnly) |
117 | #define NVolSetReadOnly(nv) set_nvol_flag(nv, ReadOnly) |
118 | #define NVolClearReadOnly(nv) clear_nvol_flag(nv, ReadOnly) |
119 | |
120 | #define NVolCaseSensitive(nv) test_nvol_flag(nv, CaseSensitive) |
121 | #define NVolSetCaseSensitive(nv) set_nvol_flag(nv, CaseSensitive) |
122 | #define NVolClearCaseSensitive(nv) clear_nvol_flag(nv, CaseSensitive) |
123 | |
124 | #define NVolLogFileEmpty(nv) test_nvol_flag(nv, LogFileEmpty) |
125 | #define NVolSetLogFileEmpty(nv) set_nvol_flag(nv, LogFileEmpty) |
126 | #define NVolClearLogFileEmpty(nv) clear_nvol_flag(nv, LogFileEmpty) |
127 | |
128 | /* |
129 | * NTFS version 1.1 and 1.2 are used by Windows NT4. |
130 | * NTFS version 2.x is used by Windows 2000 Beta |
131 | * NTFS version 3.0 is used by Windows 2000. |
132 | * NTFS version 3.1 is used by Windows XP, 2003 and Vista. |
133 | */ |
134 | |
135 | #define NTFS_V1_1(major, minor) ((major) == 1 && (minor) == 1) |
136 | #define NTFS_V1_2(major, minor) ((major) == 1 && (minor) == 2) |
137 | #define NTFS_V2_X(major, minor) ((major) == 2) |
138 | #define NTFS_V3_0(major, minor) ((major) == 3 && (minor) == 0) |
139 | #define NTFS_V3_1(major, minor) ((major) == 3 && (minor) == 1) |
140 | |
141 | #define NTFS_BUF_SIZE 8192 |
142 | |
143 | /** |
144 | * struct _ntfs_volume - structure describing an open volume in memory. |
145 | */ |
146 | struct _ntfs_volume { |
147 | union { |
148 | struct ntfs_device *dev; /* NTFS device associated with |
149 | the volume. */ |
150 | void *sb; /* For kernel porting compatibility. */ |
151 | }; |
152 | char *vol_name; /* Name of the volume. */ |
153 | unsigned long state; /* NTFS specific flags describing this volume. |
154 | See ntfs_volume_state_bits above. */ |
155 | |
156 | ntfs_inode *vol_ni; /* ntfs_inode structure for FILE_Volume. */ |
157 | u8 major_ver; /* Ntfs major version of volume. */ |
158 | u8 minor_ver; /* Ntfs minor version of volume. */ |
159 | le16 flags; /* Bit array of VOLUME_* flags. */ |
160 | |
161 | u16 sector_size; /* Byte size of a sector. */ |
162 | u8 sector_size_bits; /* Log(2) of the byte size of a sector. */ |
163 | u32 cluster_size; /* Byte size of a cluster. */ |
164 | u32 mft_record_size; /* Byte size of a mft record. */ |
165 | u32 indx_record_size; /* Byte size of a INDX record. */ |
166 | u8 cluster_size_bits; /* Log(2) of the byte size of a cluster. */ |
167 | u8 mft_record_size_bits;/* Log(2) of the byte size of a mft record. */ |
168 | u8 indx_record_size_bits;/* Log(2) of the byte size of a INDX record. */ |
169 | |
170 | /* Variables used by the cluster and mft allocators. */ |
171 | u8 mft_zone_multiplier; /* Initial mft zone multiplier. */ |
172 | u8 full_zones; /* cluster zones which are full */ |
173 | s64 mft_data_pos; /* Mft record number at which to allocate the |
174 | next mft record. */ |
175 | LCN mft_zone_start; /* First cluster of the mft zone. */ |
176 | LCN mft_zone_end; /* First cluster beyond the mft zone. */ |
177 | LCN mft_zone_pos; /* Current position in the mft zone. */ |
178 | LCN data1_zone_pos; /* Current position in the first data zone. */ |
179 | LCN data2_zone_pos; /* Current position in the second data zone. */ |
180 | |
181 | s64 nr_clusters; /* Volume size in clusters, hence also the |
182 | number of bits in lcn_bitmap. */ |
183 | ntfs_inode *lcnbmp_ni; /* ntfs_inode structure for FILE_Bitmap. */ |
184 | ntfs_attr *lcnbmp_na; /* ntfs_attr structure for the data attribute |
185 | of FILE_Bitmap. Each bit represents a |
186 | cluster on the volume, bit 0 representing |
187 | lcn 0 and so on. A set bit means that the |
188 | cluster and vice versa. */ |
189 | |
190 | LCN mft_lcn; /* Logical cluster number of the data attribute |
191 | for FILE_MFT. */ |
192 | ntfs_inode *mft_ni; /* ntfs_inode structure for FILE_MFT. */ |
193 | ntfs_attr *mft_na; /* ntfs_attr structure for the data attribute |
194 | of FILE_MFT. */ |
195 | ntfs_attr *mftbmp_na; /* ntfs_attr structure for the bitmap attribute |
196 | of FILE_MFT. Each bit represents an mft |
197 | record in the $DATA attribute, bit 0 |
198 | representing mft record 0 and so on. A set |
199 | bit means that the mft record is in use and |
200 | vice versa. */ |
201 | |
202 | ntfs_inode *secure_ni; /* ntfs_inode structure for FILE $Secure */ |
203 | ntfs_index_context *secure_xsii; /* index for using $Secure:$SII */ |
204 | ntfs_index_context *secure_xsdh; /* index for using $Secure:$SDH */ |
205 | int secure_reentry; /* check for non-rentries */ |
206 | unsigned int secure_flags; /* flags, see security.h for values */ |
207 | |
208 | int mftmirr_size; /* Size of the FILE_MFTMirr in mft records. */ |
209 | LCN mftmirr_lcn; /* Logical cluster number of the data attribute |
210 | for FILE_MFTMirr. */ |
211 | ntfs_inode *mftmirr_ni; /* ntfs_inode structure for FILE_MFTMirr. */ |
212 | ntfs_attr *mftmirr_na; /* ntfs_attr structure for the data attribute |
213 | of FILE_MFTMirr. */ |
214 | |
215 | ntfschar *upcase; /* Upper case equivalents of all 65536 2-byte |
216 | Unicode characters. Obtained from |
217 | FILE_UpCase. */ |
218 | u32 upcase_len; /* Length in Unicode characters of the upcase |
219 | table. */ |
220 | |
221 | ATTR_DEF *attrdef; /* Attribute definitions. Obtained from |
222 | FILE_AttrDef. */ |
223 | s32 attrdef_len; /* Size of the attribute definition table in |
224 | bytes. */ |
225 | |
226 | s64 free_clusters; /* Track the number of free clusters which |
227 | greatly improves statfs() performance */ |
228 | s64 free_mft_records; /* Same for free mft records (see above) */ |
229 | BOOL efs_raw; /* volume is mounted for raw access to |
230 | efs-encrypted files */ |
231 | |
232 | #if CACHE_INODE_SIZE |
233 | struct CACHE_HEADER *xinode_cache; |
234 | #endif |
235 | #if CACHE_NIDATA_SIZE |
236 | struct CACHE_HEADER *nidata_cache; |
237 | #endif |
238 | #if CACHE_LOOKUP_SIZE |
239 | struct CACHE_HEADER *lookup_cache; |
240 | #endif |
241 | #if CACHE_SECURID_SIZE |
242 | struct CACHE_HEADER *securid_cache; |
243 | #endif |
244 | #if CACHE_LEGACY_SIZE |
245 | struct CACHE_HEADER *legacy_cache; |
246 | #endif |
247 | |
248 | }; |
249 | |
250 | extern const char *ntfs_home; |
251 | |
252 | extern ntfs_volume *ntfs_volume_alloc(void); |
253 | |
254 | extern ntfs_volume *ntfs_volume_startup(struct ntfs_device *dev, |
255 | unsigned long flags); |
256 | |
257 | extern ntfs_volume *ntfs_device_mount(struct ntfs_device *dev, |
258 | unsigned long flags); |
259 | |
260 | extern ntfs_volume *ntfs_mount(const char *name, unsigned long flags); |
261 | extern int ntfs_umount(ntfs_volume *vol, const BOOL force); |
262 | |
263 | extern int ntfs_version_is_supported(ntfs_volume *vol); |
264 | extern int ntfs_volume_check_hiberfile(ntfs_volume *vol, int verbose); |
265 | extern int ntfs_logfile_reset(ntfs_volume *vol); |
266 | |
267 | extern int ntfs_volume_write_flags(ntfs_volume *vol, const le16 flags); |
268 | |
269 | extern int ntfs_volume_error(int err); |
270 | extern void ntfs_mount_error(const char *vol, const char *mntpoint, int err); |
271 | |
272 | extern int ntfs_volume_get_free_space(ntfs_volume *vol); |
273 | |
274 | extern int ntfs_set_locale(void); |
275 | |
276 | #endif /* defined _NTFS_VOLUME_H */ |
277 | |
278 |