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 *****************************************************************/
17 /* FUNCTIONS ****************************************************************/
21 FsRecIsFatVolume(IN PPACKED_BOOT_SECTOR PackedBootSector
)
23 BIOS_PARAMETER_BLOCK Bpb
;
24 BOOLEAN Result
= TRUE
;
27 RtlZeroMemory(&Bpb
, sizeof(BIOS_PARAMETER_BLOCK
));
29 /* Unpack the BPB and do a small fix up */
30 FatUnpackBios(&Bpb
, &PackedBootSector
->PackedBpb
);
31 if (Bpb
.Sectors
) Bpb
.LargeSectors
= 0;
34 if ((PackedBootSector
->Jump
[0] != 0x49) &&
35 (PackedBootSector
->Jump
[0] != 0xE9) &&
36 (PackedBootSector
->Jump
[0] != 0xEB))
41 else if ((Bpb
.BytesPerSector
!= 128) &&
42 (Bpb
.BytesPerSector
!= 256) &&
43 (Bpb
.BytesPerSector
!= 512) &&
44 (Bpb
.BytesPerSector
!= 1024) &&
45 (Bpb
.BytesPerSector
!= 2048) &&
46 (Bpb
.BytesPerSector
!= 4096))
51 else if ((Bpb
.SectorsPerCluster
!= 1) &&
52 (Bpb
.SectorsPerCluster
!= 2) &&
53 (Bpb
.SectorsPerCluster
!= 4) &&
54 (Bpb
.SectorsPerCluster
!= 8) &&
55 (Bpb
.SectorsPerCluster
!= 16) &&
56 (Bpb
.SectorsPerCluster
!= 32) &&
57 (Bpb
.SectorsPerCluster
!= 64) &&
58 (Bpb
.SectorsPerCluster
!= 128))
63 else if (!Bpb
.ReservedSectors
)
68 else if (!(Bpb
.Sectors
) && !(Bpb
.LargeSectors
))
73 else if ((Bpb
.Media
!= 0x00) &&
74 (Bpb
.Media
!= 0x01) &&
75 (Bpb
.Media
!= 0xf0) &&
76 (Bpb
.Media
!= 0xf8) &&
77 (Bpb
.Media
!= 0xf9) &&
78 (Bpb
.Media
!= 0xfa) &&
79 (Bpb
.Media
!= 0xfb) &&
80 (Bpb
.Media
!= 0xfc) &&
81 (Bpb
.Media
!= 0xfd) &&
82 (Bpb
.Media
!= 0xfe) &&
88 else if ((Bpb
.SectorsPerFat
) && !(Bpb
.RootEntries
))
94 /* Return the result */
100 FsRecVfatFsControl(IN PDEVICE_OBJECT DeviceObject
,
103 PIO_STACK_LOCATION Stack
;
105 PDEVICE_OBJECT MountDevice
;
106 PPACKED_BOOT_SECTOR Bpb
= NULL
;
108 LARGE_INTEGER Offset
= {{0, 0}};
109 BOOLEAN DeviceError
= FALSE
;
112 /* Get the I/O Stack and check the function type */
113 Stack
= IoGetCurrentIrpStackLocation(Irp
);
114 switch (Stack
->MinorFunction
)
116 case IRP_MN_MOUNT_VOLUME
:
119 Status
= STATUS_UNRECOGNIZED_VOLUME
;
121 /* Get the device object and request the sector size */
122 MountDevice
= Stack
->Parameters
.MountVolume
.DeviceObject
;
123 if (FsRecGetDeviceSectorSize(MountDevice
, &SectorSize
))
125 /* Try to read the BPB */
126 if (FsRecReadBlock(MountDevice
,
133 /* Check if it's an actual FAT volume */
134 if (FsRecIsFatVolume(Bpb
))
137 Status
= STATUS_FS_DRIVER_REQUIRED
;
141 /* Free the boot sector if we have one */
146 /* We have some sort of failure in the storage stack */
150 /* Check if we have an error on the stack */
153 /* Was this because of a floppy? */
154 if (MountDevice
->Characteristics
& FILE_FLOPPY_DISKETTE
)
156 /* Let the FS try anyway */
157 Status
= STATUS_FS_DRIVER_REQUIRED
;
163 case IRP_MN_LOAD_FILE_SYSTEM
:
165 /* Load the file system */
166 Status
= FsRecLoadFileSystem(DeviceObject
,
167 L
"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\fastfat");
172 /* Invalid request */
173 Status
= STATUS_INVALID_DEVICE_REQUEST
;