ReactOS 0.4.16-dev-306-g647d351
fat.c
Go to the documentation of this file.
1/*
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)
7 * Eric Kohl
8 */
9
10/* INCLUDES *****************************************************************/
11
12#include "fs_rec.h"
13
14#define NDEBUG
15#include <debug.h>
16
17/* FUNCTIONS ****************************************************************/
18
22{
25 PAGED_CODE();
26
28
29 /* Unpack the BPB and do a small fix up */
30 FatUnpackBios(&Bpb, &PackedBootSector->PackedBpb);
31 if (Bpb.Sectors) Bpb.LargeSectors = 0;
32
33 /* Recognize jump */
34 if ((PackedBootSector->Jump[0] != 0x49) &&
35 (PackedBootSector->Jump[0] != 0xE9) &&
36 (PackedBootSector->Jump[0] != 0xEB))
37 {
38 /* Fail */
39 Result = FALSE;
40 }
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))
47 {
48 /* Fail */
49 Result = FALSE;
50 }
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))
59 {
60 /* Fail */
61 Result = FALSE;
62 }
63 else if (!Bpb.ReservedSectors)
64 {
65 /* Fail */
66 Result = FALSE;
67 }
68 else if (!(Bpb.Sectors) && !(Bpb.LargeSectors))
69 {
70 /* Fail */
71 Result = FALSE;
72 }
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) &&
83 (Bpb.Media != 0xff))
84 {
85 /* Fail */
86 Result = FALSE;
87 }
88 else if ((Bpb.SectorsPerFat) && !(Bpb.RootEntries))
89 {
90 /* Fail */
91 Result = FALSE;
92 }
93
94 /* Return the result */
95 return Result;
96}
97
101 IN PIRP Irp)
102{
105 PDEVICE_OBJECT MountDevice;
108 LARGE_INTEGER Offset = {{0, 0}};
109 BOOLEAN DeviceError = FALSE;
110 PAGED_CODE();
111
112 /* Get the I/O Stack and check the function type */
114 switch (Stack->MinorFunction)
115 {
117
118 /* Assume failure */
120
121 /* Get the device object and request the sector size */
122 MountDevice = Stack->Parameters.MountVolume.DeviceObject;
123 if (FsRecGetDeviceSectorSize(MountDevice, &SectorSize))
124 {
125 /* Try to read the BPB */
126 if (FsRecReadBlock(MountDevice,
127 &Offset,
128 512,
130 (PVOID)&Bpb,
131 &DeviceError))
132 {
133 /* Check if it's an actual FAT volume */
134 if (FsRecIsFatVolume(Bpb))
135 {
136 /* It is! */
138 }
139 }
140
141 /* Free the boot sector if we have one */
142 ExFreePool(Bpb);
143 }
144 else
145 {
146 /* We have some sort of failure in the storage stack */
147 DeviceError = TRUE;
148 }
149
150 /* Check if we have an error on the stack */
151 if (DeviceError)
152 {
153 /* Was this because of a floppy? */
154 if (MountDevice->Characteristics & FILE_FLOPPY_DISKETTE)
155 {
156 /* Let the FS try anyway */
158 }
159 }
160
161 break;
162
164
165 /* Load the file system */
167 L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\fastfat");
168 break;
169
170 default:
171
172 /* Invalid request */
174 }
175
176 /* Return Status */
177 return Status;
178}
179
180/* EOF */
static PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(PIRP Irp)
#define PAGED_CODE()
unsigned char BOOLEAN
LONG NTSTATUS
Definition: precomp.h:26
_In_ PIRP Irp
Definition: csq.h:116
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define FatUnpackBios(Bios, Pbios)
Definition: fat.h:136
BOOLEAN NTAPI FsRecIsFatVolume(IN PPACKED_BOOT_SECTOR PackedBootSector)
Definition: fat.c:21
NTSTATUS NTAPI FsRecVfatFsControl(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: fat.c:100
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
BOOLEAN NTAPI FsRecReadBlock(IN PDEVICE_OBJECT DeviceObject, IN PLARGE_INTEGER Offset, IN ULONG Length, IN ULONG SectorSize, IN OUT PVOID *Buffer, OUT PBOOLEAN DeviceError OPTIONAL)
Definition: blockdev.c:152
BOOLEAN NTAPI FsRecGetDeviceSectorSize(IN PDEVICE_OBJECT DeviceObject, OUT PULONG SectorSize)
Definition: blockdev.c:80
NTSTATUS NTAPI FsRecLoadFileSystem(IN PDEVICE_OBJECT DeviceObject, IN PWCHAR DriverServiceName)
Definition: fs_rec.c:23
Status
Definition: gdiplustypes.h:25
#define FILE_FLOPPY_DISKETTE
Definition: nt_native.h:809
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
#define STATUS_FS_DRIVER_REQUIRED
Definition: ntstatus.h:645
#define L(x)
Definition: ntvdm.h:50
USHORT ReservedSectors
Definition: fat.h:106
USHORT BytesPerSector
Definition: fat.h:104
USHORT Sectors
Definition: fat.h:109
ULONG32 LargeSectors
Definition: fat.h:115
USHORT RootEntries
Definition: fat.h:108
UCHAR SectorsPerCluster
Definition: fat.h:105
USHORT SectorsPerFat
Definition: fat.h:111
#define NTAPI
Definition: typedefs.h:36
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define IN
Definition: typedefs.h:39
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
#define STATUS_UNRECOGNIZED_VOLUME
Definition: udferr_usr.h:173
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_In_ WDFREQUEST _In_ PIO_STACK_LOCATION Stack
Definition: wdfrequest.h:639
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:409
_In_ ULONG SectorSize
Definition: halfuncs.h:291
#define IRP_MN_LOAD_FILE_SYSTEM
Definition: iotypes.h:4406
#define IRP_MN_MOUNT_VOLUME
Definition: iotypes.h:4404