2005-09-04 21:14:54 +00:00
|
|
|
/*
|
2002-05-15 09:42:19 +00:00
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
2007-04-05 00:11:35 +00:00
|
|
|
* PROJECT: ReactOS File System Recognizer
|
|
|
|
* FILE: drivers/filesystems/fs_rec/ntfs.c
|
|
|
|
* PURPOSE: NTFS Recognizer
|
|
|
|
* PROGRAMMER: Alex Ionescu (alex.ionescu@reactos.org)
|
|
|
|
* Eric Kohl
|
2002-05-15 09:42:19 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* INCLUDES *****************************************************************/
|
|
|
|
|
2007-04-05 00:11:35 +00:00
|
|
|
#include "fs_rec.h"
|
2002-05-15 18:05:00 +00:00
|
|
|
#define NDEBUG
|
2002-05-15 09:42:19 +00:00
|
|
|
#include <debug.h>
|
|
|
|
|
|
|
|
/* FUNCTIONS ****************************************************************/
|
|
|
|
|
2007-04-05 00:11:35 +00:00
|
|
|
BOOLEAN
|
|
|
|
NTAPI
|
|
|
|
FsRecIsNtfsVolume(IN PPACKED_BOOT_SECTOR BootSector,
|
|
|
|
IN ULONG BytesPerSector,
|
|
|
|
IN PLARGE_INTEGER NumberOfSectors)
|
2002-05-15 18:05:00 +00:00
|
|
|
{
|
2007-11-21 09:18:32 +00:00
|
|
|
/* Assume failure */
|
2007-11-21 15:40:41 +00:00
|
|
|
BOOLEAN Result = FALSE;
|
|
|
|
|
|
|
|
PAGED_CODE();
|
2007-04-05 00:11:35 +00:00
|
|
|
|
|
|
|
if ((BootSector->Oem[0] == 'N') &&
|
|
|
|
(BootSector->Oem[1] == 'T') &&
|
|
|
|
(BootSector->Oem[2] == 'F') &&
|
|
|
|
(BootSector->Oem[3] == 'S') &&
|
|
|
|
(BootSector->Oem[4] == ' ') &&
|
|
|
|
(BootSector->Oem[5] == ' ') &&
|
|
|
|
(BootSector->Oem[6] == ' ') &&
|
|
|
|
(BootSector->Oem[7] == ' '))
|
2002-05-15 18:05:00 +00:00
|
|
|
{
|
2007-11-21 09:18:32 +00:00
|
|
|
/* Success */
|
|
|
|
Result = TRUE;
|
2002-05-15 18:05:00 +00:00
|
|
|
}
|
|
|
|
|
2007-04-05 00:11:35 +00:00
|
|
|
/* Return the result */
|
|
|
|
return Result;
|
2002-05-15 18:05:00 +00:00
|
|
|
}
|
|
|
|
|
2002-05-15 09:42:19 +00:00
|
|
|
NTSTATUS
|
2007-04-05 00:11:35 +00:00
|
|
|
NTAPI
|
2002-05-15 09:42:19 +00:00
|
|
|
FsRecNtfsFsControl(IN PDEVICE_OBJECT DeviceObject,
|
2007-04-05 00:11:35 +00:00
|
|
|
IN PIRP Irp)
|
2002-05-15 09:42:19 +00:00
|
|
|
{
|
2007-04-05 00:11:35 +00:00
|
|
|
PIO_STACK_LOCATION Stack;
|
|
|
|
NTSTATUS Status;
|
|
|
|
PDEVICE_OBJECT MountDevice;
|
|
|
|
PPACKED_BOOT_SECTOR Bpb = NULL;
|
|
|
|
ULONG SectorSize;
|
2008-12-03 17:29:38 +00:00
|
|
|
LARGE_INTEGER Offset = {{0, 0}}, Offset2, Offset3, SectorCount;
|
2007-04-05 00:11:35 +00:00
|
|
|
PAGED_CODE();
|
|
|
|
|
|
|
|
/* Get the I/O Stack and check the function type */
|
|
|
|
Stack = IoGetCurrentIrpStackLocation(Irp);
|
|
|
|
switch (Stack->MinorFunction)
|
2002-05-15 09:42:19 +00:00
|
|
|
{
|
2007-04-05 00:11:35 +00:00
|
|
|
case IRP_MN_MOUNT_VOLUME:
|
|
|
|
|
|
|
|
/* Assume failure */
|
|
|
|
Status = STATUS_UNRECOGNIZED_VOLUME;
|
|
|
|
|
|
|
|
/* Get the device object and request the sector size */
|
|
|
|
MountDevice = Stack->Parameters.MountVolume.DeviceObject;
|
|
|
|
if ((FsRecGetDeviceSectorSize(MountDevice, &SectorSize)) &&
|
|
|
|
(FsRecGetDeviceSectors(MountDevice, SectorSize, &SectorCount)))
|
|
|
|
{
|
|
|
|
/* Setup other offsets to try */
|
|
|
|
Offset2.QuadPart = SectorCount.QuadPart >> 1;
|
|
|
|
Offset2.QuadPart *= SectorSize;
|
|
|
|
Offset3.QuadPart = (SectorCount.QuadPart - 1) * SectorSize;
|
|
|
|
|
|
|
|
/* Try to read the BPB */
|
|
|
|
if (FsRecReadBlock(MountDevice,
|
|
|
|
&Offset,
|
|
|
|
512,
|
|
|
|
SectorSize,
|
|
|
|
(PVOID)&Bpb,
|
|
|
|
NULL))
|
|
|
|
{
|
2007-11-21 09:18:32 +00:00
|
|
|
/* Check if it's an actual NTFS volume */
|
2007-04-05 00:11:35 +00:00
|
|
|
if (FsRecIsNtfsVolume(Bpb, SectorSize, &SectorCount))
|
|
|
|
{
|
|
|
|
/* It is! */
|
|
|
|
Status = STATUS_FS_DRIVER_REQUIRED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (FsRecReadBlock(MountDevice,
|
|
|
|
&Offset2,
|
|
|
|
512,
|
|
|
|
SectorSize,
|
|
|
|
(PVOID)&Bpb,
|
|
|
|
NULL))
|
|
|
|
{
|
2007-11-21 09:18:32 +00:00
|
|
|
/* Check if it's an actual NTFS volume */
|
2007-04-05 00:11:35 +00:00
|
|
|
if (FsRecIsNtfsVolume(Bpb, SectorSize, &SectorCount))
|
|
|
|
{
|
|
|
|
/* It is! */
|
|
|
|
Status = STATUS_FS_DRIVER_REQUIRED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (FsRecReadBlock(MountDevice,
|
|
|
|
&Offset3,
|
|
|
|
512,
|
|
|
|
SectorSize,
|
|
|
|
(PVOID)&Bpb,
|
|
|
|
NULL))
|
|
|
|
{
|
2007-11-21 09:18:32 +00:00
|
|
|
/* Check if it's an actual NTFS volume */
|
2007-04-05 00:11:35 +00:00
|
|
|
if (FsRecIsNtfsVolume(Bpb, SectorSize, &SectorCount))
|
|
|
|
{
|
|
|
|
/* It is! */
|
|
|
|
Status = STATUS_FS_DRIVER_REQUIRED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Free the boot sector if we have one */
|
|
|
|
ExFreePool(Bpb);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IRP_MN_LOAD_FILE_SYSTEM:
|
|
|
|
|
|
|
|
/* Load the file system */
|
|
|
|
Status = FsRecLoadFileSystem(DeviceObject,
|
|
|
|
L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\Ntfs");
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
/* Invalid request */
|
|
|
|
Status = STATUS_INVALID_DEVICE_REQUEST;
|
2002-05-15 09:42:19 +00:00
|
|
|
}
|
2007-04-05 00:11:35 +00:00
|
|
|
|
|
|
|
/* Return Status */
|
|
|
|
return Status;
|
2002-05-15 09:42:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* EOF */
|