mirror of
https://github.com/winfsp/winfsp.git
synced 2025-04-23 17:03:12 -05:00
sys: FsContext now maintains reference to its DeviceObject
This commit is contained in:
parent
140e567fdc
commit
de065afe8d
@ -50,56 +50,56 @@ static NTSTATUS FspFsvolCleanup(
|
|||||||
|
|
||||||
NTSTATUS Result;
|
NTSTATUS Result;
|
||||||
FSP_FSVOL_DEVICE_EXTENSION *FsvolDeviceExtension = FspFsvolDeviceExtension(DeviceObject);
|
FSP_FSVOL_DEVICE_EXTENSION *FsvolDeviceExtension = FspFsvolDeviceExtension(DeviceObject);
|
||||||
PDEVICE_OBJECT FsvrtDeviceObject = FsvolDeviceExtension->FsvrtDeviceObject;
|
PFILE_OBJECT FileObject = IrpSp->FileObject;
|
||||||
|
FSP_FILE_CONTEXT *FsContext = FileObject->FsContext;
|
||||||
|
UINT64 UserContext = FsContext->UserContext;
|
||||||
|
UINT64 UserContext2 = (UINT_PTR)FileObject->FsContext2;
|
||||||
|
BOOLEAN DeletePending;
|
||||||
|
LONG OpenCount;
|
||||||
|
|
||||||
|
/* lock the FsContext */
|
||||||
|
ExAcquireResourceExclusiveLite(FsContext->Header.Resource, TRUE);
|
||||||
|
|
||||||
|
/* propagate the FsContext DeleteOnClose to DeletePending */
|
||||||
|
if (FsContext->DeleteOnClose)
|
||||||
|
FsContext->DeletePending = TRUE;
|
||||||
|
DeletePending = FsContext->DeletePending;
|
||||||
|
|
||||||
|
/* all handles on this FileObject are gone; decrement its FsContext->OpenCount */
|
||||||
|
OpenCount = FspFileContextClose(FsContext);
|
||||||
|
|
||||||
|
/* unlock the FsContext */
|
||||||
|
ExReleaseResourceLite(FsContext->Header.Resource);
|
||||||
|
|
||||||
|
/* is the FsContext going away as well? */
|
||||||
|
if (0 == OpenCount)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* The following must be done under the file system volume device Resource,
|
||||||
|
* because we are manipulating its GenericTable.
|
||||||
|
*/
|
||||||
|
ExAcquireResourceExclusiveLite(&FsvolDeviceExtension->Base.Resource, TRUE);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
/* remove the FsContext from the file system volume device generic table */
|
||||||
|
FspFsvolDeviceDeleteContext(DeviceObject, FsContext->UserContext, 0);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
ExReleaseResourceLite(&FsvolDeviceExtension->Base.Resource);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
PDEVICE_OBJECT FsvrtDeviceObject = FsvolDeviceExtension->FsvrtDeviceObject;
|
||||||
if (!FspDeviceRetain(FsvrtDeviceObject))
|
if (!FspDeviceRetain(FsvrtDeviceObject))
|
||||||
return STATUS_CANCELLED;
|
return STATUS_CANCELLED;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
FSP_FSVRT_DEVICE_EXTENSION *FsvrtDeviceExtension =
|
FSP_FSVRT_DEVICE_EXTENSION *FsvrtDeviceExtension = FspFsvrtDeviceExtension(FsvrtDeviceObject);
|
||||||
FspFsvrtDeviceExtension(FsvrtDeviceObject);
|
|
||||||
PFILE_OBJECT FileObject = IrpSp->FileObject;
|
|
||||||
FSP_FILE_CONTEXT *FsContext = FileObject->FsContext;
|
|
||||||
UINT64 UserContext = FsContext->UserContext;
|
|
||||||
UINT64 UserContext2 = (UINT_PTR)FileObject->FsContext2;
|
|
||||||
BOOLEAN FileNameRequired = 0 != FsvrtDeviceExtension->VolumeParams.FileNameRequired;
|
BOOLEAN FileNameRequired = 0 != FsvrtDeviceExtension->VolumeParams.FileNameRequired;
|
||||||
BOOLEAN DeletePending;
|
|
||||||
LONG OpenCount;
|
|
||||||
FSP_FSCTL_TRANSACT_REQ *Request;
|
FSP_FSCTL_TRANSACT_REQ *Request;
|
||||||
|
|
||||||
/* lock the FsContext */
|
|
||||||
ExAcquireResourceExclusiveLite(FsContext->Header.Resource, TRUE);
|
|
||||||
|
|
||||||
/* propagate the FsContext DeleteOnClose to DeletePending */
|
|
||||||
if (FsContext->DeleteOnClose)
|
|
||||||
FsContext->DeletePending = TRUE;
|
|
||||||
DeletePending = FsContext->DeletePending;
|
|
||||||
|
|
||||||
/* all handles on this FileObject are gone; decrement its FsContext->OpenCount */
|
|
||||||
OpenCount = FspFileContextClose(FsContext);
|
|
||||||
|
|
||||||
/* unlock the FsContext */
|
|
||||||
ExReleaseResourceLite(FsContext->Header.Resource);
|
|
||||||
|
|
||||||
/* is the FsContext going away as well? */
|
|
||||||
if (0 == OpenCount)
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
* The following must be done under the file system volume device Resource,
|
|
||||||
* because we are manipulating its GenericTable.
|
|
||||||
*/
|
|
||||||
ExAcquireResourceExclusiveLite(&FsvolDeviceExtension->Base.Resource, TRUE);
|
|
||||||
try
|
|
||||||
{
|
|
||||||
/* remove the FsContext from the file system volume device generic table */
|
|
||||||
FspFsvolDeviceDeleteContext(DeviceObject, FsContext->UserContext, 0);
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
ExReleaseResourceLite(&FsvolDeviceExtension->Base.Resource);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* create the user-mode file system request */
|
/* create the user-mode file system request */
|
||||||
Result = FspIopCreateRequest(Irp, FileNameRequired ? &FsContext->FileName : 0, 0, &Request);
|
Result = FspIopCreateRequest(Irp, FileNameRequired ? &FsContext->FileName : 0, 0, &Request);
|
||||||
if (!NT_SUCCESS(Result))
|
if (!NT_SUCCESS(Result))
|
||||||
|
@ -50,24 +50,24 @@ static NTSTATUS FspFsvolClose(
|
|||||||
|
|
||||||
NTSTATUS Result;
|
NTSTATUS Result;
|
||||||
FSP_FSVOL_DEVICE_EXTENSION *FsvolDeviceExtension = FspFsvolDeviceExtension(DeviceObject);
|
FSP_FSVOL_DEVICE_EXTENSION *FsvolDeviceExtension = FspFsvolDeviceExtension(DeviceObject);
|
||||||
PDEVICE_OBJECT FsvrtDeviceObject = FsvolDeviceExtension->FsvrtDeviceObject;
|
PFILE_OBJECT FileObject = IrpSp->FileObject;
|
||||||
|
FSP_FILE_CONTEXT *FsContext = FileObject->FsContext;
|
||||||
|
UINT64 UserContext = FsContext->UserContext;
|
||||||
|
UINT64 UserContext2 = (UINT_PTR)FileObject->FsContext2;
|
||||||
|
|
||||||
|
/* dereference the FsContext (and delete if no more references) */
|
||||||
|
FspFileContextRelease(FsContext);
|
||||||
|
|
||||||
|
PDEVICE_OBJECT FsvrtDeviceObject = FsvolDeviceExtension->FsvrtDeviceObject;
|
||||||
if (!FspDeviceRetain(FsvrtDeviceObject))
|
if (!FspDeviceRetain(FsvrtDeviceObject))
|
||||||
return STATUS_CANCELLED;
|
return STATUS_CANCELLED;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
FSP_FSVRT_DEVICE_EXTENSION *FsvrtDeviceExtension =
|
FSP_FSVRT_DEVICE_EXTENSION *FsvrtDeviceExtension = FspFsvrtDeviceExtension(FsvrtDeviceObject);
|
||||||
FspFsvrtDeviceExtension(FsvrtDeviceObject);
|
|
||||||
PFILE_OBJECT FileObject = IrpSp->FileObject;
|
|
||||||
FSP_FILE_CONTEXT *FsContext = FileObject->FsContext;
|
|
||||||
UINT64 UserContext = FsContext->UserContext;
|
|
||||||
UINT64 UserContext2 = (UINT_PTR)FileObject->FsContext2;
|
|
||||||
BOOLEAN FileNameRequired = 0 != FsvrtDeviceExtension->VolumeParams.FileNameRequired;
|
BOOLEAN FileNameRequired = 0 != FsvrtDeviceExtension->VolumeParams.FileNameRequired;
|
||||||
FSP_FSCTL_TRANSACT_REQ *Request;
|
FSP_FSCTL_TRANSACT_REQ *Request;
|
||||||
|
|
||||||
/* dereference the FsContext (and delete if no more references) */
|
|
||||||
FspFileContextRelease(FsContext);
|
|
||||||
|
|
||||||
/* create the user-mode file system request */
|
/* create the user-mode file system request */
|
||||||
Result = FspIopCreateRequest(0, FileNameRequired ? &FsContext->FileName : 0, 0, &Request);
|
Result = FspIopCreateRequest(0, FileNameRequired ? &FsContext->FileName : 0, 0, &Request);
|
||||||
if (!NT_SUCCESS(Result))
|
if (!NT_SUCCESS(Result))
|
||||||
|
@ -63,14 +63,14 @@ static NTSTATUS FspFsvolCreate(
|
|||||||
|
|
||||||
NTSTATUS Result;
|
NTSTATUS Result;
|
||||||
FSP_FSVOL_DEVICE_EXTENSION *FsvolDeviceExtension = FspFsvolDeviceExtension(DeviceObject);
|
FSP_FSVOL_DEVICE_EXTENSION *FsvolDeviceExtension = FspFsvolDeviceExtension(DeviceObject);
|
||||||
PDEVICE_OBJECT FsvrtDeviceObject = FsvolDeviceExtension->FsvrtDeviceObject;
|
|
||||||
|
|
||||||
|
PDEVICE_OBJECT FsvrtDeviceObject = FsvolDeviceExtension->FsvrtDeviceObject;
|
||||||
if (!FspDeviceRetain(FsvrtDeviceObject))
|
if (!FspDeviceRetain(FsvrtDeviceObject))
|
||||||
return STATUS_CANCELLED;
|
return STATUS_CANCELLED;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
FSP_FSVRT_DEVICE_EXTENSION *FsvrtDeviceExtension =
|
FSP_FSVRT_DEVICE_EXTENSION *FsvrtDeviceExtension = FspFsvrtDeviceExtension(FsvrtDeviceObject);
|
||||||
FspFsvrtDeviceExtension(FsvrtDeviceObject);
|
|
||||||
PFILE_OBJECT FileObject = IrpSp->FileObject;
|
PFILE_OBJECT FileObject = IrpSp->FileObject;
|
||||||
PFILE_OBJECT RelatedFileObject = FileObject->RelatedFileObject;
|
PFILE_OBJECT RelatedFileObject = FileObject->RelatedFileObject;
|
||||||
UNICODE_STRING FileName = FileObject->FileName;
|
UNICODE_STRING FileName = FileObject->FileName;
|
||||||
@ -223,7 +223,7 @@ static NTSTATUS FspFsvolCreate(
|
|||||||
BOOLEAN AppendBackslash =
|
BOOLEAN AppendBackslash =
|
||||||
sizeof(WCHAR) * 2/* not empty or root */ <= RelatedFsContext->FileName.Length &&
|
sizeof(WCHAR) * 2/* not empty or root */ <= RelatedFsContext->FileName.Length &&
|
||||||
sizeof(WCHAR) <= FileName.Length && L':' != FileName.Buffer[0];
|
sizeof(WCHAR) <= FileName.Length && L':' != FileName.Buffer[0];
|
||||||
Result = FspFileContextCreate(
|
Result = FspFileContextCreate(DeviceObject,
|
||||||
RelatedFsContext->FileName.Length + AppendBackslash * sizeof(WCHAR) + FileName.Length,
|
RelatedFsContext->FileName.Length + AppendBackslash * sizeof(WCHAR) + FileName.Length,
|
||||||
&FsContext);
|
&FsContext);
|
||||||
if (!NT_SUCCESS(Result))
|
if (!NT_SUCCESS(Result))
|
||||||
@ -254,7 +254,7 @@ static NTSTATUS FspFsvolCreate(
|
|||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
Result = FspFileContextCreate(
|
Result = FspFileContextCreate(DeviceObject,
|
||||||
FileName.Length,
|
FileName.Length,
|
||||||
&FsContext);
|
&FsContext);
|
||||||
if (!NT_SUCCESS(Result))
|
if (!NT_SUCCESS(Result))
|
||||||
|
@ -398,11 +398,13 @@ typedef struct
|
|||||||
BOOLEAN DeleteOnClose; /* FILE_DELETE_ON_CLOSE */
|
BOOLEAN DeleteOnClose; /* FILE_DELETE_ON_CLOSE */
|
||||||
/* read-only after creation */
|
/* read-only after creation */
|
||||||
FSP_DEVICE_GENERIC_TABLE_ELEMENT ElementStorage;
|
FSP_DEVICE_GENERIC_TABLE_ELEMENT ElementStorage;
|
||||||
|
PDEVICE_OBJECT FsvolDeviceObject;
|
||||||
UINT64 UserContext;
|
UINT64 UserContext;
|
||||||
UNICODE_STRING FileName;
|
UNICODE_STRING FileName;
|
||||||
WCHAR FileNameBuf[];
|
WCHAR FileNameBuf[];
|
||||||
} FSP_FILE_CONTEXT;
|
} FSP_FILE_CONTEXT;
|
||||||
NTSTATUS FspFileContextCreate(ULONG ExtraSize, FSP_FILE_CONTEXT **PContext);
|
NTSTATUS FspFileContextCreate(PDEVICE_OBJECT DeviceObject,
|
||||||
|
ULONG ExtraSize, FSP_FILE_CONTEXT **PFsContext);
|
||||||
VOID FspFileContextDelete(FSP_FILE_CONTEXT *Context);
|
VOID FspFileContextDelete(FSP_FILE_CONTEXT *Context);
|
||||||
static inline
|
static inline
|
||||||
VOID FspFileContextOpen(FSP_FILE_CONTEXT *Context)
|
VOID FspFileContextOpen(FSP_FILE_CONTEXT *Context)
|
||||||
|
@ -6,7 +6,8 @@
|
|||||||
|
|
||||||
#include <sys/driver.h>
|
#include <sys/driver.h>
|
||||||
|
|
||||||
NTSTATUS FspFileContextCreate(ULONG ExtraSize, FSP_FILE_CONTEXT **PContext);
|
NTSTATUS FspFileContextCreate(PDEVICE_OBJECT DeviceObject,
|
||||||
|
ULONG ExtraSize, FSP_FILE_CONTEXT **PFsContext);
|
||||||
VOID FspFileContextDelete(FSP_FILE_CONTEXT *Context);
|
VOID FspFileContextDelete(FSP_FILE_CONTEXT *Context);
|
||||||
|
|
||||||
#ifdef ALLOC_PRAGMA
|
#ifdef ALLOC_PRAGMA
|
||||||
@ -14,7 +15,8 @@ VOID FspFileContextDelete(FSP_FILE_CONTEXT *Context);
|
|||||||
#pragma alloc_text(PAGE, FspFileContextDelete)
|
#pragma alloc_text(PAGE, FspFileContextDelete)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
NTSTATUS FspFileContextCreate(ULONG ExtraSize, FSP_FILE_CONTEXT **PFsContext)
|
NTSTATUS FspFileContextCreate(PDEVICE_OBJECT DeviceObject,
|
||||||
|
ULONG ExtraSize, FSP_FILE_CONTEXT **PFsContext)
|
||||||
{
|
{
|
||||||
PAGED_CODE();
|
PAGED_CODE();
|
||||||
|
|
||||||
@ -45,6 +47,8 @@ NTSTATUS FspFileContextCreate(ULONG ExtraSize, FSP_FILE_CONTEXT **PFsContext)
|
|||||||
FsRtlSetupAdvancedHeader(&FsContext->Header, &NonPaged->HeaderFastMutex);
|
FsRtlSetupAdvancedHeader(&FsContext->Header, &NonPaged->HeaderFastMutex);
|
||||||
FsContext->NonPaged = NonPaged;
|
FsContext->NonPaged = NonPaged;
|
||||||
FsContext->RefCount = 1;
|
FsContext->RefCount = 1;
|
||||||
|
FsContext->FsvolDeviceObject = DeviceObject;
|
||||||
|
FspDeviceRetain(FsContext->FsvolDeviceObject);
|
||||||
RtlInitEmptyUnicodeString(&FsContext->FileName, FsContext->FileNameBuf, (USHORT)ExtraSize);
|
RtlInitEmptyUnicodeString(&FsContext->FileName, FsContext->FileNameBuf, (USHORT)ExtraSize);
|
||||||
|
|
||||||
*PFsContext = FsContext;
|
*PFsContext = FsContext;
|
||||||
@ -58,6 +62,8 @@ VOID FspFileContextDelete(FSP_FILE_CONTEXT *FsContext)
|
|||||||
|
|
||||||
FsRtlTeardownPerStreamContexts(&FsContext->Header);
|
FsRtlTeardownPerStreamContexts(&FsContext->Header);
|
||||||
|
|
||||||
|
FspDeviceRelease(FsContext->FsvolDeviceObject);
|
||||||
|
|
||||||
ExDeleteResourceLite(&FsContext->NonPaged->PagingIoResource);
|
ExDeleteResourceLite(&FsContext->NonPaged->PagingIoResource);
|
||||||
ExDeleteResourceLite(&FsContext->NonPaged->Resource);
|
ExDeleteResourceLite(&FsContext->NonPaged->Resource);
|
||||||
FspFree(FsContext->NonPaged);
|
FspFree(FsContext->NonPaged);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user