From 154a945c9a414b5eaee6adbc84e92536ab9d538a Mon Sep 17 00:00:00 2001 From: Bill Zissimopoulos Date: Mon, 7 Dec 2015 23:52:31 -0800 Subject: [PATCH] sys: IRP_MJ_CLOSE --- src/sys/close.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/src/sys/close.c b/src/sys/close.c index 4a1a96d1..317a8dad 100644 --- a/src/sys/close.c +++ b/src/sys/close.c @@ -48,7 +48,63 @@ static NTSTATUS FspFsvolClose( { PAGED_CODE(); - return STATUS_INVALID_DEVICE_REQUEST; + NTSTATUS Result; + FSP_FSVOL_DEVICE_EXTENSION *FsvolDeviceExtension = FspFsvolDeviceExtension(DeviceObject); + PDEVICE_OBJECT FsvrtDeviceObject = FsvolDeviceExtension->FsvrtDeviceObject; + + if (!FspDeviceRetain(FsvrtDeviceObject)) + return STATUS_CANCELLED; + try + { + FSP_FSVRT_DEVICE_EXTENSION *FsvrtDeviceExtension = + FspFsvrtDeviceExtension(FsvrtDeviceObject); + PFILE_OBJECT FileObject = IrpSp->FileObject; + FSP_FILE_CONTEXT *FsContext = FileObject->FsContext; + BOOLEAN FileNameRequired = 0 != FsvrtDeviceExtension->VolumeParams.FileNameRequired; + FSP_FSCTL_TRANSACT_REQ *Request; + + /* dereference the FsContext (and delete if no more references) */ + FspFileContextRelease(FsContext); + + /* create the user-mode file system request */ + Result = FspIopCreateRequest(Irp, FileNameRequired ? &FsContext->FileName : 0, 0, &Request); + if (!NT_SUCCESS(Result)) + { + /* IRP_MJ_CLOSE cannot really fail :-\ */ + Result = STATUS_SUCCESS; + goto exit; + } + + /* + * The new request is associated with our IRP and will be deleted during its completion. + */ + + /* populate the Close request */ + Request->Kind = FspFsctlTransactCloseKind; + Request->Req.Cleanup.UserContext = FsContext->UserContext; + Request->Req.Cleanup.UserContext2 = (UINT_PTR)FileObject->FsContext2; + Request->Req.Cleanup.Delete = DeletePending && 0 == OpenCount; + + /* post as a work request; this allows us to complete our own IRP and return immediately! */ + if (!FspIopPostWorkRequest(DeviceObject, Request)) + { + /* no need to delete the request here as FspIopPostWorkRequest() will do so in all cases */ + + /* IRP_MJ_CLOSE cannot really fail :-\ */ + Result = STATUS_SUCCESS; + goto exit; + } + + Result = STATUS_SUCCESS; + + exit:; + } + finally + { + FspDeviceRelease(FsvrtDeviceObject); + } + + return Result; } VOID FspFsvolCloseComplete(