2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS File System Recognizer
4 * FILE: drivers/filesystems/fs_rec/ntfs.c
5 * PURPOSE: NTFS Recognizer
6 * PROGRAMMER: Alex Ionescu (alex.ionescu@reactos.org)
10 /* INCLUDES *****************************************************************/
16 /* FUNCTIONS ****************************************************************/
20 FsRecIsNtfsVolume(IN PPACKED_BOOT_SECTOR BootSector
,
21 IN ULONG BytesPerSector
,
22 IN PLARGE_INTEGER NumberOfSectors
)
25 BOOLEAN Result
= FALSE
;
29 if ((BootSector
->Oem
[0] == 'N') &&
30 (BootSector
->Oem
[1] == 'T') &&
31 (BootSector
->Oem
[2] == 'F') &&
32 (BootSector
->Oem
[3] == 'S') &&
33 (BootSector
->Oem
[4] == ' ') &&
34 (BootSector
->Oem
[5] == ' ') &&
35 (BootSector
->Oem
[6] == ' ') &&
36 (BootSector
->Oem
[7] == ' '))
42 /* Return the result */
48 FsRecNtfsFsControl(IN PDEVICE_OBJECT DeviceObject
,
51 PIO_STACK_LOCATION Stack
;
53 PDEVICE_OBJECT MountDevice
;
54 PPACKED_BOOT_SECTOR Bpb
= NULL
;
56 LARGE_INTEGER Offset
= {{0, 0}}, Offset2
, Offset3
, SectorCount
;
59 /* Get the I/O Stack and check the function type */
60 Stack
= IoGetCurrentIrpStackLocation(Irp
);
61 switch (Stack
->MinorFunction
)
63 case IRP_MN_MOUNT_VOLUME
:
66 Status
= STATUS_UNRECOGNIZED_VOLUME
;
68 /* Get the device object and request the sector size */
69 MountDevice
= Stack
->Parameters
.MountVolume
.DeviceObject
;
70 if ((FsRecGetDeviceSectorSize(MountDevice
, &SectorSize
)) &&
71 (FsRecGetDeviceSectors(MountDevice
, SectorSize
, &SectorCount
)))
73 /* Setup other offsets to try */
74 Offset2
.QuadPart
= SectorCount
.QuadPart
>> 1;
75 Offset2
.QuadPart
*= SectorSize
;
76 Offset3
.QuadPart
= (SectorCount
.QuadPart
- 1) * SectorSize
;
78 /* Try to read the BPB */
79 if (FsRecReadBlock(MountDevice
,
86 /* Check if it's an actual NTFS volume */
87 if (FsRecIsNtfsVolume(Bpb
, SectorSize
, &SectorCount
))
90 Status
= STATUS_FS_DRIVER_REQUIRED
;
93 else if (FsRecReadBlock(MountDevice
,
100 /* Check if it's an actual NTFS volume */
101 if (FsRecIsNtfsVolume(Bpb
, SectorSize
, &SectorCount
))
104 Status
= STATUS_FS_DRIVER_REQUIRED
;
107 else if (FsRecReadBlock(MountDevice
,
114 /* Check if it's an actual NTFS volume */
115 if (FsRecIsNtfsVolume(Bpb
, SectorSize
, &SectorCount
))
118 Status
= STATUS_FS_DRIVER_REQUIRED
;
122 /* Free the boot sector if we have one */
127 case IRP_MN_LOAD_FILE_SYSTEM
:
129 /* Load the file system */
130 Status
= FsRecLoadFileSystem(DeviceObject
,
131 L
"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\Ntfs");
136 /* Invalid request */
137 Status
= STATUS_INVALID_DEVICE_REQUEST
;