mirror of
https://github.com/reactos/reactos.git
synced 2025-04-20 12:29:56 +00:00
Fixed typos
Added more safety checks Minor cleanup svn path=/trunk/; revision=1662
This commit is contained in:
parent
de10767975
commit
2d5f3d1c74
2 changed files with 245 additions and 174 deletions
|
@ -37,7 +37,7 @@ VfatReadSectors (IN PDEVICE_OBJECT pDeviceObject,
|
||||||
KeInitializeEvent (&event, NotificationEvent, FALSE);
|
KeInitializeEvent (&event, NotificationEvent, FALSE);
|
||||||
sectorSize = BLOCKSIZE * SectorCount;
|
sectorSize = BLOCKSIZE * SectorCount;
|
||||||
|
|
||||||
DPRINT ("VFATReadSector(pDeviceObject %x, DiskSector %d, Buffer %x)\n",
|
DPRINT ("VfatReadSectors(pDeviceObject %x, DiskSector %d, Buffer %x)\n",
|
||||||
pDeviceObject, DiskSector, Buffer);
|
pDeviceObject, DiskSector, Buffer);
|
||||||
DPRINT ("sectorNumber %08lx:%08lx sectorSize %ld\n",
|
DPRINT ("sectorNumber %08lx:%08lx sectorSize %ld\n",
|
||||||
(unsigned long int) sectorNumber.u.LowPart,
|
(unsigned long int) sectorNumber.u.LowPart,
|
||||||
|
@ -56,7 +56,7 @@ VfatReadSectors (IN PDEVICE_OBJECT pDeviceObject,
|
||||||
if (Irp == NULL)
|
if (Irp == NULL)
|
||||||
{
|
{
|
||||||
DPRINT("IoBuildSynchronousFsdRequest failed\n");
|
DPRINT("IoBuildSynchronousFsdRequest failed\n");
|
||||||
return(STATUS_UNSUCCESSFUL);;
|
return(STATUS_UNSUCCESSFUL);
|
||||||
}
|
}
|
||||||
|
|
||||||
DPRINT ("Calling IO Driver... with irp %x\n", Irp);
|
DPRINT ("Calling IO Driver... with irp %x\n", Irp);
|
||||||
|
@ -73,7 +73,7 @@ VfatReadSectors (IN PDEVICE_OBJECT pDeviceObject,
|
||||||
|
|
||||||
if (!NT_SUCCESS (Status))
|
if (!NT_SUCCESS (Status))
|
||||||
{
|
{
|
||||||
DPRINT ("IO failed!!! VFATREadSectors : Error code: %x\n", Status);
|
DPRINT ("IO failed!!! VfatReadSectors : Error code: %x\n", Status);
|
||||||
DPRINT ("(pDeviceObject %x, DiskSector %x, Buffer %x, offset 0x%x%x)\n",
|
DPRINT ("(pDeviceObject %x, DiskSector %x, Buffer %x, offset 0x%x%x)\n",
|
||||||
pDeviceObject, DiskSector, Buffer, sectorNumber.u.HighPart,
|
pDeviceObject, DiskSector, Buffer, sectorNumber.u.HighPart,
|
||||||
sectorNumber.u.LowPart);
|
sectorNumber.u.LowPart);
|
||||||
|
@ -96,7 +96,7 @@ VfatWriteSectors (IN PDEVICE_OBJECT pDeviceObject,
|
||||||
NTSTATUS Status;
|
NTSTATUS Status;
|
||||||
ULONG sectorSize;
|
ULONG sectorSize;
|
||||||
|
|
||||||
DPRINT ("VFATWriteSector(pDeviceObject %x, DiskSector %d, Buffer %x)\n",
|
DPRINT ("VfatWriteSectors(pDeviceObject %x, DiskSector %d, Buffer %x)\n",
|
||||||
pDeviceObject, DiskSector, Buffer);
|
pDeviceObject, DiskSector, Buffer);
|
||||||
|
|
||||||
sectorNumber.u.LowPart = DiskSector << 9;
|
sectorNumber.u.LowPart = DiskSector << 9;
|
||||||
|
@ -134,7 +134,7 @@ VfatWriteSectors (IN PDEVICE_OBJECT pDeviceObject,
|
||||||
|
|
||||||
if (!NT_SUCCESS (Status))
|
if (!NT_SUCCESS (Status))
|
||||||
{
|
{
|
||||||
DPRINT1 ("IO failed!!! VFATWriteSectors : Error code: %x\n", Status);
|
DPRINT1 ("IO failed!!! VfatWriteSectors : Error code: %x\n", Status);
|
||||||
return (Status);
|
return (Status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $Id: iface.c,v 1.49 2001/01/16 09:55:02 dwelch Exp $
|
/* $Id: iface.c,v 1.50 2001/03/06 08:19:58 ekohl Exp $
|
||||||
*
|
*
|
||||||
* COPYRIGHT: See COPYING in the top level directory
|
* COPYRIGHT: See COPYING in the top level directory
|
||||||
* PROJECT: ReactOS kernel
|
* PROJECT: ReactOS kernel
|
||||||
|
@ -27,7 +27,6 @@
|
||||||
/* INCLUDES *****************************************************************/
|
/* INCLUDES *****************************************************************/
|
||||||
|
|
||||||
#include <ddk/ntddk.h>
|
#include <ddk/ntddk.h>
|
||||||
#include <wchar.h>
|
|
||||||
|
|
||||||
#define NDEBUG
|
#define NDEBUG
|
||||||
#include <debug.h>
|
#include <debug.h>
|
||||||
|
@ -40,44 +39,61 @@ static PDRIVER_OBJECT VfatDriverObject;
|
||||||
|
|
||||||
/* FUNCTIONS ****************************************************************/
|
/* FUNCTIONS ****************************************************************/
|
||||||
|
|
||||||
BOOLEAN
|
static NTSTATUS
|
||||||
VfatHasFileSystem (PDEVICE_OBJECT DeviceToMount)
|
VfatHasFileSystem(PDEVICE_OBJECT DeviceToMount,
|
||||||
|
PBOOLEAN RecognizedFS)
|
||||||
/*
|
/*
|
||||||
* FUNCTION: Tests if the device contains a filesystem that can be mounted
|
* FUNCTION: Tests if the device contains a filesystem that can be mounted
|
||||||
* by this fsd
|
* by this fsd
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
BootSector *Boot;
|
BootSector *Boot;
|
||||||
|
NTSTATUS Status;
|
||||||
|
|
||||||
Boot = ExAllocatePool(NonPagedPool, 512);
|
Boot = ExAllocatePool(NonPagedPool, 512);
|
||||||
|
|
||||||
/* FIXME: Check status */
|
Status = VfatReadSectors(DeviceToMount, 0, 1, (UCHAR *) Boot);
|
||||||
VfatReadSectors (DeviceToMount, 0, 1, (UCHAR *) Boot);
|
if (!NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
|
||||||
DPRINT("Boot->SysType %.5s\n", Boot->SysType);
|
DPRINT("Boot->SysType %.5s\n", Boot->SysType);
|
||||||
if (strncmp(Boot->SysType, "FAT12", 5) == 0 ||
|
if (strncmp(Boot->SysType, "FAT12", 5) == 0 ||
|
||||||
strncmp(Boot->SysType, "FAT16", 5) == 0 ||
|
strncmp(Boot->SysType, "FAT16", 5) == 0 ||
|
||||||
strncmp(((struct _BootSector32 *) (Boot))->SysType, "FAT32", 5) == 0)
|
strncmp(((struct _BootSector32 *) (Boot))->SysType, "FAT32", 5) == 0)
|
||||||
{
|
{
|
||||||
ExFreePool (Boot);
|
*RecognizedFS = TRUE;
|
||||||
return (TRUE);
|
|
||||||
}
|
}
|
||||||
ExFreePool (Boot);
|
else
|
||||||
return (FALSE);
|
{
|
||||||
|
*RecognizedFS = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
NTSTATUS
|
ExFreePool(Boot);
|
||||||
|
|
||||||
|
return STATUS_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static NTSTATUS
|
||||||
VfatMountDevice (PDEVICE_EXTENSION DeviceExt, PDEVICE_OBJECT DeviceToMount)
|
VfatMountDevice (PDEVICE_EXTENSION DeviceExt, PDEVICE_OBJECT DeviceToMount)
|
||||||
/*
|
/*
|
||||||
* FUNCTION: Mounts the device
|
* FUNCTION: Mounts the device
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
|
NTSTATUS Status;
|
||||||
|
|
||||||
DPRINT("Mounting VFAT device...");
|
DPRINT("Mounting VFAT device...");
|
||||||
DPRINT("DeviceExt %x\n", DeviceExt);
|
DPRINT("DeviceExt %x\n", DeviceExt);
|
||||||
|
|
||||||
DeviceExt->Boot = ExAllocatePool(NonPagedPool, 512);
|
DeviceExt->Boot = ExAllocatePool(NonPagedPool, 512);
|
||||||
/* FIXME: Check status */
|
|
||||||
VfatReadSectors (DeviceToMount, 0, 1, (UCHAR *) DeviceExt->Boot);
|
Status = VfatReadSectors(DeviceToMount, 0, 1, (UCHAR *) DeviceExt->Boot);
|
||||||
|
if (!NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
|
||||||
DeviceExt->FATStart = DeviceExt->Boot->ReservedSectors;
|
DeviceExt->FATStart = DeviceExt->Boot->ReservedSectors;
|
||||||
DeviceExt->rootDirectorySectors =
|
DeviceExt->rootDirectorySectors =
|
||||||
|
@ -109,8 +125,7 @@ VfatMountDevice (PDEVICE_EXTENSION DeviceExt, PDEVICE_OBJECT DeviceToMount)
|
||||||
DbgPrint("FAT12\n");
|
DbgPrint("FAT12\n");
|
||||||
DeviceExt->FatType = FAT12;
|
DeviceExt->FatType = FAT12;
|
||||||
}
|
}
|
||||||
else
|
else if (strncmp
|
||||||
if (strncmp
|
|
||||||
(((struct _BootSector32 *) (DeviceExt->Boot))->SysType, "FAT32",
|
(((struct _BootSector32 *) (DeviceExt->Boot))->SysType, "FAT32",
|
||||||
5) == 0)
|
5) == 0)
|
||||||
{
|
{
|
||||||
|
@ -131,7 +146,8 @@ VfatMountDevice (PDEVICE_EXTENSION DeviceExt, PDEVICE_OBJECT DeviceToMount)
|
||||||
return STATUS_SUCCESS;
|
return STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
NTSTATUS
|
|
||||||
|
static NTSTATUS
|
||||||
VfatMount (PDEVICE_OBJECT DeviceToMount)
|
VfatMount (PDEVICE_OBJECT DeviceToMount)
|
||||||
/*
|
/*
|
||||||
* FUNCTION: Mount the filesystem
|
* FUNCTION: Mount the filesystem
|
||||||
|
@ -139,24 +155,60 @@ VfatMount (PDEVICE_OBJECT DeviceToMount)
|
||||||
{
|
{
|
||||||
PDEVICE_OBJECT DeviceObject;
|
PDEVICE_OBJECT DeviceObject;
|
||||||
PDEVICE_EXTENSION DeviceExt;
|
PDEVICE_EXTENSION DeviceExt;
|
||||||
|
BOOLEAN RecognizedFS;
|
||||||
NTSTATUS Status;
|
NTSTATUS Status;
|
||||||
|
|
||||||
IoCreateDevice (VfatDriverObject,
|
Status = VfatHasFileSystem (DeviceToMount, &RecognizedFS);
|
||||||
|
if (!NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (RecognizedFS == FALSE)
|
||||||
|
{
|
||||||
|
DPRINT("VFAT: Unrecognized Volume\n");
|
||||||
|
return STATUS_UNRECOGNIZED_VOLUME;
|
||||||
|
}
|
||||||
|
|
||||||
|
DPRINT("VFAT: Recognized volume\n");
|
||||||
|
|
||||||
|
Status = IoCreateDevice(VfatDriverObject,
|
||||||
sizeof (DEVICE_EXTENSION),
|
sizeof (DEVICE_EXTENSION),
|
||||||
NULL, FILE_DEVICE_FILE_SYSTEM, 0, FALSE, &DeviceObject);
|
NULL,
|
||||||
|
FILE_DEVICE_FILE_SYSTEM,
|
||||||
|
0,
|
||||||
|
FALSE,
|
||||||
|
&DeviceObject);
|
||||||
|
if (!NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
|
||||||
DeviceObject->Flags = DeviceObject->Flags | DO_DIRECT_IO;
|
DeviceObject->Flags = DeviceObject->Flags | DO_DIRECT_IO;
|
||||||
DeviceExt = (PVOID) DeviceObject->DeviceExtension;
|
DeviceExt = (PVOID) DeviceObject->DeviceExtension;
|
||||||
// use same vpb as device disk
|
/* use same vpb as device disk */
|
||||||
DeviceObject->Vpb = DeviceToMount->Vpb;
|
DeviceObject->Vpb = DeviceToMount->Vpb;
|
||||||
VfatMountDevice (DeviceExt, DeviceToMount);
|
Status = VfatMountDevice (DeviceExt, DeviceToMount);
|
||||||
|
if (!NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
/* FIXME: delete device object */
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
|
||||||
DeviceObject->Vpb->Flags |= VPB_MOUNTED;
|
DeviceObject->Vpb->Flags |= VPB_MOUNTED;
|
||||||
DeviceExt->StorageDevice = IoAttachDeviceToDeviceStack(DeviceObject,
|
DeviceExt->StorageDevice = IoAttachDeviceToDeviceStack(DeviceObject,
|
||||||
DeviceToMount);
|
DeviceToMount);
|
||||||
DeviceExt->StreamStorageDevice =
|
DeviceExt->StreamStorageDevice = IoCreateStreamFileObject(NULL,
|
||||||
IoCreateStreamFileObject(NULL, DeviceExt->StorageDevice);
|
DeviceExt->StorageDevice);
|
||||||
Status = CcInitializeFileCache(DeviceExt->StreamStorageDevice,
|
Status = CcInitializeFileCache(DeviceExt->StreamStorageDevice,
|
||||||
&DeviceExt->StorageBcb,
|
&DeviceExt->StorageBcb,
|
||||||
PAGESIZE);
|
PAGESIZE);
|
||||||
|
if (!NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
/* FIXME: delete device object */
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
|
||||||
if (DeviceExt->FatType == FAT12)
|
if (DeviceExt->FatType == FAT12)
|
||||||
{
|
{
|
||||||
DeviceExt->Fat12StorageDevice =
|
DeviceExt->Fat12StorageDevice =
|
||||||
|
@ -164,6 +216,11 @@ VfatMount (PDEVICE_OBJECT DeviceToMount)
|
||||||
Status = CcInitializeFileCache(DeviceExt->Fat12StorageDevice,
|
Status = CcInitializeFileCache(DeviceExt->Fat12StorageDevice,
|
||||||
&DeviceExt->Fat12StorageBcb,
|
&DeviceExt->Fat12StorageBcb,
|
||||||
PAGESIZE * 3);
|
PAGESIZE * 3);
|
||||||
|
if (!NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
/* FIXME: delete device object */
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ExInitializeResourceLite (&DeviceExt->DirResource);
|
ExInitializeResourceLite (&DeviceExt->DirResource);
|
||||||
ExInitializeResourceLite (&DeviceExt->FatResource);
|
ExInitializeResourceLite (&DeviceExt->FatResource);
|
||||||
|
@ -182,9 +239,10 @@ VfatMount (PDEVICE_OBJECT DeviceToMount)
|
||||||
/* read volume label */
|
/* read volume label */
|
||||||
ReadVolumeLabel(DeviceExt, DeviceObject->Vpb);
|
ReadVolumeLabel(DeviceExt, DeviceObject->Vpb);
|
||||||
|
|
||||||
return (STATUS_SUCCESS);
|
return STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
NTSTATUS STDCALL
|
NTSTATUS STDCALL
|
||||||
VfatFileSystemControl (PDEVICE_OBJECT DeviceObject, PIRP Irp)
|
VfatFileSystemControl (PDEVICE_OBJECT DeviceObject, PIRP Irp)
|
||||||
/*
|
/*
|
||||||
|
@ -192,24 +250,28 @@ VfatFileSystemControl (PDEVICE_OBJECT DeviceObject, PIRP Irp)
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
PIO_STACK_LOCATION Stack = IoGetCurrentIrpStackLocation (Irp);
|
PIO_STACK_LOCATION Stack = IoGetCurrentIrpStackLocation (Irp);
|
||||||
// PVPB vpb = Stack->Parameters.Mount.Vpb;
|
|
||||||
PDEVICE_OBJECT DeviceToMount = Stack->Parameters.Mount.DeviceObject;
|
|
||||||
NTSTATUS Status;
|
NTSTATUS Status;
|
||||||
|
|
||||||
// DPRINT("VFAT FSC\n");
|
switch (Stack->MinorFunction)
|
||||||
DbgPrint ("VFAT FSC\n");
|
|
||||||
|
|
||||||
/* FIXME: should make sure that this is actually a mount request! */
|
|
||||||
|
|
||||||
if (VfatHasFileSystem (DeviceToMount))
|
|
||||||
{
|
{
|
||||||
DPRINT ("VFAT: Recognized volume\n");
|
case IRP_MN_USER_FS_REQUEST:
|
||||||
Status = VfatMount (DeviceToMount);
|
DPRINT1("VFAT FSC: IRP_MN_USER_FS_REQUEST\n");
|
||||||
}
|
Status = STATUS_INVALID_DEVICE_REQUEST;
|
||||||
else
|
break;
|
||||||
{
|
|
||||||
DPRINT ("VFAT: Unrecognized Volume\n");
|
case IRP_MN_MOUNT_VOLUME:
|
||||||
Status = STATUS_UNRECOGNIZED_VOLUME;
|
Status = VfatMount(Stack->Parameters.Mount.DeviceObject);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case IRP_MN_VERIFY_VOLUME:
|
||||||
|
DPRINT1("VFAT FSC: IRP_MN_VERIFY_VOLUME\n");
|
||||||
|
Status = STATUS_INVALID_DEVICE_REQUEST;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
DPRINT1("VFAT FSC: MinorFunction %d\n", Stack->MinorFunction);
|
||||||
|
Status = STATUS_INVALID_DEVICE_REQUEST;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
Irp->IoStatus.Status = Status;
|
Irp->IoStatus.Status = Status;
|
||||||
|
@ -219,6 +281,7 @@ VfatFileSystemControl (PDEVICE_OBJECT DeviceObject, PIRP Irp)
|
||||||
return (Status);
|
return (Status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
NTSTATUS STDCALL
|
NTSTATUS STDCALL
|
||||||
DriverEntry (PDRIVER_OBJECT _DriverObject, PUNICODE_STRING RegistryPath)
|
DriverEntry (PDRIVER_OBJECT _DriverObject, PUNICODE_STRING RegistryPath)
|
||||||
/*
|
/*
|
||||||
|
@ -230,19 +293,25 @@ DriverEntry (PDRIVER_OBJECT _DriverObject, PUNICODE_STRING RegistryPath)
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
PDEVICE_OBJECT DeviceObject;
|
PDEVICE_OBJECT DeviceObject;
|
||||||
NTSTATUS ret;
|
|
||||||
UNICODE_STRING DeviceName;
|
UNICODE_STRING DeviceName;
|
||||||
|
NTSTATUS Status;
|
||||||
|
|
||||||
DbgPrint("VFAT 0.0.6\n");
|
DbgPrint("VFAT 0.0.6\n");
|
||||||
|
|
||||||
VfatDriverObject = _DriverObject;
|
VfatDriverObject = _DriverObject;
|
||||||
|
|
||||||
RtlInitUnicodeString (&DeviceName, L"\\Device\\Vfat");
|
RtlInitUnicodeString(&DeviceName,
|
||||||
ret = IoCreateDevice (VfatDriverObject, 0, &DeviceName,
|
L"\\Device\\Vfat");
|
||||||
FILE_DEVICE_FILE_SYSTEM, 0, FALSE, &DeviceObject);
|
Status = IoCreateDevice(VfatDriverObject,
|
||||||
if (ret != STATUS_SUCCESS)
|
0,
|
||||||
|
&DeviceName,
|
||||||
|
FILE_DEVICE_FILE_SYSTEM,
|
||||||
|
0,
|
||||||
|
FALSE,
|
||||||
|
&DeviceObject);
|
||||||
|
if (!NT_SUCCESS(Status))
|
||||||
{
|
{
|
||||||
return (ret);
|
return (Status);
|
||||||
}
|
}
|
||||||
|
|
||||||
DeviceObject->Flags = DO_DIRECT_IO;
|
DeviceObject->Flags = DO_DIRECT_IO;
|
||||||
|
@ -266,5 +335,7 @@ DriverEntry (PDRIVER_OBJECT _DriverObject, PUNICODE_STRING RegistryPath)
|
||||||
|
|
||||||
IoRegisterFileSystem(DeviceObject);
|
IoRegisterFileSystem(DeviceObject);
|
||||||
|
|
||||||
return (STATUS_SUCCESS);
|
return STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* EOF */
|
||||||
|
|
Loading…
Reference in a new issue