xref: /reactos/drivers/filesystems/fs_rec/fs_rec.h (revision 84344399)
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     FS_TYPE_FFS,
180     FS_TYPE_FATX,
181 } FILE_SYSTEM_TYPE, *PFILE_SYSTEM_TYPE;
182 
183 /* FS Recognizer State */
184 typedef enum _FS_REC_STATE
185 {
186     Pending,
187     Loaded,
188     Unloading
189 } FS_REC_STATE, *PFS_REC_STATE;
190 
191 /* Device extension */
192 typedef struct _DEVICE_EXTENSION
193 {
194     FS_REC_STATE State;
195     FILE_SYSTEM_TYPE FsType;
196     PDEVICE_OBJECT Alternate;
197 } DEVICE_EXTENSION, *PDEVICE_EXTENSION;
198 
199 /* Prototypes */
200 NTSTATUS
201 NTAPI
202 FsRecCdfsFsControl(
203     IN PDEVICE_OBJECT DeviceObject,
204     IN PIRP Irp
205 );
206 
207 NTSTATUS
208 NTAPI
209 FsRecVfatFsControl(
210     IN PDEVICE_OBJECT DeviceObject,
211     IN PIRP Irp
212 );
213 
214 NTSTATUS
215 NTAPI
216 FsRecNtfsFsControl(
217     IN PDEVICE_OBJECT DeviceObject,
218     IN PIRP Irp
219 );
220 
221 NTSTATUS
222 NTAPI
223 FsRecUdfsFsControl(
224     IN PDEVICE_OBJECT DeviceObject,
225     IN PIRP Irp
226 );
227 
228 NTSTATUS
229 NTAPI
230 FsRecExt2FsControl(
231     IN PDEVICE_OBJECT DeviceObject,
232     IN PIRP Irp
233 );
234 
235 NTSTATUS
236 NTAPI
237 FsRecBtrfsFsControl(
238     IN PDEVICE_OBJECT DeviceObject,
239     IN PIRP Irp
240 );
241 
242 NTSTATUS
243 NTAPI
244 FsRecReiserfsFsControl(
245     IN PDEVICE_OBJECT DeviceObject,
246     IN PIRP Irp
247 );
248 
249 NTSTATUS
250 NTAPI
251 FsRecFfsFsControl(
252     IN PDEVICE_OBJECT DeviceObject,
253     IN PIRP Irp
254 );
255 
256 NTSTATUS
257 NTAPI
258 FsRecFatxFsControl(
259     IN PDEVICE_OBJECT DeviceObject,
260     IN PIRP Irp
261 );
262 
263 BOOLEAN
264 NTAPI
265 FsRecGetDeviceSectors(
266     IN PDEVICE_OBJECT DeviceObject,
267     IN ULONG SectorSize,
268     OUT PLARGE_INTEGER SectorCount
269 );
270 
271 BOOLEAN
272 NTAPI
273 FsRecGetDeviceSectorSize(
274     IN PDEVICE_OBJECT DeviceObject,
275     OUT PULONG SectorSize
276 );
277 
278 BOOLEAN
279 NTAPI
280 FsRecReadBlock(
281     IN PDEVICE_OBJECT DeviceObject,
282     IN PLARGE_INTEGER Offset,
283     IN ULONG Length,
284     IN ULONG SectorSize,
285     IN OUT PVOID *Buffer,
286     OUT PBOOLEAN DeviceError OPTIONAL
287 );
288 
289 NTSTATUS
290 NTAPI
291 FsRecLoadFileSystem(
292     IN PDEVICE_OBJECT DeviceObject,
293     IN PWCHAR DriverServiceName
294 );
295 
296 #endif /* _FS_REC_H */
297