2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS File System Recognizer
4 * FILE: drivers/filesystems/fs_rec/fat.c
5 * PURPOSE: FAT Recognizer
6 * PROGRAMMER: Alex Ionescu (alex.ionescu@reactos.org)
10 /* INCLUDES *****************************************************************/
16 /* FUNCTIONS ****************************************************************/
20 FsRecIsFatVolume(IN PPACKED_BOOT_SECTOR PackedBootSector
)
22 BIOS_PARAMETER_BLOCK Bpb
;
23 BOOLEAN Result
= TRUE
;
26 RtlZeroMemory(&Bpb
, sizeof(BIOS_PARAMETER_BLOCK
));
28 /* Unpack the BPB and do a small fix up */
29 FatUnpackBios(&Bpb
, &PackedBootSector
->PackedBpb
);
30 if (Bpb
.Sectors
) Bpb
.LargeSectors
= 0;
33 if ((PackedBootSector
->Jump
[0] != 0x49) &&
34 (PackedBootSector
->Jump
[0] != 0xE9) &&
35 (PackedBootSector
->Jump
[0] != 0xEB))
40 else if ((Bpb
.BytesPerSector
!= 128) &&
41 (Bpb
.BytesPerSector
!= 256) &&
42 (Bpb
.BytesPerSector
!= 512) &&
43 (Bpb
.BytesPerSector
!= 1024) &&
44 (Bpb
.BytesPerSector
!= 2048) &&
45 (Bpb
.BytesPerSector
!= 4096))
50 else if ((Bpb
.SectorsPerCluster
!= 1) &&
51 (Bpb
.SectorsPerCluster
!= 2) &&
52 (Bpb
.SectorsPerCluster
!= 4) &&
53 (Bpb
.SectorsPerCluster
!= 8) &&
54 (Bpb
.SectorsPerCluster
!= 16) &&
55 (Bpb
.SectorsPerCluster
!= 32) &&
56 (Bpb
.SectorsPerCluster
!= 64) &&
57 (Bpb
.SectorsPerCluster
!= 128))
62 else if (!Bpb
.ReservedSectors
)
67 else if (!(Bpb
.Sectors
) && !(Bpb
.LargeSectors
))
72 else if ((Bpb
.Media
!= 0x00) &&
73 (Bpb
.Media
!= 0x01) &&
74 (Bpb
.Media
!= 0xf0) &&
75 (Bpb
.Media
!= 0xf8) &&
76 (Bpb
.Media
!= 0xf9) &&
77 (Bpb
.Media
!= 0xfa) &&
78 (Bpb
.Media
!= 0xfb) &&
79 (Bpb
.Media
!= 0xfc) &&
80 (Bpb
.Media
!= 0xfd) &&
81 (Bpb
.Media
!= 0xfe) &&
87 else if ((Bpb
.SectorsPerFat
) && !(Bpb
.RootEntries
))
93 /* Return the result */
99 FsRecVfatFsControl(IN PDEVICE_OBJECT DeviceObject
,
102 PIO_STACK_LOCATION Stack
;
104 PDEVICE_OBJECT MountDevice
;
105 PPACKED_BOOT_SECTOR Bpb
= NULL
;
107 LARGE_INTEGER Offset
= {{0, 0}};
108 BOOLEAN DeviceError
= FALSE
;
111 /* Get the I/O Stack and check the function type */
112 Stack
= IoGetCurrentIrpStackLocation(Irp
);
113 switch (Stack
->MinorFunction
)
115 case IRP_MN_MOUNT_VOLUME
:
118 Status
= STATUS_UNRECOGNIZED_VOLUME
;
120 /* Get the device object and request the sector size */
121 MountDevice
= Stack
->Parameters
.MountVolume
.DeviceObject
;
122 if (FsRecGetDeviceSectorSize(MountDevice
, &SectorSize
))
124 /* Try to read the BPB */
125 if (FsRecReadBlock(MountDevice
,
132 /* Check if it's an actual FAT volume */
133 if (FsRecIsFatVolume(Bpb
))
136 Status
= STATUS_FS_DRIVER_REQUIRED
;
140 /* Free the boot sector if we have one */
145 /* We have some sort of failure in the storage stack */
149 /* Check if we have an error on the stack */
152 /* Was this because of a floppy? */
153 if (MountDevice
->Characteristics
& FILE_FLOPPY_DISKETTE
)
155 /* Let the FS try anyway */
156 Status
= STATUS_FS_DRIVER_REQUIRED
;
162 case IRP_MN_LOAD_FILE_SYSTEM
:
164 /* Load the file system */
165 Status
= FsRecLoadFileSystem(DeviceObject
,
166 L
"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\fastfat");
171 /* Invalid request */
172 Status
= STATUS_INVALID_DEVICE_REQUEST
;