[FS_REC]
[reactos.git] / reactos / drivers / filesystems / fs_rec / fs_rec.h
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS File System Recognizer
4 * FILE: drivers/filesystems/fs_rec/fs_rec.h
5 * PURPOSE: Main Header File
6 * PROGRAMMER: Alex Ionescu (alex.ionescu@reactos.org)
7 * Eric Kohl
8 */
9
10 #ifndef _FS_REC_H
11 #define _FS_REC_H
12
13 #include <ntifs.h>
14
15 /* Tag for memory allocations */
16 #define FSREC_TAG 'cRsF'
17
18 /* UDFS Offsets */
19 #define UDFS_VRS_START_OFFSET 32768
20 #define UDFS_AVDP_SECTOR 256
21
22 /* Non-standard rounding macros */
23 #ifndef ROUND_UP
24 #define ROUND_UP(n, align) \
25 ROUND_DOWN(((ULONG)n) + (align) - 1, (align))
26
27 #define ROUND_DOWN(n, align) \
28 (((ULONG)n) & ~((align) - 1l))
29 #endif
30
31 /* Conversion types and macros taken from internal ntifs headers */
32 typedef union _UCHAR1
33 {
34 UCHAR Uchar[1];
35 UCHAR ForceAlignment;
36 } UCHAR1, *PUCHAR1;
37
38 typedef union _UCHAR2
39 {
40 UCHAR Uchar[2];
41 USHORT ForceAlignment;
42 } UCHAR2, *PUCHAR2;
43
44 typedef union _UCHAR4
45 {
46 UCHAR Uchar[4];
47 ULONG ForceAlignment;
48 } UCHAR4, *PUCHAR4;
49
50 #define CopyUchar1(Dst,Src) { \
51 *((UCHAR1 *)(Dst)) = *((UNALIGNED UCHAR1 *)(Src)); \
52 }
53
54 #define CopyUchar2(Dst,Src) { \
55 *((UCHAR2 *)(Dst)) = *((UNALIGNED UCHAR2 *)(Src)); \
56 }
57
58 #define CopyUchar4(Dst,Src) { \
59 *((UCHAR4 *)(Dst)) = *((UNALIGNED UCHAR4 *)(Src)); \
60 }
61
62 #define FatUnpackBios(Bios,Pbios) { \
63 CopyUchar2(&(Bios)->BytesPerSector, &(Pbios)->BytesPerSector[0] ); \
64 CopyUchar1(&(Bios)->SectorsPerCluster, &(Pbios)->SectorsPerCluster[0]); \
65 CopyUchar2(&(Bios)->ReservedSectors, &(Pbios)->ReservedSectors[0] ); \
66 CopyUchar1(&(Bios)->Fats, &(Pbios)->Fats[0] ); \
67 CopyUchar2(&(Bios)->RootEntries, &(Pbios)->RootEntries[0] ); \
68 CopyUchar2(&(Bios)->Sectors, &(Pbios)->Sectors[0] ); \
69 CopyUchar1(&(Bios)->Media, &(Pbios)->Media[0] ); \
70 CopyUchar2(&(Bios)->SectorsPerFat, &(Pbios)->SectorsPerFat[0] ); \
71 CopyUchar2(&(Bios)->SectorsPerTrack, &(Pbios)->SectorsPerTrack[0] ); \
72 CopyUchar2(&(Bios)->Heads, &(Pbios)->Heads[0] ); \
73 CopyUchar4(&(Bios)->HiddenSectors, &(Pbios)->HiddenSectors[0] ); \
74 CopyUchar4(&(Bios)->LargeSectors, &(Pbios)->LargeSectors[0] ); \
75 }
76
77 /* Packed versions of the BPB and Boot Sector */
78 typedef struct _PACKED_BIOS_PARAMETER_BLOCK
79 {
80 UCHAR BytesPerSector[2];
81 UCHAR SectorsPerCluster[1];
82 UCHAR ReservedSectors[2];
83 UCHAR Fats[1];
84 UCHAR RootEntries[2];
85 UCHAR Sectors[2];
86 UCHAR Media[1];
87 UCHAR SectorsPerFat[2];
88 UCHAR SectorsPerTrack[2];
89 UCHAR Heads[2];
90 UCHAR HiddenSectors[4];
91 UCHAR LargeSectors[4];
92 } PACKED_BIOS_PARAMETER_BLOCK, *PPACKED_BIOS_PARAMETER_BLOCK;
93
94 typedef struct _PACKED_BOOT_SECTOR
95 {
96 UCHAR Jump[3];
97 UCHAR Oem[8];
98 PACKED_BIOS_PARAMETER_BLOCK PackedBpb;
99 UCHAR PhysicalDriveNumber;
100 UCHAR CurrentHead;
101 UCHAR Signature;
102 UCHAR Id[4];
103 UCHAR VolumeLabel[11];
104 UCHAR SystemId[8];
105 } PACKED_BOOT_SECTOR, *PPACKED_BOOT_SECTOR;
106
107 /* Unpacked version of the BPB */
108 typedef struct BIOS_PARAMETER_BLOCK
109 {
110 USHORT BytesPerSector;
111 UCHAR SectorsPerCluster;
112 USHORT ReservedSectors;
113 UCHAR Fats;
114 USHORT RootEntries;
115 USHORT Sectors;
116 UCHAR Media;
117 USHORT SectorsPerFat;
118 USHORT SectorsPerTrack;
119 USHORT Heads;
120 ULONG32 HiddenSectors;
121 ULONG32 LargeSectors;
122 ULONG32 LargeSectorsPerFat;
123 union
124 {
125 USHORT ExtendedFlags;
126 struct
127 {
128 ULONG ActiveFat:4;
129 ULONG Reserved0:3;
130 ULONG MirrorDisabled:1;
131 ULONG Reserved1:8;
132 };
133 };
134 USHORT FsVersion;
135 ULONG32 RootDirFirstCluster;
136 USHORT FsInfoSector;
137 USHORT BackupBootSector;
138 } BIOS_PARAMETER_BLOCK, *PBIOS_PARAMETER_BLOCK;
139
140 /* UDFS Structures */
141 #include <pshpack1.h>
142 typedef struct _TAG
143 {
144 USHORT Identifier;
145 USHORT Version;
146 UCHAR Checksum;
147 UCHAR Reserved;
148 USHORT SerialNumber;
149 USHORT Crc;
150 USHORT CrcLength;
151 ULONG Location;
152 } TAG, *PTAG;
153
154 typedef struct _EXTENT
155 {
156 ULONG Length;
157 ULONG Location;
158 } EXTENT, *PEXTENT;
159
160 typedef struct _AVDP
161 {
162 TAG DescriptorTag;
163 EXTENT MainVolumeDescriptorExtent;
164 EXTENT ReserveVolumeDescriptorExtent;
165 } AVDP, *PAVDP;
166 #include <poppack.h>
167
168 /* Filesystem Types */
169 typedef enum _FILE_SYSTEM_TYPE
170 {
171 FS_TYPE_UNUSED,
172 FS_TYPE_VFAT,
173 FS_TYPE_NTFS,
174 FS_TYPE_CDFS,
175 FS_TYPE_UDFS,
176 FS_TYPE_EXT2,
177 FS_TYPE_BTRFS,
178 FS_TYPE_REISERFS,
179 } FILE_SYSTEM_TYPE, *PFILE_SYSTEM_TYPE;
180
181 /* FS Recognizer State */
182 typedef enum _FS_REC_STATE
183 {
184 Pending,
185 Loaded,
186 Unloading
187 } FS_REC_STATE, *PFS_REC_STATE;
188
189 /* Device extension */
190 typedef struct _DEVICE_EXTENSION
191 {
192 FS_REC_STATE State;
193 FILE_SYSTEM_TYPE FsType;
194 PDEVICE_OBJECT Alternate;
195 } DEVICE_EXTENSION, *PDEVICE_EXTENSION;
196
197 /* Prototypes */
198 NTSTATUS
199 NTAPI
200 FsRecCdfsFsControl(
201 IN PDEVICE_OBJECT DeviceObject,
202 IN PIRP Irp
203 );
204
205 NTSTATUS
206 NTAPI
207 FsRecVfatFsControl(
208 IN PDEVICE_OBJECT DeviceObject,
209 IN PIRP Irp
210 );
211
212 NTSTATUS
213 NTAPI
214 FsRecNtfsFsControl(
215 IN PDEVICE_OBJECT DeviceObject,
216 IN PIRP Irp
217 );
218
219 NTSTATUS
220 NTAPI
221 FsRecUdfsFsControl(
222 IN PDEVICE_OBJECT DeviceObject,
223 IN PIRP Irp
224 );
225
226 NTSTATUS
227 NTAPI
228 FsRecExt2FsControl(
229 IN PDEVICE_OBJECT DeviceObject,
230 IN PIRP Irp
231 );
232
233 NTSTATUS
234 NTAPI
235 FsRecBtrfsFsControl(
236 IN PDEVICE_OBJECT DeviceObject,
237 IN PIRP Irp
238 );
239
240 NTSTATUS
241 NTAPI
242 FsRecReiserfsFsControl(
243 IN PDEVICE_OBJECT DeviceObject,
244 IN PIRP Irp
245 );
246
247 BOOLEAN
248 NTAPI
249 FsRecGetDeviceSectors(
250 IN PDEVICE_OBJECT DeviceObject,
251 IN ULONG SectorSize,
252 OUT PLARGE_INTEGER SectorCount
253 );
254
255 BOOLEAN
256 NTAPI
257 FsRecGetDeviceSectorSize(
258 IN PDEVICE_OBJECT DeviceObject,
259 OUT PULONG SectorSize
260 );
261
262 BOOLEAN
263 NTAPI
264 FsRecReadBlock(
265 IN PDEVICE_OBJECT DeviceObject,
266 IN PLARGE_INTEGER Offset,
267 IN ULONG Length,
268 IN ULONG SectorSize,
269 IN OUT PVOID *Buffer,
270 OUT PBOOLEAN DeviceError OPTIONAL
271 );
272
273 NTSTATUS
274 NTAPI
275 FsRecLoadFileSystem(
276 IN PDEVICE_OBJECT DeviceObject,
277 IN PWCHAR DriverServiceName
278 );
279
280 #endif /* _FS_REC_H */