xref: /haiku/src/add-ons/kernel/file_systems/ntfs/libntfs/volume.h (revision 1acbe440b8dd798953bec31d18ee589aa3f71b73)
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-2006 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 and MS_NOATIME,
47  * so we define them ourselves.
48  */
49 #ifndef MS_RDONLY
50 #define MS_RDONLY 1
51 #endif
52 /*
53  * Solaris defines MS_RDONLY but not MS_NOATIME thus we need to carefully
54  * define MS_NOATIME.
55  */
56 #ifndef MS_NOATIME
57 #if (MS_RDONLY != 1)
58 #	define MS_NOATIME 1
59 #else
60 #	define MS_NOATIME 2
61 #endif
62 #endif
63 
64 #define MS_EXCLUSIVE 0x08000000
65 
66 /* Forward declaration */
67 typedef struct _ntfs_volume ntfs_volume;
68 
69 #include "types.h"
70 #include "support.h"
71 #include "device.h"
72 #include "inode.h"
73 #include "attrib.h"
74 
75 /**
76  * enum ntfs_mount_flags -
77  *
78  * Flags returned by the ntfs_check_if_mounted() function.
79  */
80 typedef enum {
81 	NTFS_MF_MOUNTED		= 1,	/* Device is mounted. */
82 	NTFS_MF_ISROOT		= 2,	/* Device is mounted as system root. */
83 	NTFS_MF_READONLY	= 4,	/* Device is mounted read-only. */
84 } ntfs_mount_flags;
85 
86 extern int ntfs_check_if_mounted(const char *file, unsigned long *mnt_flags);
87 
88 /**
89  * enum ntfs_volume_state_bits -
90  *
91  * Defined bits for the state field in the ntfs_volume structure.
92  */
93 typedef enum {
94 	NV_ReadOnly,		/* 1: Volume is read-only. */
95 	NV_CaseSensitive,	/* 1: Volume is mounted case-sensitive. */
96 	NV_LogFileEmpty,	/* 1: $logFile journal is empty. */
97 	NV_NoATime,		/* 1: Do not update access time. */
98 } ntfs_volume_state_bits;
99 
100 #define  test_nvol_flag(nv, flag)	 test_bit(NV_##flag, (nv)->state)
101 #define   set_nvol_flag(nv, flag)	  set_bit(NV_##flag, (nv)->state)
102 #define clear_nvol_flag(nv, flag)	clear_bit(NV_##flag, (nv)->state)
103 
104 #define NVolReadOnly(nv)		 test_nvol_flag(nv, ReadOnly)
105 #define NVolSetReadOnly(nv)		  set_nvol_flag(nv, ReadOnly)
106 #define NVolClearReadOnly(nv)		clear_nvol_flag(nv, ReadOnly)
107 
108 #define NVolCaseSensitive(nv)		 test_nvol_flag(nv, CaseSensitive)
109 #define NVolSetCaseSensitive(nv)	  set_nvol_flag(nv, CaseSensitive)
110 #define NVolClearCaseSensitive(nv)	clear_nvol_flag(nv, CaseSensitive)
111 
112 #define NVolLogFileEmpty(nv)		 test_nvol_flag(nv, LogFileEmpty)
113 #define NVolSetLogFileEmpty(nv)		  set_nvol_flag(nv, LogFileEmpty)
114 #define NVolClearLogFileEmpty(nv)	clear_nvol_flag(nv, LogFileEmpty)
115 
116 #define NVolNoATime(nv)			 test_nvol_flag(nv, NoATime)
117 #define NVolSetNoATime(nv)		  set_nvol_flag(nv, NoATime)
118 #define NVolClearNoATime(nv)		clear_nvol_flag(nv, NoATime)
119 
120 /*
121  * NTFS version 1.1 and 1.2 are used by Windows NT4.
122  * NTFS version 2.x is used by Windows 2000 Beta
123  * NTFS version 3.0 is used by Windows 2000.
124  * NTFS version 3.1 is used by Windows XP, 2003 and Vista.
125  */
126 
127 #define NTFS_V1_1(major, minor) ((major) == 1 && (minor) == 1)
128 #define NTFS_V1_2(major, minor) ((major) == 1 && (minor) == 2)
129 #define NTFS_V2_X(major, minor) ((major) == 2)
130 #define NTFS_V3_0(major, minor) ((major) == 3 && (minor) == 0)
131 #define NTFS_V3_1(major, minor) ((major) == 3 && (minor) == 1)
132 
133 #define NTFS_BUF_SIZE 8192
134 
135 /**
136  * struct _ntfs_volume - structure describing an open volume in memory.
137  */
138 struct _ntfs_volume {
139 	union {
140 		struct ntfs_device *dev;	/* NTFS device associated with
141 						   the volume. */
142 		void *sb;	/* For kernel porting compatibility. */
143 	};
144 	char *vol_name;		/* Name of the volume. */
145 	unsigned long state;	/* NTFS specific flags describing this volume.
146 				   See ntfs_volume_state_bits above. */
147 
148 	ntfs_inode *vol_ni;	/* ntfs_inode structure for FILE_Volume. */
149 	u8 major_ver;		/* Ntfs major version of volume. */
150 	u8 minor_ver;		/* Ntfs minor version of volume. */
151 	u16 flags;		/* Bit array of VOLUME_* flags. */
152 
153 	u16 sector_size;	/* Byte size of a sector. */
154 	u8 sector_size_bits;	/* Log(2) of the byte size of a sector. */
155 	u32 cluster_size;	/* Byte size of a cluster. */
156 	u32 mft_record_size;	/* Byte size of a mft record. */
157 	u32 indx_record_size;	/* Byte size of a INDX record. */
158 	u8 cluster_size_bits;	/* Log(2) of the byte size of a cluster. */
159 	u8 mft_record_size_bits;/* Log(2) of the byte size of a mft record. */
160 	u8 indx_record_size_bits;/* Log(2) of the byte size of a INDX record. */
161 
162 	/* Variables used by the cluster and mft allocators. */
163 	u8 mft_zone_multiplier;	/* Initial mft zone multiplier. */
164 	s64 mft_data_pos;	/* Mft record number at which to allocate the
165 				   next mft record. */
166 	LCN mft_zone_start;	/* First cluster of the mft zone. */
167 	LCN mft_zone_end;	/* First cluster beyond the mft zone. */
168 	LCN mft_zone_pos;	/* Current position in the mft zone. */
169 	LCN data1_zone_pos;	/* Current position in the first data zone. */
170 	LCN data2_zone_pos;	/* Current position in the second data zone. */
171 
172 	s64 nr_clusters;	/* Volume size in clusters, hence also the
173 				   number of bits in lcn_bitmap. */
174 	ntfs_inode *lcnbmp_ni;	/* ntfs_inode structure for FILE_Bitmap. */
175 	ntfs_attr *lcnbmp_na;	/* ntfs_attr structure for the data attribute
176 				   of FILE_Bitmap. Each bit represents a
177 				   cluster on the volume, bit 0 representing
178 				   lcn 0 and so on. A set bit means that the
179 				   cluster and vice versa. */
180 
181 	LCN mft_lcn;		/* Logical cluster number of the data attribute
182 				   for FILE_MFT. */
183 	ntfs_inode *mft_ni;	/* ntfs_inode structure for FILE_MFT. */
184 	ntfs_attr *mft_na;	/* ntfs_attr structure for the data attribute
185 				   of FILE_MFT. */
186 	ntfs_attr *mftbmp_na;	/* ntfs_attr structure for the bitmap attribute
187 				   of FILE_MFT. Each bit represents an mft
188 				   record in the $DATA attribute, bit 0
189 				   representing mft record 0 and so on. A set
190 				   bit means that the mft record is in use and
191 				   vice versa. */
192 
193 	int mftmirr_size;	/* Size of the FILE_MFTMirr in mft records. */
194 	LCN mftmirr_lcn;	/* Logical cluster number of the data attribute
195 				   for FILE_MFTMirr. */
196 	ntfs_inode *mftmirr_ni;	/* ntfs_inode structure for FILE_MFTMirr. */
197 	ntfs_attr *mftmirr_na;	/* ntfs_attr structure for the data attribute
198 				   of FILE_MFTMirr. */
199 
200 	ntfschar *upcase;	/* Upper case equivalents of all 65536 2-byte
201 				   Unicode characters. Obtained from
202 				   FILE_UpCase. */
203 	u32 upcase_len;		/* Length in Unicode characters of the upcase
204 				   table. */
205 
206 	ATTR_DEF *attrdef;	/* Attribute definitions. Obtained from
207 				   FILE_AttrDef. */
208 	s32 attrdef_len;	/* Size of the attribute definition table in
209 				   bytes. */
210 
211 	/* Temp: for directory handling */
212 	void *private_data;	/* ntfs_dir for . */
213 	void *private_bmp1;	/* ntfs_bmp for $MFT/$BITMAP */
214 	void *private_bmp2;	/* ntfs_bmp for $Bitmap */
215 };
216 
217 extern ntfs_volume *ntfs_volume_alloc(void);
218 
219 extern ntfs_volume *ntfs_volume_startup(struct ntfs_device *dev,
220 		unsigned long flags);
221 
222 extern ntfs_volume *ntfs_device_mount(struct ntfs_device *dev,
223 		unsigned long flags);
224 extern int ntfs_device_umount(ntfs_volume *vol, const BOOL force);
225 
226 extern ntfs_volume *ntfs_mount(const char *name, unsigned long flags);
227 extern int ntfs_umount(ntfs_volume *vol, const BOOL force);
228 
229 extern int ntfs_version_is_supported(ntfs_volume *vol);
230 extern int ntfs_logfile_reset(ntfs_volume *vol);
231 
232 extern int ntfs_volume_write_flags(ntfs_volume *vol, const u16 flags);
233 
234 #endif /* defined _NTFS_VOLUME_H */
235 
236