Major refactoring: IRP_MJ_CREATE

This commit is contained in:
Bill Zissimopoulos 2015-12-24 11:52:37 -08:00
parent 983ba0bcc1
commit 78c5fdb6f2
4 changed files with 77 additions and 1 deletions

View File

@ -156,6 +156,7 @@
<ClCompile Include="..\..\src\sys\driver.c" /> <ClCompile Include="..\..\src\sys\driver.c" />
<ClCompile Include="..\..\src\sys\ea.c" /> <ClCompile Include="..\..\src\sys\ea.c" />
<ClCompile Include="..\..\src\sys\fastio.c" /> <ClCompile Include="..\..\src\sys\fastio.c" />
<ClCompile Include="..\..\src\sys\filectx.c" />
<ClCompile Include="..\..\src\sys\fileinfo.c" /> <ClCompile Include="..\..\src\sys\fileinfo.c" />
<ClCompile Include="..\..\src\sys\flush.c" /> <ClCompile Include="..\..\src\sys\flush.c" />
<ClCompile Include="..\..\src\sys\fsctl.c" /> <ClCompile Include="..\..\src\sys\fsctl.c" />

View File

@ -83,6 +83,9 @@
<ClCompile Include="..\..\src\sys\volume.c"> <ClCompile Include="..\..\src\sys\volume.c">
<Filter>Source</Filter> <Filter>Source</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\src\sys\filectx.c">
<Filter>Source</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="..\..\src\sys\driver.h"> <ClInclude Include="..\..\src\sys\driver.h">

View File

@ -476,10 +476,10 @@ typedef struct
BOOLEAN DeletePending; /* FileDispositionInformation */ BOOLEAN DeletePending; /* FileDispositionInformation */
BOOLEAN DeleteOnClose; /* FILE_DELETE_ON_CLOSE */ BOOLEAN DeleteOnClose; /* FILE_DELETE_ON_CLOSE */
FSP_DEVICE_GENERIC_TABLE_ELEMENT ElementStorage; FSP_DEVICE_GENERIC_TABLE_ELEMENT ElementStorage;
PDEVICE_OBJECT FsvolDeviceObject;
UINT64 UserContext; UINT64 UserContext;
#endif #endif
/* read-only after creation */ /* read-only after creation */
PDEVICE_OBJECT FsvolDeviceObject;
UNICODE_STRING FileName; UNICODE_STRING FileName;
WCHAR FileNameBuf[]; WCHAR FileNameBuf[];
} FSP_FILE_CONTEXT; } FSP_FILE_CONTEXT;

72
src/sys/filectx.c Normal file
View File

@ -0,0 +1,72 @@
/**
* @file sys/filectx.c
*
* @copyright 2015 Bill Zissimopoulos
*/
#include <sys/driver.h>
NTSTATUS FspFileContextCreate(PDEVICE_OBJECT DeviceObject,
ULONG ExtraSize, FSP_FILE_CONTEXT **PFsContext);
VOID FspFileContextDelete(FSP_FILE_CONTEXT *Context);
#ifdef ALLOC_PRAGMA
#pragma alloc_text(PAGE, FspFileContextCreate)
#pragma alloc_text(PAGE, FspFileContextDelete)
#endif
NTSTATUS FspFileContextCreate(PDEVICE_OBJECT DeviceObject,
ULONG ExtraSize, FSP_FILE_CONTEXT **PFsContext)
{
PAGED_CODE();
*PFsContext = 0;
FSP_FILE_CONTEXT_NONPAGED *NonPaged = FspAllocNonPaged(sizeof *NonPaged);
if (0 == NonPaged)
return STATUS_INSUFFICIENT_RESOURCES;
FSP_FILE_CONTEXT *FsContext = FspAlloc(sizeof *FsContext + ExtraSize);
if (0 == FsContext)
{
FspFree(NonPaged);
return STATUS_INSUFFICIENT_RESOURCES;
}
RtlZeroMemory(NonPaged, sizeof *NonPaged);
ExInitializeResourceLite(&NonPaged->Resource);
ExInitializeResourceLite(&NonPaged->PagingIoResource);
ExInitializeFastMutex(&NonPaged->HeaderFastMutex);
RtlZeroMemory(FsContext, sizeof *FsContext + ExtraSize);
FsContext->Header.NodeTypeCode = FspFileContextFileKind;
FsContext->Header.NodeByteSize = sizeof *FsContext;
FsContext->Header.IsFastIoPossible = FastIoIsQuestionable;
FsContext->Header.Resource = &NonPaged->Resource;
FsContext->Header.PagingIoResource = &NonPaged->PagingIoResource;
FsRtlSetupAdvancedHeader(&FsContext->Header, &NonPaged->HeaderFastMutex);
FsContext->NonPaged = NonPaged;
FsContext->RefCount = 1;
FsContext->FsvolDeviceObject = DeviceObject;
FspDeviceRetain(FsContext->FsvolDeviceObject);
RtlInitEmptyUnicodeString(&FsContext->FileName, FsContext->FileNameBuf, (USHORT)ExtraSize);
*PFsContext = FsContext;
return STATUS_SUCCESS;
}
VOID FspFileContextDelete(FSP_FILE_CONTEXT *FsContext)
{
PAGED_CODE();
FsRtlTeardownPerStreamContexts(&FsContext->Header);
FspDeviceRelease(FsContext->FsvolDeviceObject);
ExDeleteResourceLite(&FsContext->NonPaged->PagingIoResource);
ExDeleteResourceLite(&FsContext->NonPaged->Resource);
FspFree(FsContext->NonPaged);
FspFree(FsContext);
}