From ae5018a9dd3409c0ee4986e76f88968570f194fe Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Sun, 19 Jun 2011 20:03:49 +0000 Subject: [PATCH] [FASTFAT] - Move verification code to the BlockDev* functions (like CDFS does) so functions that call those directly will have verification handled for them - Add verification handling for IOCTL requests svn path=/trunk/; revision=52374 --- .../drivers/filesystems/fastfat/blockdev.c | 84 +++++++++++++++++++ reactos/drivers/filesystems/fastfat/create.c | 14 ---- reactos/drivers/filesystems/fastfat/rw.c | 29 ------- 3 files changed, 84 insertions(+), 43 deletions(-) diff --git a/reactos/drivers/filesystems/fastfat/blockdev.c b/reactos/drivers/filesystems/fastfat/blockdev.c index f0ff0598c2e..b3d3a0e39d8 100644 --- a/reactos/drivers/filesystems/fastfat/blockdev.c +++ b/reactos/drivers/filesystems/fastfat/blockdev.c @@ -38,6 +38,10 @@ VfatReadWritePartialCompletion (IN PDEVICE_OBJECT DeviceObject, { IrpContext->Flags |= IRPCONTEXT_PENDINGRETURNED; } + else + { + IrpContext->Flags &= ~IRPCONTEXT_PENDINGRETURNED; + } if (!NT_SUCCESS(Irp->IoStatus.Status)) { IrpContext->Irp->IoStatus.Status = Irp->IoStatus.Status; @@ -67,6 +71,7 @@ VfatReadDisk (IN PDEVICE_OBJECT pDeviceObject, KEVENT event; NTSTATUS Status; +again: KeInitializeEvent (&event, NotificationEvent, FALSE); DPRINT ("VfatReadDisk(pDeviceObject %p, Offset %I64x, Length %d, Buffer %p)\n", @@ -104,6 +109,25 @@ VfatReadDisk (IN PDEVICE_OBJECT pDeviceObject, Status = IoStatus.Status; } + if (Status == STATUS_VERIFY_REQUIRED) + { + PDEVICE_OBJECT DeviceToVerify; + + DPRINT1 ("Media change detected!\n"); + + /* Find the device to verify and reset the thread field to empty value again. */ + DeviceToVerify = IoGetDeviceToVerify (PsGetCurrentThread ()); + IoSetDeviceToVerify (PsGetCurrentThread (), NULL); + Status = IoVerifyVolume (DeviceToVerify, + FALSE); + + if (NT_SUCCESS(Status)) + { + DPRINT1 ("Volume verification successful; Reissuing read request\n"); + goto again; + } + } + if (!NT_SUCCESS (Status)) { DPRINT ("IO failed!!! VfatReadDisk : Error code: %x\n", Status); @@ -134,6 +158,7 @@ VfatReadDiskPartial (IN PVFAT_IRP_CONTEXT IrpContext, Buffer = (PCHAR)MmGetMdlVirtualAddress(IrpContext->Irp->MdlAddress) + BufferOffset; +again: Irp = IoAllocateIrp(IrpContext->DeviceExt->StorageDevice->StackSize, TRUE); if (Irp == NULL) { @@ -190,6 +215,25 @@ VfatReadDiskPartial (IN PVFAT_IRP_CONTEXT IrpContext, Status = IrpContext->Irp->IoStatus.Status; } + if (Status == STATUS_VERIFY_REQUIRED) + { + PDEVICE_OBJECT DeviceToVerify; + + DPRINT1 ("Media change detected!\n"); + + /* Find the device to verify and reset the thread field to empty value again. */ + DeviceToVerify = IoGetDeviceToVerify (PsGetCurrentThread ()); + IoSetDeviceToVerify (PsGetCurrentThread (), NULL); + Status = IoVerifyVolume (DeviceToVerify, + FALSE); + + if (NT_SUCCESS(Status)) + { + DPRINT1 ("Volume verification successful; Reissuing read request\n"); + goto again; + } + } + DPRINT("%x\n", Status); return Status; } @@ -212,6 +256,7 @@ VfatWriteDiskPartial (IN PVFAT_IRP_CONTEXT IrpContext, Buffer = (PCHAR)MmGetMdlVirtualAddress(IrpContext->Irp->MdlAddress) + BufferOffset; +again: DPRINT ("Building asynchronous FSD Request...\n"); Irp = IoAllocateIrp(IrpContext->DeviceExt->StorageDevice->StackSize, TRUE); if (Irp == NULL) @@ -268,6 +313,25 @@ VfatWriteDiskPartial (IN PVFAT_IRP_CONTEXT IrpContext, Status = IrpContext->Irp->IoStatus.Status; } + if (Status == STATUS_VERIFY_REQUIRED) + { + PDEVICE_OBJECT DeviceToVerify; + + DPRINT1 ("Media change detected!\n"); + + /* Find the device to verify and reset the thread field to empty value again. */ + DeviceToVerify = IoGetDeviceToVerify (PsGetCurrentThread ()); + IoSetDeviceToVerify (PsGetCurrentThread (), NULL); + Status = IoVerifyVolume (DeviceToVerify, + FALSE); + + if (NT_SUCCESS(Status)) + { + DPRINT1 ("Volume verification successful; Reissuing write request\n"); + goto again; + } + } + return Status; } @@ -292,6 +356,7 @@ VfatBlockDeviceIoControl (IN PDEVICE_OBJECT DeviceObject, InputBuffer, InputBufferSize, OutputBuffer, OutputBufferSize, OutputBufferSize ? *OutputBufferSize : 0); +again: KeInitializeEvent (&Event, NotificationEvent, FALSE); DPRINT("Building device I/O control request ...\n"); @@ -328,6 +393,25 @@ VfatBlockDeviceIoControl (IN PDEVICE_OBJECT DeviceObject, Status = IoStatus.Status; } + + if (Status == STATUS_VERIFY_REQUIRED) + { + PDEVICE_OBJECT DeviceToVerify; + + DPRINT1 ("Media change detected!\n"); + + /* Find the device to verify and reset the thread field to empty value again. */ + DeviceToVerify = IoGetDeviceToVerify (PsGetCurrentThread ()); + IoSetDeviceToVerify (PsGetCurrentThread (), NULL); + Status = IoVerifyVolume (DeviceToVerify, + FALSE); + + if (NT_SUCCESS(Status)) + { + DPRINT1 ("Volume verification successful; Reissuing IOCTL request\n"); + goto again; + } + } if (OutputBufferSize) { diff --git a/reactos/drivers/filesystems/fastfat/create.c b/reactos/drivers/filesystems/fastfat/create.c index 1053413d945..864798a0a7a 100644 --- a/reactos/drivers/filesystems/fastfat/create.c +++ b/reactos/drivers/filesystems/fastfat/create.c @@ -372,20 +372,6 @@ VfatOpenFile ( 0, FALSE); - if (Status == STATUS_VERIFY_REQUIRED) - - { - PDEVICE_OBJECT DeviceToVerify; - - DPRINT ("Media change detected!\n"); - DPRINT ("Device %p\n", DeviceExt->StorageDevice); - - /* Find the device to verify and reset the thread field to empty value again. */ - DeviceToVerify = IoGetDeviceToVerify (PsGetCurrentThread ()); - IoSetDeviceToVerify (PsGetCurrentThread (), NULL); - Status = IoVerifyVolume (DeviceToVerify, - FALSE); - } if (!NT_SUCCESS(Status)) { DPRINT ("Status %lx\n", Status); diff --git a/reactos/drivers/filesystems/fastfat/rw.c b/reactos/drivers/filesystems/fastfat/rw.c index 3d395a193b6..5dd906b672a 100644 --- a/reactos/drivers/filesystems/fastfat/rw.c +++ b/reactos/drivers/filesystems/fastfat/rw.c @@ -537,7 +537,6 @@ VfatRead(PVFAT_IRP_CONTEXT IrpContext) PERESOURCE Resource = NULL; LARGE_INTEGER ByteOffset; PVOID Buffer; - PDEVICE_OBJECT DeviceToVerify; ULONG BytesPerSector; ASSERT(IrpContext); @@ -697,20 +696,6 @@ VfatRead(PVFAT_IRP_CONTEXT IrpContext) } Status = VfatReadFileData(IrpContext, Length, ByteOffset, &ReturnedLength); - if (Status == STATUS_VERIFY_REQUIRED) - { - DPRINT("VfatReadFileData returned STATUS_VERIFY_REQUIRED\n"); - DeviceToVerify = IoGetDeviceToVerify(PsGetCurrentThread()); - IoSetDeviceToVerify(PsGetCurrentThread(), NULL); - Status = IoVerifyVolume (DeviceToVerify, FALSE); - - if (NT_SUCCESS(Status)) - { - Status = VfatReadFileData(IrpContext, Length, - ByteOffset, &ReturnedLength); - } - } - if (NT_SUCCESS(Status)) { IrpContext->Irp->IoStatus.Information = ReturnedLength; @@ -767,7 +752,6 @@ NTSTATUS VfatWrite (PVFAT_IRP_CONTEXT IrpContext) ULONG OldAllocationSize; PVOID Buffer; ULONG BytesPerSector; - PDEVICE_OBJECT DeviceToVerify; ASSERT(IrpContext); @@ -989,19 +973,6 @@ NTSTATUS VfatWrite (PVFAT_IRP_CONTEXT IrpContext) } Status = VfatWriteFileData(IrpContext, Length, ByteOffset); - if (Status == STATUS_VERIFY_REQUIRED) - { - DPRINT("VfatWriteFileData returned STATUS_VERIFY_REQUIRED\n"); - DeviceToVerify = IoGetDeviceToVerify(PsGetCurrentThread()); - IoSetDeviceToVerify(PsGetCurrentThread(), NULL); - Status = IoVerifyVolume (DeviceToVerify, FALSE); - - if (NT_SUCCESS(Status)) - { - Status = VfatWriteFileData(IrpContext, Length, ByteOffset); - } - } - if (NT_SUCCESS(Status)) { IrpContext->Irp->IoStatus.Information = Length;