mirror of
https://github.com/winfsp/winfsp.git
synced 2025-04-23 08:53:01 -05:00
sys: device.c
This commit is contained in:
parent
f4de97f3c6
commit
ccf4ef5cc8
@ -139,6 +139,7 @@
|
|||||||
<ClCompile Include="..\..\src\sys\create.c" />
|
<ClCompile Include="..\..\src\sys\create.c" />
|
||||||
<ClCompile Include="..\..\src\sys\debug.c" />
|
<ClCompile Include="..\..\src\sys\debug.c" />
|
||||||
<ClCompile Include="..\..\src\sys\devctl.c" />
|
<ClCompile Include="..\..\src\sys\devctl.c" />
|
||||||
|
<ClCompile Include="..\..\src\sys\device.c" />
|
||||||
<ClCompile Include="..\..\src\sys\dirctl.c" />
|
<ClCompile Include="..\..\src\sys\dirctl.c" />
|
||||||
<ClCompile Include="..\..\src\sys\driver.c" />
|
<ClCompile Include="..\..\src\sys\driver.c" />
|
||||||
<ClCompile Include="..\..\src\sys\ea.c" />
|
<ClCompile Include="..\..\src\sys\ea.c" />
|
||||||
|
@ -80,6 +80,9 @@
|
|||||||
<ClCompile Include="..\..\src\sys\iop.c">
|
<ClCompile Include="..\..\src\sys\iop.c">
|
||||||
<Filter>Source</Filter>
|
<Filter>Source</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\..\src\sys\device.c">
|
||||||
|
<Filter>Source</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="..\..\src\sys\driver.h">
|
<ClInclude Include="..\..\src\sys\driver.h">
|
||||||
|
149
src/sys/device.c
Normal file
149
src/sys/device.c
Normal file
@ -0,0 +1,149 @@
|
|||||||
|
/**
|
||||||
|
* @file sys/device.c
|
||||||
|
*
|
||||||
|
* @copyright 2015 Bill Zissimopoulos
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/driver.h>
|
||||||
|
|
||||||
|
NTSTATUS FspDeviceCreateList(
|
||||||
|
PDRIVER_OBJECT DriverObject, PDEVICE_OBJECT **PDeviceObjects, PULONG PDeviceObjectCount);
|
||||||
|
VOID FspDeviceDeleteList(
|
||||||
|
PDEVICE_OBJECT *DeviceObjects, ULONG DeviceObjectCount);
|
||||||
|
NTSTATUS FspDeviceOwned(
|
||||||
|
PDRIVER_OBJECT DriverObject, PDEVICE_OBJECT DeviceObject);
|
||||||
|
static VOID FspFsctlDeviceDeleteObject(PDEVICE_OBJECT DeviceObject);
|
||||||
|
static VOID FspFsvrtDeviceDeleteObject(PDEVICE_OBJECT DeviceObject);
|
||||||
|
static VOID FspFsvolDeviceDeleteObject(PDEVICE_OBJECT DeviceObject);
|
||||||
|
VOID FspDeviceDeleteObject(PDEVICE_OBJECT DeviceObject);
|
||||||
|
VOID FspDeviceDeleteObjects(PDRIVER_OBJECT DriverObject);
|
||||||
|
|
||||||
|
#ifdef ALLOC_PRAGMA
|
||||||
|
#pragma alloc_text(PAGE, FspDeviceCreateList)
|
||||||
|
#pragma alloc_text(PAGE, FspDeviceDeleteList)
|
||||||
|
#pragma alloc_text(PAGE, FspDeviceOwned)
|
||||||
|
#pragma alloc_text(PAGE, FspFsctlDeviceDeleteObject)
|
||||||
|
#pragma alloc_text(PAGE, FspFsvrtDeviceDeleteObject)
|
||||||
|
#pragma alloc_text(PAGE, FspFsvolDeviceDeleteObject)
|
||||||
|
#pragma alloc_text(PAGE, FspDeviceDeleteObject)
|
||||||
|
#pragma alloc_text(PAGE, FspDeviceDeleteObjects)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
NTSTATUS FspDeviceCreateList(
|
||||||
|
PDRIVER_OBJECT DriverObject, PDEVICE_OBJECT **PDeviceObjects, PULONG PDeviceObjectCount)
|
||||||
|
{
|
||||||
|
PAGED_CODE();
|
||||||
|
|
||||||
|
PDEVICE_OBJECT *DeviceObjects = 0;
|
||||||
|
ULONG DeviceObjectCount = 0;
|
||||||
|
|
||||||
|
while (STATUS_BUFFER_TOO_SMALL == IoEnumerateDeviceObjectList(DriverObject,
|
||||||
|
DeviceObjects, DeviceObjectCount, &DeviceObjectCount))
|
||||||
|
{
|
||||||
|
if (0 != DeviceObjects)
|
||||||
|
ExFreePoolWithTag(DeviceObjects, FSP_TAG);
|
||||||
|
DeviceObjects = ExAllocatePoolWithTag(NonPagedPool,
|
||||||
|
sizeof *DeviceObjects * DeviceObjectCount, FSP_TAG);
|
||||||
|
if (0 == DeviceObjects)
|
||||||
|
return STATUS_INSUFFICIENT_RESOURCES;
|
||||||
|
RtlZeroMemory(DeviceObjects, sizeof *DeviceObjects * DeviceObjectCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
*PDeviceObjects = DeviceObjects;
|
||||||
|
*PDeviceObjectCount = DeviceObjectCount;
|
||||||
|
|
||||||
|
return STATUS_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
VOID FspDeviceDeleteList(
|
||||||
|
PDEVICE_OBJECT *DeviceObjects, ULONG DeviceObjectCount)
|
||||||
|
{
|
||||||
|
PAGED_CODE();
|
||||||
|
|
||||||
|
for (ULONG i = 0; DeviceObjectCount > i; i++)
|
||||||
|
ObDereferenceObject(DeviceObjects[i]);
|
||||||
|
|
||||||
|
ExFreePoolWithTag(DeviceObjects, FSP_TAG);
|
||||||
|
}
|
||||||
|
|
||||||
|
NTSTATUS FspDeviceOwned(
|
||||||
|
PDRIVER_OBJECT DriverObject, PDEVICE_OBJECT DeviceObject)
|
||||||
|
{
|
||||||
|
PAGED_CODE();
|
||||||
|
|
||||||
|
NTSTATUS Result = STATUS_NO_SUCH_DEVICE;
|
||||||
|
PDEVICE_OBJECT *DeviceObjects = 0;
|
||||||
|
ULONG DeviceObjectCount = 0;
|
||||||
|
|
||||||
|
Result = FspDeviceCreateList(DriverObject, &DeviceObjects, &DeviceObjectCount);
|
||||||
|
if (!NT_SUCCESS(Result))
|
||||||
|
return Result;
|
||||||
|
|
||||||
|
for (ULONG i = 0; DeviceObjectCount > i; i++)
|
||||||
|
if (DeviceObjects[i] == DeviceObject)
|
||||||
|
{
|
||||||
|
Result = STATUS_SUCCESS;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
FspDeviceDeleteList(DeviceObjects, DeviceObjectCount);
|
||||||
|
|
||||||
|
return Result;
|
||||||
|
}
|
||||||
|
|
||||||
|
static VOID FspFsctlDeviceDeleteObject(PDEVICE_OBJECT DeviceObject)
|
||||||
|
{
|
||||||
|
PAGED_CODE();
|
||||||
|
|
||||||
|
IoDeleteDevice(DeviceObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
static VOID FspFsvrtDeviceDeleteObject(PDEVICE_OBJECT DeviceObject)
|
||||||
|
{
|
||||||
|
PAGED_CODE();
|
||||||
|
|
||||||
|
IoDeleteDevice(DeviceObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
static VOID FspFsvolDeviceDeleteObject(PDEVICE_OBJECT DeviceObject)
|
||||||
|
{
|
||||||
|
PAGED_CODE();
|
||||||
|
|
||||||
|
IoDeleteDevice(DeviceObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
VOID FspDeviceDeleteObject(PDEVICE_OBJECT DeviceObject)
|
||||||
|
{
|
||||||
|
PAGED_CODE();
|
||||||
|
|
||||||
|
switch (FspDeviceExtension(DeviceObject)->Kind)
|
||||||
|
{
|
||||||
|
case FspFsvolDeviceExtensionKind:
|
||||||
|
FspFsvolDeviceDeleteObject(DeviceObject);
|
||||||
|
break;
|
||||||
|
case FspFsvrtDeviceExtensionKind:
|
||||||
|
FspFsvrtDeviceDeleteObject(DeviceObject);
|
||||||
|
break;
|
||||||
|
case FspFsctlDeviceExtensionKind:
|
||||||
|
FspFsctlDeviceDeleteObject(DeviceObject);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
VOID FspDeviceDeleteObjects(PDRIVER_OBJECT DriverObject)
|
||||||
|
{
|
||||||
|
PAGED_CODE();
|
||||||
|
|
||||||
|
NTSTATUS Result;
|
||||||
|
PDEVICE_OBJECT *DeviceObjects = 0;
|
||||||
|
ULONG DeviceObjectCount = 0;
|
||||||
|
|
||||||
|
Result = FspDeviceCreateList(DriverObject, &DeviceObjects, &DeviceObjectCount);
|
||||||
|
if (!NT_SUCCESS(Result))
|
||||||
|
return;
|
||||||
|
|
||||||
|
for (ULONG i = 0; DeviceObjectCount > i; i++)
|
||||||
|
FspDeviceDeleteObject(DeviceObjects[i]);
|
||||||
|
|
||||||
|
FspDeviceDeleteList(DeviceObjects, DeviceObjectCount);
|
||||||
|
}
|
@ -286,6 +286,14 @@ FSP_FSVOL_DEVICE_EXTENSION *FspFsvolDeviceExtension(PDEVICE_OBJECT DeviceObject)
|
|||||||
ASSERT(FspFsvolDeviceExtensionKind == ((FSP_DEVICE_EXTENSION *)DeviceObject->DeviceExtension)->Kind);
|
ASSERT(FspFsvolDeviceExtensionKind == ((FSP_DEVICE_EXTENSION *)DeviceObject->DeviceExtension)->Kind);
|
||||||
return DeviceObject->DeviceExtension;
|
return DeviceObject->DeviceExtension;
|
||||||
}
|
}
|
||||||
|
NTSTATUS FspDeviceCreateList(
|
||||||
|
PDRIVER_OBJECT DriverObject, PDEVICE_OBJECT **PDeviceObjects, PULONG PDeviceObjectCount);
|
||||||
|
VOID FspDeviceDeleteList(
|
||||||
|
PDEVICE_OBJECT *DeviceObjects, ULONG DeviceObjectCount);
|
||||||
|
NTSTATUS FspDeviceOwned(
|
||||||
|
PDRIVER_OBJECT DriverObject, PDEVICE_OBJECT DeviceObject);
|
||||||
|
VOID FspDeviceDeleteObject(PDEVICE_OBJECT DeviceObject);
|
||||||
|
VOID FspDeviceDeleteObjects(PDRIVER_OBJECT DriverObject);
|
||||||
|
|
||||||
/* I/O processing */
|
/* I/O processing */
|
||||||
VOID FspIopCompleteRequest(PIRP Irp, NTSTATUS Result);
|
VOID FspIopCompleteRequest(PIRP Irp, NTSTATUS Result);
|
||||||
@ -295,12 +303,6 @@ VOID FspIopDispatchComplete(PIRP Irp, const FSP_FSCTL_TRANSACT_RSP *Response);
|
|||||||
NTSTATUS FspCreateGuid(GUID *Guid);
|
NTSTATUS FspCreateGuid(GUID *Guid);
|
||||||
NTSTATUS FspSecuritySubjectContextAccessCheck(
|
NTSTATUS FspSecuritySubjectContextAccessCheck(
|
||||||
PSECURITY_DESCRIPTOR SecurityDescriptor, ACCESS_MASK DesiredAccess, KPROCESSOR_MODE AccessMode);
|
PSECURITY_DESCRIPTOR SecurityDescriptor, ACCESS_MASK DesiredAccess, KPROCESSOR_MODE AccessMode);
|
||||||
NTSTATUS FspCreateDeviceObjectList(
|
|
||||||
PDRIVER_OBJECT DriverObject, PDEVICE_OBJECT **PDeviceObjects, PULONG PDeviceObjectCount);
|
|
||||||
VOID FspDeleteDeviceObjectList(
|
|
||||||
PDEVICE_OBJECT *DeviceObjects, ULONG DeviceObjectCount);
|
|
||||||
NTSTATUS FspHasDeviceObject(
|
|
||||||
PDRIVER_OBJECT DriverObject, PDEVICE_OBJECT DeviceObject);
|
|
||||||
|
|
||||||
/* debug */
|
/* debug */
|
||||||
#if DBG
|
#if DBG
|
||||||
|
@ -116,7 +116,7 @@ static NTSTATUS FspFsctlMountVolume(
|
|||||||
FSP_FSVOL_DEVICE_EXTENSION *FsvolDeviceExtension;
|
FSP_FSVOL_DEVICE_EXTENSION *FsvolDeviceExtension;
|
||||||
|
|
||||||
/* check the passed in volume object; it must be one of our own */
|
/* check the passed in volume object; it must be one of our own */
|
||||||
Result = FspHasDeviceObject(DeviceObject->DriverObject, FsvrtDeviceObject);
|
Result = FspDeviceOwned(DeviceObject->DriverObject, FsvrtDeviceObject);
|
||||||
if (!NT_SUCCESS(Result))
|
if (!NT_SUCCESS(Result))
|
||||||
{
|
{
|
||||||
if (STATUS_NO_SUCH_DEVICE == Result)
|
if (STATUS_NO_SUCH_DEVICE == Result)
|
||||||
|
@ -49,59 +49,3 @@ NTSTATUS FspSecuritySubjectContextAccessCheck(
|
|||||||
|
|
||||||
return Result;
|
return Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
NTSTATUS FspCreateDeviceObjectList(
|
|
||||||
PDRIVER_OBJECT DriverObject, PDEVICE_OBJECT **PDeviceObjects, PULONG PDeviceObjectCount)
|
|
||||||
{
|
|
||||||
PDEVICE_OBJECT *DeviceObjects = 0;
|
|
||||||
ULONG DeviceObjectCount = 0;
|
|
||||||
|
|
||||||
while (STATUS_BUFFER_TOO_SMALL == IoEnumerateDeviceObjectList(DriverObject,
|
|
||||||
DeviceObjects, DeviceObjectCount, &DeviceObjectCount))
|
|
||||||
{
|
|
||||||
if (0 != DeviceObjects)
|
|
||||||
ExFreePoolWithTag(DeviceObjects, FSP_TAG);
|
|
||||||
DeviceObjects = ExAllocatePoolWithTag(NonPagedPool,
|
|
||||||
sizeof *DeviceObjects * DeviceObjectCount, FSP_TAG);
|
|
||||||
if (0 == DeviceObjects)
|
|
||||||
return STATUS_INSUFFICIENT_RESOURCES;
|
|
||||||
RtlZeroMemory(DeviceObjects, sizeof *DeviceObjects * DeviceObjectCount);
|
|
||||||
}
|
|
||||||
|
|
||||||
*PDeviceObjects = DeviceObjects;
|
|
||||||
*PDeviceObjectCount = DeviceObjectCount;
|
|
||||||
|
|
||||||
return STATUS_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
VOID FspDeleteDeviceObjectList(
|
|
||||||
PDEVICE_OBJECT *DeviceObjects, ULONG DeviceObjectCount)
|
|
||||||
{
|
|
||||||
for (ULONG i = 0; DeviceObjectCount > i; i++)
|
|
||||||
ObDereferenceObject(DeviceObjects[i]);
|
|
||||||
|
|
||||||
ExFreePoolWithTag(DeviceObjects, FSP_TAG);
|
|
||||||
}
|
|
||||||
|
|
||||||
NTSTATUS FspHasDeviceObject(
|
|
||||||
PDRIVER_OBJECT DriverObject, PDEVICE_OBJECT DeviceObject)
|
|
||||||
{
|
|
||||||
NTSTATUS Result = STATUS_NO_SUCH_DEVICE;
|
|
||||||
PDEVICE_OBJECT *DeviceObjects = 0;
|
|
||||||
ULONG DeviceObjectCount = 0;
|
|
||||||
|
|
||||||
Result = FspCreateDeviceObjectList(DriverObject, &DeviceObjects, &DeviceObjectCount);
|
|
||||||
if (!NT_SUCCESS(Result))
|
|
||||||
return Result;
|
|
||||||
|
|
||||||
for (ULONG i = 0; DeviceObjectCount > i; i++)
|
|
||||||
if (DeviceObjects[i] == DeviceObject)
|
|
||||||
{
|
|
||||||
Result = STATUS_SUCCESS;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
FspDeleteDeviceObjectList(DeviceObjects, DeviceObjectCount);
|
|
||||||
|
|
||||||
return Result;
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user