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 *****************************************************************/
17 /* FUNCTIONS ****************************************************************/
21 FsRecIsNtfsVolume(IN PPACKED_BOOT_SECTOR BootSector
,
22 IN ULONG BytesPerSector
,
23 IN PLARGE_INTEGER NumberOfSectors
)
26 BOOLEAN Result
= FALSE
;
28 UNREFERENCED_PARAMETER(BytesPerSector
);
29 UNREFERENCED_PARAMETER(NumberOfSectors
);
33 if ((BootSector
->Oem
[0] == 'N') &&
34 (BootSector
->Oem
[1] == 'T') &&
35 (BootSector
->Oem
[2] == 'F') &&
36 (BootSector
->Oem
[3] == 'S') &&
37 (BootSector
->Oem
[4] == ' ') &&
38 (BootSector
->Oem
[5] == ' ') &&
39 (BootSector
->Oem
[6] == ' ') &&
40 (BootSector
->Oem
[7] == ' '))
46 /* Return the result */
52 FsRecNtfsFsControl(IN PDEVICE_OBJECT DeviceObject
,
55 PIO_STACK_LOCATION Stack
;
57 PDEVICE_OBJECT MountDevice
;
58 PPACKED_BOOT_SECTOR Bpb
= NULL
;
60 LARGE_INTEGER Offset
= {{0, 0}}, Offset2
, Offset3
, SectorCount
;
63 /* Get the I/O Stack and check the function type */
64 Stack
= IoGetCurrentIrpStackLocation(Irp
);
65 switch (Stack
->MinorFunction
)
67 case IRP_MN_MOUNT_VOLUME
:
70 Status
= STATUS_UNRECOGNIZED_VOLUME
;
72 /* Get the device object and request the sector size */
73 MountDevice
= Stack
->Parameters
.MountVolume
.DeviceObject
;
74 if ((FsRecGetDeviceSectorSize(MountDevice
, &SectorSize
)) &&
75 (FsRecGetDeviceSectors(MountDevice
, SectorSize
, &SectorCount
)))
77 /* Setup other offsets to try */
78 Offset2
.QuadPart
= SectorCount
.QuadPart
>> 1;
79 Offset2
.QuadPart
*= SectorSize
;
80 Offset3
.QuadPart
= (SectorCount
.QuadPart
- 1) * SectorSize
;
82 /* Try to read the BPB */
83 if (FsRecReadBlock(MountDevice
,
90 /* Check if it's an actual NTFS volume */
91 if (FsRecIsNtfsVolume(Bpb
, SectorSize
, &SectorCount
))
94 Status
= STATUS_FS_DRIVER_REQUIRED
;
97 else if (FsRecReadBlock(MountDevice
,
104 /* Check if it's an actual NTFS volume */
105 if (FsRecIsNtfsVolume(Bpb
, SectorSize
, &SectorCount
))
108 Status
= STATUS_FS_DRIVER_REQUIRED
;
111 else if (FsRecReadBlock(MountDevice
,
118 /* Check if it's an actual NTFS volume */
119 if (FsRecIsNtfsVolume(Bpb
, SectorSize
, &SectorCount
))
122 Status
= STATUS_FS_DRIVER_REQUIRED
;
126 /* Free the boot sector if we have one */
131 case IRP_MN_LOAD_FILE_SYSTEM
:
133 /* Load the file system */
134 Status
= FsRecLoadFileSystem(DeviceObject
,
135 L
"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\Ntfs");
140 /* Invalid request */
141 Status
= STATUS_INVALID_DEVICE_REQUEST
;