ReactOS 0.4.16-dev-197-g92996da
fat.c File Reference
#include "fs_rec.h"
#include <debug.h>
Include dependency graph for fat.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

BOOLEAN NTAPI FsRecIsFatVolume (IN PPACKED_BOOT_SECTOR PackedBootSector)
 
NTSTATUS NTAPI FsRecVfatFsControl (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 14 of file fat.c.

Function Documentation

◆ FsRecIsFatVolume()

BOOLEAN NTAPI FsRecIsFatVolume ( IN PPACKED_BOOT_SECTOR  PackedBootSector)

Definition at line 21 of file fat.c.

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}
#define PAGED_CODE()
unsigned char BOOLEAN
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define FatUnpackBios(Bios, Pbios)
Definition: fat.h:136
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 RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
_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

Referenced by FsRecVfatFsControl().

◆ FsRecVfatFsControl()

NTSTATUS NTAPI FsRecVfatFsControl ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

Definition at line 100 of file fat.c.

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}
static PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(PIRP Irp)
LONG NTSTATUS
Definition: precomp.h:26
_In_ PIRP Irp
Definition: csq.h:116
#define NULL
Definition: types.h:112
BOOLEAN NTAPI FsRecIsFatVolume(IN PPACKED_BOOT_SECTOR PackedBootSector)
Definition: fat.c:21
#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
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
_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

Referenced by FsRecFsControl().