2005-01-13 02:39:38 +00:00
|
|
|
/*
|
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
2008-02-11 16:41:25 +00:00
|
|
|
* PROJECT: ReactOS File System Recognizer
|
|
|
|
* FILE: drivers/filesystems/fs_rec/ext2.c
|
|
|
|
* PURPOSE: EXT2 Recognizer
|
2005-01-13 02:39:38 +00:00
|
|
|
* PROGRAMMER: Eric Kohl
|
2015-10-17 22:39:13 +00:00
|
|
|
* Pierre Schweitzer (pierre@reactos.org)
|
2005-01-13 02:39:38 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* INCLUDES *****************************************************************/
|
|
|
|
|
2008-02-11 16:41:25 +00:00
|
|
|
#include "fs_rec.h"
|
2015-10-17 22:39:13 +00:00
|
|
|
#include "ext2.h"
|
2014-02-06 10:59:19 +00:00
|
|
|
|
2005-01-13 02:39:38 +00:00
|
|
|
#define NDEBUG
|
|
|
|
#include <debug.h>
|
|
|
|
|
|
|
|
/* FUNCTIONS ****************************************************************/
|
|
|
|
|
2008-02-11 16:41:25 +00:00
|
|
|
BOOLEAN
|
|
|
|
NTAPI
|
2015-10-17 22:39:13 +00:00
|
|
|
FsRecIsExt2Volume(IN PEXT2_SUPER_BLOCK SuperBlock)
|
2005-01-13 02:39:38 +00:00
|
|
|
{
|
2015-10-17 22:39:13 +00:00
|
|
|
/* Just check for magic */
|
|
|
|
return (SuperBlock->Magic == EXT2_SUPER_MAGIC);
|
2005-01-13 02:39:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS
|
2008-02-11 16:41:25 +00:00
|
|
|
NTAPI
|
2005-01-13 02:39:38 +00:00
|
|
|
FsRecExt2FsControl(IN PDEVICE_OBJECT DeviceObject,
|
2008-02-11 16:41:25 +00:00
|
|
|
IN PIRP Irp)
|
2005-01-13 02:39:38 +00:00
|
|
|
{
|
2008-02-11 16:41:25 +00:00
|
|
|
PIO_STACK_LOCATION Stack;
|
|
|
|
NTSTATUS Status;
|
|
|
|
PDEVICE_OBJECT MountDevice;
|
2015-10-17 22:39:13 +00:00
|
|
|
PEXT2_SUPER_BLOCK Spb = NULL;
|
2008-02-11 16:41:25 +00:00
|
|
|
ULONG SectorSize;
|
2015-10-17 22:39:13 +00:00
|
|
|
LARGE_INTEGER Offset;
|
2008-02-11 16:41:25 +00:00
|
|
|
BOOLEAN DeviceError = FALSE;
|
|
|
|
PAGED_CODE();
|
|
|
|
|
|
|
|
/* Get the I/O Stack and check the function type */
|
|
|
|
Stack = IoGetCurrentIrpStackLocation(Irp);
|
|
|
|
switch (Stack->MinorFunction)
|
2005-01-13 02:39:38 +00:00
|
|
|
{
|
2008-02-11 16:41:25 +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))
|
|
|
|
{
|
2015-10-17 22:39:13 +00:00
|
|
|
/* Try to read the superblock */
|
2016-02-28 11:27:05 +00:00
|
|
|
Offset.QuadPart = EXT2_SB_OFFSET;
|
2008-02-11 16:41:25 +00:00
|
|
|
if (FsRecReadBlock(MountDevice,
|
|
|
|
&Offset,
|
2016-02-28 11:27:05 +00:00
|
|
|
EXT2_SB_SIZE,
|
2008-02-11 16:41:25 +00:00
|
|
|
SectorSize,
|
2015-10-17 22:39:13 +00:00
|
|
|
(PVOID)&Spb,
|
2008-02-11 16:41:25 +00:00
|
|
|
&DeviceError))
|
|
|
|
{
|
|
|
|
/* Check if it's an actual EXT2 volume */
|
2015-10-17 22:39:13 +00:00
|
|
|
if (FsRecIsExt2Volume(Spb))
|
2008-02-11 16:41:25 +00:00
|
|
|
{
|
|
|
|
/* It is! */
|
|
|
|
Status = STATUS_FS_DRIVER_REQUIRED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Free the boot sector if we have one */
|
2015-10-17 22:39:13 +00:00
|
|
|
ExFreePool(Spb);
|
2008-02-11 16:41:25 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* We have some sort of failure in the storage stack */
|
|
|
|
DeviceError = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if we have an error on the stack */
|
|
|
|
if (DeviceError)
|
|
|
|
{
|
|
|
|
/* Was this because of a floppy? */
|
|
|
|
if (MountDevice->Characteristics & FILE_FLOPPY_DISKETTE)
|
|
|
|
{
|
|
|
|
/* Let the FS try anyway */
|
|
|
|
Status = STATUS_FS_DRIVER_REQUIRED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IRP_MN_LOAD_FILE_SYSTEM:
|
|
|
|
|
|
|
|
/* Load the file system */
|
|
|
|
Status = FsRecLoadFileSystem(DeviceObject,
|
2014-02-25 03:39:23 +00:00
|
|
|
L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\Ext2fs");
|
2008-02-11 16:41:25 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
/* Invalid request */
|
|
|
|
Status = STATUS_INVALID_DEVICE_REQUEST;
|
2005-01-13 02:39:38 +00:00
|
|
|
}
|
2008-02-11 16:41:25 +00:00
|
|
|
|
|
|
|
/* Return Status */
|
|
|
|
return Status;
|
2005-01-13 02:39:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* EOF */
|