From f69b5f786447b720ca6b3238d318ef8211727fca Mon Sep 17 00:00:00 2001 From: Bill Zissimopoulos Date: Tue, 24 Nov 2015 17:34:02 -0800 Subject: [PATCH] sys: fsctl: WIP --- src/sys/driver.h | 19 ++++++++++++++----- src/sys/fsctl.c | 30 +++++++++++++++++++++++++++++- 2 files changed, 43 insertions(+), 6 deletions(-) diff --git a/src/sys/driver.h b/src/sys/driver.h index 0d60f399..cb2b45b3 100644 --- a/src/sys/driver.h +++ b/src/sys/driver.h @@ -80,11 +80,19 @@ NtStatusSym(Result), \ !NT_SUCCESS(Result) ? 0 : Irp->IoStatus.Information);\ if (STATUS_PENDING == Result) \ - {\ - ASSERT(FspFsvrtDeviceExtensionKind == FspDeviceExtension(DeviceObject)->Kind);\ - FspIoqPostIrp(&FspFsvrtDeviceExtension(DeviceObject)->Ioq, Irp);\ - /* also marks the IRP pending */\ - }\ + { \ + if (0 == (IrpSp->Control & SL_PENDING_RETURNED))\ + { \ + /* if the IRP has not been marked pending already */\ + ASSERT(FspFsvolDeviceExtensionKind == FspDeviceExtension(DeviceObject)->Kind);\ + FSP_FSVOL_DEVICE_EXTENSION *FsvolDeviceExtension =\ + FspFsvolDeviceExtension(DeviceObject);\ + FSP_FSVRT_DEVICE_EXTENSION *FsvrtDeviceExtension =\ + FspFsvrtDeviceExtension(FsvolDeviceExtension->FsvrtDeviceObject);\ + if (!FspIoqPostIrp(&FsvrtDeviceExtension->Ioq, Irp))\ + FspCompleteRequest(Irp, STATUS_ACCESS_DENIED);\ + } \ + } \ else \ FspCompleteRequest(Irp, Result);\ ); \ @@ -198,6 +206,7 @@ typedef struct typedef struct { FSP_DEVICE_EXTENSION Base; + PDEVICE_OBJECT FsvrtDeviceObject; } FSP_FSVOL_DEVICE_EXTENSION; static inline FSP_DEVICE_EXTENSION *FspDeviceExtension(PDEVICE_OBJECT DeviceObject) diff --git a/src/sys/fsctl.c b/src/sys/fsctl.c index e0ac70bc..c4fe4afb 100644 --- a/src/sys/fsctl.c +++ b/src/sys/fsctl.c @@ -125,6 +125,9 @@ static NTSTATUS FspFsvrtTransact( NTSTATUS Result; FSP_FSVRT_DEVICE_EXTENSION *FsvrtDeviceExtension = FspFsvrtDeviceExtension(DeviceObject); + PUINT8 SystemBufferEnd; + FSP_TRANSACT_RSP *Response; + PIRP ProcessIrp; /* access check */ Result = FspSecuritySubjectContextAccessCheck( @@ -132,7 +135,32 @@ static NTSTATUS FspFsvrtTransact( if (!NT_SUCCESS(Result)) return Result; - return STATUS_INVALID_DEVICE_REQUEST; + /* process any user-mode file system responses */ + Response = SystemBuffer; + SystemBufferEnd = (PUINT8)SystemBuffer + InputBufferLength; + for (;;) + { + if ((PUINT8)Response + sizeof(Response->Size) > SystemBufferEnd || + sizeof(FSP_TRANSACT_RSP) > Response->Size || + (PUINT8)Response + Response->Size > SystemBufferEnd) + break; + + ProcessIrp = FspIoqEndProcessingIrp(&FsvrtDeviceExtension->Ioq, Response->Hint); + if (0 == ProcessIrp) + /* either IRP was canceled or a bogus IrpHint was provided */ + continue; + + //FspDispatchProcessedIrp(ProcessIrp, Response); + + Response = (PVOID)((PUINT8)Response + Response->Size); + } + + if (FspIoqPostIrp(&FsvrtDeviceExtension->TransactIoq, Irp)) + Result = STATUS_PENDING; + else + Result = STATUS_ACCESS_DENIED; + + return Result; } static NTSTATUS FspFsctlFileSystemControl(