mirror of
https://github.com/winfsp/winfsp.git
synced 2025-04-22 16:33:02 -05:00
205 lines
7.5 KiB
C
205 lines
7.5 KiB
C
/**
|
|
* @file winfsp/fsctl.h
|
|
*
|
|
* @copyright 2015 Bill Zissimopoulos
|
|
*/
|
|
|
|
#ifndef WINFSP_FSCTL_H_INCLUDED
|
|
#define WINFSP_FSCTL_H_INCLUDED
|
|
|
|
#include <devioctl.h>
|
|
|
|
// {6F9D25FA-6DEE-4A9D-80F5-E98E14F35E54}
|
|
extern const __declspec(selectany) GUID FspFsctlDeviceClassGuid =
|
|
{ 0x6f9d25fa, 0x6dee, 0x4a9d, { 0x80, 0xf5, 0xe9, 0x8e, 0x14, 0xf3, 0x5e, 0x54 } };
|
|
// {B48171C3-DD50-4852-83A3-344C50D93B17}
|
|
extern const __declspec(selectany) GUID FspFsvrtDeviceClassGuid =
|
|
{ 0xb48171c3, 0xdd50, 0x4852, { 0x83, 0xa3, 0x34, 0x4c, 0x50, 0xd9, 0x3b, 0x17 } };
|
|
|
|
#define FSP_FSCTL_DISK_DEVICE_NAME "WinFsp.Disk"
|
|
#define FSP_FSCTL_NET_DEVICE_NAME "WinFsp.Net"
|
|
|
|
/* alignment macros */
|
|
#define FSP_FSCTL_ALIGN_UP(x, s) (((x) + ((s) - 1L)) & ~((s) - 1L))
|
|
#define FSP_FSCTL_DEFAULT_ALIGNMENT 8
|
|
#define FSP_FSCTL_DEFAULT_ALIGN_UP(x) FSP_FSCTL_ALIGN_UP(x, FSP_FSCTL_DEFAULT_ALIGNMENT)
|
|
#define FSP_FSCTL_DECLSPEC_ALIGN __declspec(align(FSP_FSCTL_DEFAULT_ALIGNMENT))
|
|
|
|
/* fsctl device codes */
|
|
#define FSP_FSCTL_CREATE \
|
|
CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 0x800 + 'C', METHOD_BUFFERED, FILE_ANY_ACCESS)
|
|
#define FSP_FSCTL_TRANSACT \
|
|
CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 0x800 + 'T', METHOD_BUFFERED, FILE_ANY_ACCESS)
|
|
|
|
#define FSP_FSCTL_CREATE_BUFFER_SIZEMIN 128
|
|
#define FSP_FSCTL_TRANSACT_REQ_BUFFER_SIZEMIN 16384 /* checked by driver! */
|
|
#define FSP_FSCTL_TRANSACT_REQ_SIZEMAX (4096 - 64) /* 64: size for internal request header */
|
|
#define FSP_FSCTL_TRANSACT_RSP_SIZEMAX (4096 - 64) /* symmetry! */
|
|
|
|
/* marshalling */
|
|
#pragma warning(push)
|
|
#pragma warning(disable:4200) /* zero-sized array in struct/union */
|
|
enum
|
|
{
|
|
FspFsctlTransactUnknownKind = 0,
|
|
FspFsctlTransactCreateKind,
|
|
FspFsctlTransactCloseKind,
|
|
FspFsctlTransactReadKind,
|
|
FspFsctlTransactWriteKind,
|
|
FspFsctlTransactQueryInformationKind,
|
|
FspFsctlTransactSetInformationKind,
|
|
FspFsctlTransactQueryEaKind,
|
|
FspFsctlTransactSetEaKind,
|
|
FspFsctlTransactFlushBuffersKind,
|
|
FspFsctlTransactQueryVolumeInformationKind,
|
|
FspFsctlTransactSetVolumeInformationKind,
|
|
FspFsctlTransactDirectoryControlKind,
|
|
FspFsctlTransactFileSystemControlKind,
|
|
FspFsctlTransactDeviceControlKind,
|
|
FspFsctlTransactShutdownKind,
|
|
FspFsctlTransactLockControlKind,
|
|
FspFsctlTransactCleanupKind,
|
|
FspFsctlTransactQuerySecurityKind,
|
|
FspFsctlTransactSetSecurityKind,
|
|
FspFsctlTransactKindCount,
|
|
};
|
|
enum
|
|
{
|
|
FspFsctlTransactTimeoutMinimum = 1000,
|
|
FspFsctlTransactTimeoutMaximum = 10000,
|
|
FspFsctlTransactTimeoutDefault = 1000,
|
|
FspFsctlIrpTimeoutMinimum = 60000,
|
|
FspFsctlIrpTimeoutMaximum = 600000,
|
|
FspFsctlIrpTimeoutDefault = 300000,
|
|
FspFsctlIrpTimeoutDebug = 42, /* special value for IRP timeout testing; debug driver only */
|
|
};
|
|
typedef struct
|
|
{
|
|
UINT16 Version;
|
|
UINT16 SectorSize;
|
|
UINT32 SerialNumber;
|
|
UINT32 TransactTimeout; /* milliseconds; values between 1 sec and 10 sec */
|
|
UINT32 IrpTimeout; /* milliseconds; values between 1 min and 10 min */
|
|
UINT32 EaSupported:1; /* supports extended attributes (unimplemented; set to 0) */
|
|
UINT32 FileNameRequired:1; /* FileName required for all operations (not just Create) */
|
|
} FSP_FSCTL_VOLUME_PARAMS;
|
|
typedef struct
|
|
{
|
|
UINT16 Offset;
|
|
UINT16 Size;
|
|
} FSP_FSCTL_TRANSACT_BUF;
|
|
typedef struct
|
|
{
|
|
UINT16 Version;
|
|
UINT16 Size;
|
|
UINT32 Kind;
|
|
UINT64 Hint;
|
|
union
|
|
{
|
|
struct
|
|
{
|
|
UINT32 CreateOptions; /* Disposition: high 8 bits; Options: low 24 bits */
|
|
UINT32 FileAttributes; /* FILE_ATTRIBUTE_{NORMAL,DIRECTORY,etc.} */
|
|
FSP_FSCTL_TRANSACT_BUF SecurityDescriptor; /* security descriptor for new files */
|
|
UINT64 AllocationSize; /* initial allocation size */
|
|
UINT64 AccessToken; /* (HANDLE); request access token; sent if NoAccessCheck is 0 */
|
|
UINT32 DesiredAccess; /* FILE_{READ_DATA,WRITE_DATA,etc.} */
|
|
UINT32 ShareAccess; /* FILE_SHARE_{READ,WRITE,DELETE} */
|
|
FSP_FSCTL_TRANSACT_BUF Ea; /* reserved; not currently implemented */
|
|
UINT32 UserMode:1; /* request originated in user mode */
|
|
UINT32 HasTraversePrivilege:1; /* requestor has TOKEN_HAS_TRAVERSE_PRIVILEGE */
|
|
UINT32 OpenTargetDirectory:1; /* open target dir and report FILE_{EXISTS,DOES_NOT_EXIST} */
|
|
UINT32 CaseSensitive:1; /* FileName comparisons should be case-sensitive */
|
|
} Create;
|
|
struct
|
|
{
|
|
UINT64 UserContext;
|
|
UINT64 UserContext2;
|
|
UINT32 Delete:1; /* if set, the file or directory must be deleted */
|
|
} Cleanup;
|
|
struct
|
|
{
|
|
UINT64 UserContext;
|
|
UINT64 UserContext2;
|
|
} Close;
|
|
} Req;
|
|
FSP_FSCTL_TRANSACT_BUF FileName;
|
|
FSP_FSCTL_DECLSPEC_ALIGN UINT8 Buffer[];
|
|
} FSP_FSCTL_TRANSACT_REQ;
|
|
typedef struct
|
|
{
|
|
UINT16 Version;
|
|
UINT16 Size;
|
|
UINT32 Kind;
|
|
UINT64 Hint;
|
|
struct
|
|
{
|
|
UINT64 Information;
|
|
UINT32 Status;
|
|
} IoStatus;
|
|
union
|
|
{
|
|
union
|
|
{
|
|
/* IoStatus.Status == STATUS_SUCCESS */
|
|
struct
|
|
{
|
|
UINT64 UserContext; /* open file user context (unique file id) */
|
|
UINT64 UserContext2; /* kernel file object user context (only low 32 bits valid) */
|
|
} Opened;
|
|
/* IoStatus.Status == STATUS_REPARSE */
|
|
struct
|
|
{
|
|
FSP_FSCTL_TRANSACT_BUF FileName; /* file name to use for STATUS_REPARSE */
|
|
} Reparse;
|
|
} Create;
|
|
} Rsp;
|
|
FSP_FSCTL_DECLSPEC_ALIGN UINT8 Buffer[];
|
|
} FSP_FSCTL_TRANSACT_RSP;
|
|
#pragma warning(pop)
|
|
static inline BOOLEAN FspFsctlTransactCanProduceRequest(
|
|
FSP_FSCTL_TRANSACT_REQ *Request, PVOID RequestBufEnd)
|
|
{
|
|
return (PUINT8)Request + FSP_FSCTL_TRANSACT_REQ_SIZEMAX <= (PUINT8)RequestBufEnd;
|
|
}
|
|
static inline FSP_FSCTL_TRANSACT_REQ *FspFsctlTransactProduceRequest(
|
|
FSP_FSCTL_TRANSACT_REQ *Request, SIZE_T RequestSize)
|
|
{
|
|
PVOID NextRequest = (PUINT8)Request + FSP_FSCTL_DEFAULT_ALIGN_UP(RequestSize);
|
|
return NextRequest;
|
|
}
|
|
static inline FSP_FSCTL_TRANSACT_REQ *FspFsctlTransactConsumeRequest(
|
|
FSP_FSCTL_TRANSACT_REQ *Request, PVOID RequestBufEnd)
|
|
{
|
|
if ((PUINT8)Request + sizeof(Request->Size) > (PUINT8)RequestBufEnd ||
|
|
sizeof(FSP_FSCTL_TRANSACT_REQ) > Request->Size)
|
|
return 0;
|
|
PVOID NextRequest = (PUINT8)Request + FSP_FSCTL_DEFAULT_ALIGN_UP(Request->Size);
|
|
return NextRequest <= RequestBufEnd ? NextRequest : 0;
|
|
}
|
|
static inline BOOLEAN FspFsctlTransactCanProduceResponse(
|
|
FSP_FSCTL_TRANSACT_RSP *Response, PVOID ResponseBufEnd)
|
|
{
|
|
return (PUINT8)Response + FSP_FSCTL_TRANSACT_RSP_SIZEMAX <= (PUINT8)ResponseBufEnd;
|
|
}
|
|
static inline FSP_FSCTL_TRANSACT_RSP *FspFsctlTransactProduceResponse(
|
|
FSP_FSCTL_TRANSACT_RSP *Response, SIZE_T ResponseSize)
|
|
{
|
|
PVOID NextResponse = (PUINT8)Response + FSP_FSCTL_DEFAULT_ALIGN_UP(ResponseSize);
|
|
return NextResponse;
|
|
}
|
|
static inline FSP_FSCTL_TRANSACT_RSP *FspFsctlTransactConsumeResponse(
|
|
FSP_FSCTL_TRANSACT_RSP *Response, PVOID ResponseBufEnd)
|
|
{
|
|
if ((PUINT8)Response + sizeof(Response->Size) > (PUINT8)ResponseBufEnd ||
|
|
sizeof(FSP_FSCTL_TRANSACT_RSP) > Response->Size)
|
|
return 0;
|
|
PVOID NextResponse = (PUINT8)Response + FSP_FSCTL_DEFAULT_ALIGN_UP(Response->Size);
|
|
return NextResponse <= ResponseBufEnd ? NextResponse : 0;
|
|
}
|
|
|
|
#if !defined(WINFSP_SYS_INTERNAL)
|
|
#endif
|
|
|
|
#endif
|