ReactOS 0.4.15-dev-7834-g00c4b3d
fatx.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS File System Recognizer
3 * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4 * PURPOSE: FATX Recognizer
5 * COPYRIGHT: Copyright 2022 Hervé Poussineau <hpoussin@reactos.org>
6 */
7
8/* INCLUDES *****************************************************************/
9
10#include "fs_rec.h"
11
12#define NDEBUG
13#include <debug.h>
14
15/* TYPES ****************************************************************/
16
17#include <pshpack1.h>
18typedef struct _FATX_BOOT_SECTOR
19{
27#include <poppack.h>
28
29/* FUNCTIONS ****************************************************************/
30
34{
36
37 PAGED_CODE();
38
39 if (BootSector->SysType[0] != 'F' ||
40 BootSector->SysType[1] != 'A' ||
41 BootSector->SysType[2] != 'T' ||
42 BootSector->SysType[3] != 'X')
43 {
44 /* Fail */
45 Result = FALSE;
46 }
47 else if (BootSector->SectorsPerCluster != 1 &&
55 {
56 /* Fail */
57 Result = FALSE;
58 }
59
60 /* Return the result */
61 return Result;
62}
63
67 IN PIRP Irp)
68{
71 PDEVICE_OBJECT MountDevice;
74 LARGE_INTEGER Offset = {{0, 0}};
75 BOOLEAN DeviceError = FALSE;
76 PAGED_CODE();
77
78 /* Get the I/O Stack and check the function type */
80 switch (Stack->MinorFunction)
81 {
83
84 /* Assume failure */
86
87 /* Get the device object and request the sector size */
88 MountDevice = Stack->Parameters.MountVolume.DeviceObject;
89 if (FsRecGetDeviceSectorSize(MountDevice, &SectorSize))
90 {
91 /* Try to read the BPB */
92 if (FsRecReadBlock(MountDevice,
93 &Offset,
94 512,
96 (PVOID)&Bpb,
97 &DeviceError))
98 {
99 /* Check if it's an actual FAT volume */
100 if (FsRecIsFatxVolume(Bpb))
101 {
102 /* It is! */
104 }
105 }
106
107 /* Free the boot sector if we have one */
108 ExFreePool(Bpb);
109 }
110
111 break;
112
114
115 /* Load the file system */
117 L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\vfatfs");
118 break;
119
120 default:
121
122 /* Invalid request */
124 }
125
126 /* Return Status */
127 return Status;
128}
129
130/* EOF */
#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
BOOLEAN NTAPI FsRecIsFatxVolume(IN PFATX_BOOT_SECTOR BootSector)
Definition: fatx.c:33
struct _FATX_BOOT_SECTOR FATX_BOOT_SECTOR
NTSTATUS NTAPI FsRecFatxFsControl(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: fatx.c:66
struct _FATX_BOOT_SECTOR * PFATX_BOOT_SECTOR
#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
_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
unsigned short USHORT
Definition: pedump.c:61
BYTE SectorsPerCluster
Definition: fatfs.h:76
ULONG VolumeId
Definition: fatx.c:21
ULONG Reserved
Definition: fatx.c:24
USHORT FatCount
Definition: fatx.c:23
UCHAR SysType[4]
Definition: fatx.c:20
ULONG SectorsPerCluster
Definition: fatx.c:22
UCHAR Unused[4078]
Definition: fatx.c:25
#define NTAPI
Definition: typedefs.h:36
#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
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2793
#define IRP_MN_LOAD_FILE_SYSTEM
Definition: iotypes.h:4406
#define IRP_MN_MOUNT_VOLUME
Definition: iotypes.h:4404
unsigned char UCHAR
Definition: xmlstorage.h:181