dll: fsctl.c, ntstatus.c

This commit is contained in:
Bill Zissimopoulos 2015-11-25 16:04:05 -08:00
parent ceb46a8c55
commit 1ad43de1a1
6 changed files with 119 additions and 3 deletions

View File

@ -164,6 +164,7 @@
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\..\src\dll\fsctl.c" />
<ClCompile Include="..\..\src\dll\ntstatus.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\inc\winfsp\fsctl.h" />

View File

@ -17,6 +17,9 @@
<ClCompile Include="..\..\src\dll\fsctl.c">
<Filter>Source</Filter>
</ClCompile>
<ClCompile Include="..\..\src\dll\ntstatus.c">
<Filter>Source</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\inc\winfsp\fsctl.h">

View File

@ -29,7 +29,7 @@ extern const __declspec(selectany) GUID FspFsvrtDeviceClassGuid =
#define FSP_FSCTL_TRANSACT \
CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 0x800 + 'T', METHOD_BUFFERED, FILE_ANY_ACCESS)
#define FSP_FSCTL_CREATE_BUFFER_SIZE 64
#define FSP_FSCTL_CREATE_BUFFER_SIZE 128
#define FSP_FSCTL_TRANSACT_BUFFER_SIZE 4096
#define FSP_FSCTL_TRANSACT_REQ_SIZEMAX 1536
@ -60,8 +60,10 @@ typedef struct
#pragma warning(pop)
#if !defined(WINFSP_SYS_DRIVER_H_INTERNAL)
NTSTATUS FspFsctlCreateVolume(PSECURITY_DESCRIPTOR SecurityDescriptor, PHANDLE *PHandle);
NTSTATUS FspFsctlOpenVolume(PWSTR VolumeName);
NTSTATUS FspFsctlCreateVolume(PWSTR DevicePath, PSECURITY_DESCRIPTOR SecurityDescriptor,
PHANDLE *PHandle);
NTSTATUS FspFsctlOpenVolume(PWSTR VolumePath,
PHANDLE *PHandle);
NTSTATUS FspFsctlDeleteVolume(HANDLE Handle);
NTSTATUS FspFsctlTransact(HANDLE Handle,
const FSP_TRANSACT_RSP *Responses, size_t NumResponses,

View File

@ -13,4 +13,6 @@
#include <winternl.h>
#include <ntstatus.h>
NTSTATUS FspNtStatusFromWin32(DWORD Error);
#endif

View File

@ -6,3 +6,99 @@
#include <winfsp/winfsp.h>
#include <winfsp/fsctl.h>
#include <strsafe.h>
#define GLOBALROOT L"\\\\?\\GLOBALROOT"
NTSTATUS FspFsctlCreateVolume(PWSTR DevicePath, PSECURITY_DESCRIPTOR SecurityDescriptor,
PHANDLE *PHandle)
{
NTSTATUS Result = STATUS_SUCCESS;
WCHAR DevicePathBuf[(sizeof GLOBALROOT + FSP_FSCTL_CREATE_BUFFER_SIZE) / sizeof(WCHAR)];
WCHAR VolumePathBuf[FSP_FSCTL_CREATE_BUFFER_SIZE / sizeof(WCHAR)];
PSECURITY_DESCRIPTOR SecurityDescriptorBuf = 0;
DWORD SecurityDescriptorLen, Bytes;
HANDLE DeviceHandle = INVALID_HANDLE_VALUE;
*PHandle = 0;
DevicePathBuf[0] = L'\0';
StringCbPrintf(DevicePathBuf, sizeof DevicePathBuf, GLOBALROOT "%S", DevicePath);
if (!MakeSelfRelativeSD(SecurityDescriptor, 0, &SecurityDescriptorLen))
{
SecurityDescriptorBuf = malloc(SecurityDescriptorLen);
if (0 == SecurityDescriptorBuf)
{
Result = STATUS_INSUFFICIENT_RESOURCES;
goto exit;
}
if (!MakeSelfRelativeSD(SecurityDescriptor, SecurityDescriptorBuf, &SecurityDescriptorLen))
{
Result = FspNtStatusFromWin32(GetLastError());
goto exit;
}
}
DeviceHandle = CreateFileW(DevicePathBuf,
0, FILE_SHARE_WRITE | FILE_SHARE_WRITE | FILE_SHARE_DELETE, 0, OPEN_EXISTING, 0, 0);
if (INVALID_HANDLE_VALUE == DeviceHandle)
{
Result = FspNtStatusFromWin32(GetLastError());
goto exit;
}
if (!DeviceIoControl(DeviceHandle, FSP_FSCTL_CREATE,
SecurityDescriptorBuf, SecurityDescriptorLen, VolumePathBuf, sizeof VolumePathBuf,
&Bytes, 0))
{
Result = FspNtStatusFromWin32(GetLastError());
goto exit;
}
Result = FspFsctlOpenVolume(VolumePathBuf, PHandle);
exit:
if (INVALID_HANDLE_VALUE != DeviceHandle)
CloseHandle(DeviceHandle);
free(SecurityDescriptorBuf);
return Result;
}
NTSTATUS FspFsctlOpenVolume(PWSTR VolumePath,
PHANDLE *PHandle)
{
NTSTATUS Result = STATUS_SUCCESS;
WCHAR DevicePathBuf[(sizeof GLOBALROOT + FSP_FSCTL_CREATE_BUFFER_SIZE) / sizeof(WCHAR)];
HANDLE DeviceHandle;
*PHandle = 0;
DevicePathBuf[0] = L'\0';
StringCbPrintf(DevicePathBuf, sizeof DevicePathBuf, GLOBALROOT "%S", VolumePath);
DeviceHandle = CreateFileW(DevicePathBuf,
0, FILE_SHARE_WRITE | FILE_SHARE_WRITE | FILE_SHARE_DELETE, 0, OPEN_EXISTING, 0, 0);
if (INVALID_HANDLE_VALUE == DeviceHandle)
{
Result = FspNtStatusFromWin32(GetLastError());
goto exit;
}
*PHandle = DeviceHandle;
exit:
return Result;
}
NTSTATUS FspFsctlDeleteVolume(HANDLE Handle)
{
return STATUS_NOT_IMPLEMENTED;
}
NTSTATUS FspFsctlTransact(HANDLE Handle,
const FSP_TRANSACT_RSP *Responses, size_t NumResponses,
const FSP_TRANSACT_REQ *Requests, size_t *NumRequests)
{
return STATUS_NOT_IMPLEMENTED;
}

12
src/dll/ntstatus.c Normal file
View File

@ -0,0 +1,12 @@
/**
* @file dll/ntstatus.c
*
* @copyright 2015 Bill Zissimopoulos
*/
#include <winfsp/winfsp.h>
NTSTATUS FspNtStatusFromWin32(DWORD Error)
{
return STATUS_ACCESS_DENIED;
}