From 3e3aa7651fe7befd74ca4395e21ae6d413adb90b Mon Sep 17 00:00:00 2001 From: Bill Zissimopoulos Date: Tue, 1 Nov 2016 18:49:28 -0700 Subject: [PATCH] dll: UmFileContextIsUserContext2, UmFileContextIsFullContext support --- inc/winfsp/fsctl.h | 12 ++-- inc/winfsp/winfsp.h | 160 +++++++++++++++++++++++++------------------- src/dll/fs.c | 7 +- src/dll/fsop.c | 124 ++++++++++++++++++++-------------- src/dll/fuse/fuse.c | 2 +- 5 files changed, 178 insertions(+), 127 deletions(-) diff --git a/inc/winfsp/fsctl.h b/inc/winfsp/fsctl.h index 3d78d716..81b314cc 100644 --- a/inc/winfsp/fsctl.h +++ b/inc/winfsp/fsctl.h @@ -78,8 +78,6 @@ FSP_FSCTL_STATIC_ASSERT(FSP_FSCTL_VOLUME_NAME_SIZEMAX <= 260 * sizeof(WCHAR), #define FSP_FSCTL_TRANSACT_BATCH_BUFFER_SIZEMIN (64 * 1024) #define FSP_FSCTL_TRANSACT_BUFFER_SIZEMIN FSP_FSCTL_TRANSACT_REQ_SIZEMAX -#define FSP_FSCTL_TRANSACT_USERCONTEXT(s,i) (((PUINT64)&(s).UserContext)[i]) - /* marshalling */ #pragma warning(push) #pragma warning(disable:4200) /* zero-sized array in struct/union */ @@ -151,8 +149,9 @@ typedef struct UINT32 PostCleanupOnDeleteOnly:1; /* post Cleanup when deleting a file only */ UINT32 KmReservedFlags:5; /* user-mode flags */ - UINT32 UmFileNodeIsUserContext2:1; /* user mode: FileNode parameter is UserContext2 */ - UINT32 UmReservedFlags:15; + UINT32 UmFileContextIsUserContext2:1; /* user mode: FileContext parameter is UserContext2 */ + UINT32 UmFileContextIsFullContext:1; /* user mode: FileContext parameter is FullContext */ + UINT32 UmReservedFlags:14; WCHAR Prefix[FSP_FSCTL_VOLUME_PREFIX_SIZE / sizeof(WCHAR)]; /* UNC prefix (\Server\Share) */ WCHAR FileSystemName[FSP_FSCTL_VOLUME_FSNAME_SIZE / sizeof(WCHAR)]; } FSP_FSCTL_VOLUME_PARAMS; @@ -198,6 +197,11 @@ typedef struct WCHAR StreamNameBuf[]; } FSP_FSCTL_STREAM_INFO; typedef struct +{ + UINT64 UserContext; + UINT64 UserContext2; +} FSP_FSCTL_TRANSACT_FULL_CONTEXT; +typedef struct { UINT16 Offset; UINT16 Size; diff --git a/inc/winfsp/winfsp.h b/inc/winfsp/winfsp.h index e6b92fb8..944c0174 100644 --- a/inc/winfsp/winfsp.h +++ b/inc/winfsp/winfsp.h @@ -127,7 +127,35 @@ typedef enum * File system interface. * * The operations in this interface must be implemented by the user mode - * file system. + * file system. Not all operations need be implemented. For example, + * a user mode file system that does not wish to support reparse points, + * need not implement the reparse point operations. + * + * Most of the operations accept a FileContext parameter. This parameter + * has different meanings depending on the value of the FSP_FSCTL_VOLUME_PARAMS + * flags UmFileContextIsUserContext2 and UmFileContextIsFullContext. + * + * There are three cases to consider: + * */ typedef struct _FSP_FILE_SYSTEM_INTERFACE { @@ -219,12 +247,8 @@ typedef struct _FSP_FILE_SYSTEM_INTERFACE * Windows GetSecurityDescriptorLength API. Will be NULL for named streams. * @param AllocationSize * Allocation size for the newly created file. - * @param PFileNode [out] - * Pointer that will receive the file node on successful return from this call. The file - * node is a void pointer (or an integer that can fit in a pointer) that is used to - * uniquely identify an open file. Opening the same file name should always return the same - * file node value for as long as the file with that name remains open anywhere in the - * system. The file system can place any value it needs here. + * @param PFileContext [out] + * Pointer that will receive the file context on successful return from this call. * @param FileInfo [out] * Pointer to a structure that will receive the file information on successful return * from this call. This information includes file attributes, file times, etc. @@ -234,7 +258,7 @@ typedef struct _FSP_FILE_SYSTEM_INTERFACE NTSTATUS (*Create)(FSP_FILE_SYSTEM *FileSystem, PWSTR FileName, UINT32 CreateOptions, UINT32 GrantedAccess, UINT32 FileAttributes, PSECURITY_DESCRIPTOR SecurityDescriptor, UINT64 AllocationSize, - PVOID *PFileNode, FSP_FSCTL_FILE_INFO *FileInfo); + PVOID *PFileContext, FSP_FSCTL_FILE_INFO *FileInfo); /** * Open a file or directory. * @@ -254,12 +278,8 @@ typedef struct _FSP_FILE_SYSTEM_INTERFACE * need not perform any additional checks. However this parameter may be useful to a user * mode file system; for example the WinFsp-FUSE layer uses this parameter to determine * which flags to use in its POSIX open() call. - * @param PFileNode [out] - * Pointer that will receive the file node on successful return from this call. The file - * node is a void pointer (or an integer that can fit in a pointer) that is used to - * uniquely identify an open file. Opening the same file name should always return the same - * file node value for as long as the file with that name remains open anywhere in the - * system. The file system can place any value it needs here. + * @param PFileContext [out] + * Pointer that will receive the file context on successful return from this call. * @param FileInfo [out] * Pointer to a structure that will receive the file information on successful return * from this call. This information includes file attributes, file times, etc. @@ -268,14 +288,14 @@ typedef struct _FSP_FILE_SYSTEM_INTERFACE */ NTSTATUS (*Open)(FSP_FILE_SYSTEM *FileSystem, PWSTR FileName, UINT32 CreateOptions, UINT32 GrantedAccess, - PVOID *PFileNode, FSP_FSCTL_FILE_INFO *FileInfo); + PVOID *PFileContext, FSP_FSCTL_FILE_INFO *FileInfo); /** * Overwrite a file. * * @param FileSystem * The file system on which this request is posted. - * @param FileNode - * The file node of the file to overwrite. + * @param FileContext + * The file context of the file to overwrite. * @param FileAttributes * File attributes to apply to the overwritten file. * @param ReplaceFileAttributes @@ -288,7 +308,7 @@ typedef struct _FSP_FILE_SYSTEM_INTERFACE * STATUS_SUCCESS or error code. */ NTSTATUS (*Overwrite)(FSP_FILE_SYSTEM *FileSystem, - PVOID FileNode, UINT32 FileAttributes, BOOLEAN ReplaceFileAttributes, + PVOID FileContext, UINT32 FileAttributes, BOOLEAN ReplaceFileAttributes, FSP_FSCTL_FILE_INFO *FileInfo); /** * Cleanup a file. @@ -315,8 +335,8 @@ typedef struct _FSP_FILE_SYSTEM_INTERFACE * * @param FileSystem * The file system on which this request is posted. - * @param FileNode - * The file node of the file or directory to cleanup. + * @param FileContext + * The file context of the file or directory to cleanup. * @param FileName * The name of the file or directory to cleanup. Sent only when a Delete is requested. * @param Delete @@ -328,24 +348,24 @@ typedef struct _FSP_FILE_SYSTEM_INTERFACE * CanDelete */ VOID (*Cleanup)(FSP_FILE_SYSTEM *FileSystem, - PVOID FileNode, PWSTR FileName, BOOLEAN Delete); + PVOID FileContext, PWSTR FileName, BOOLEAN Delete); /** * Close a file. * * @param FileSystem * The file system on which this request is posted. - * @param FileNode - * The file node of the file or directory to be closed. + * @param FileContext + * The file context of the file or directory to be closed. */ VOID (*Close)(FSP_FILE_SYSTEM *FileSystem, - PVOID FileNode); + PVOID FileContext); /** * Read a file. * * @param FileSystem * The file system on which this request is posted. - * @param FileNode - * The file node of the file to be read. + * @param FileContext + * The file context of the file to be read. * @param Buffer * Pointer to a buffer that will receive the results of the read operation. * @param Offset @@ -359,15 +379,15 @@ typedef struct _FSP_FILE_SYSTEM_INTERFACE * operation. */ NTSTATUS (*Read)(FSP_FILE_SYSTEM *FileSystem, - PVOID FileNode, PVOID Buffer, UINT64 Offset, ULONG Length, + PVOID FileContext, PVOID Buffer, UINT64 Offset, ULONG Length, PULONG PBytesTransferred); /** * Write a file. * * @param FileSystem * The file system on which this request is posted. - * @param FileNode - * The file node of the file to be written. + * @param FileContext + * The file context of the file to be written. * @param Buffer * Pointer to a buffer that contains the data to write. * @param Offset @@ -389,7 +409,7 @@ typedef struct _FSP_FILE_SYSTEM_INTERFACE * operation. */ NTSTATUS (*Write)(FSP_FILE_SYSTEM *FileSystem, - PVOID FileNode, PVOID Buffer, UINT64 Offset, ULONG Length, + PVOID FileContext, PVOID Buffer, UINT64 Offset, ULONG Length, BOOLEAN WriteToEndOfFile, BOOLEAN ConstrainedIo, PULONG PBytesTransferred, FSP_FSCTL_FILE_INFO *FileInfo); /** @@ -399,20 +419,20 @@ typedef struct _FSP_FILE_SYSTEM_INTERFACE * * @param FileSystem * The file system on which this request is posted. - * @param FileNode - * The file node of the file to be flushed. When NULL the whole volume is being flushed. + * @param FileContext + * The file context of the file to be flushed. When NULL the whole volume is being flushed. * @return * STATUS_SUCCESS or error code. */ NTSTATUS (*Flush)(FSP_FILE_SYSTEM *FileSystem, - PVOID FileNode); + PVOID FileContext); /** * Get file or directory information. * * @param FileSystem * The file system on which this request is posted. - * @param FileNode - * The file node of the file or directory to get information for. + * @param FileContext + * The file context of the file or directory to get information for. * @param FileInfo [out] * Pointer to a structure that will receive the file information on successful return * from this call. This information includes file attributes, file times, etc. @@ -420,15 +440,15 @@ typedef struct _FSP_FILE_SYSTEM_INTERFACE * STATUS_SUCCESS or error code. */ NTSTATUS (*GetFileInfo)(FSP_FILE_SYSTEM *FileSystem, - PVOID FileNode, + PVOID FileContext, FSP_FSCTL_FILE_INFO *FileInfo); /** * Set file or directory basic information. * * @param FileSystem * The file system on which this request is posted. - * @param FileNode - * The file node of the file or directory to set information for. + * @param FileContext + * The file context of the file or directory to set information for. * @param FileAttributes * File attributes to apply to the file or directory. If the value INVALID_FILE_ATTRIBUTES * is sent, the file attributes should not be changed. @@ -448,7 +468,7 @@ typedef struct _FSP_FILE_SYSTEM_INTERFACE * STATUS_SUCCESS or error code. */ NTSTATUS (*SetBasicInfo)(FSP_FILE_SYSTEM *FileSystem, - PVOID FileNode, UINT32 FileAttributes, + PVOID FileContext, UINT32 FileAttributes, UINT64 CreationTime, UINT64 LastAccessTime, UINT64 LastWriteTime, FSP_FSCTL_FILE_INFO *FileInfo); /** @@ -473,8 +493,8 @@ typedef struct _FSP_FILE_SYSTEM_INTERFACE * * @param FileSystem * The file system on which this request is posted. - * @param FileNode - * The file node of the file to set the file/allocation size for. + * @param FileContext + * The file context of the file to set the file/allocation size for. * @param NewSize * New file/allocation size to apply to the file. * @param SetAllocationSize @@ -486,7 +506,7 @@ typedef struct _FSP_FILE_SYSTEM_INTERFACE * STATUS_SUCCESS or error code. */ NTSTATUS (*SetFileSize)(FSP_FILE_SYSTEM *FileSystem, - PVOID FileNode, UINT64 NewSize, BOOLEAN SetAllocationSize, + PVOID FileContext, UINT64 NewSize, BOOLEAN SetAllocationSize, FSP_FSCTL_FILE_INFO *FileInfo); /** * Determine whether a file or directory can be deleted. @@ -503,8 +523,8 @@ typedef struct _FSP_FILE_SYSTEM_INTERFACE * * @param FileSystem * The file system on which this request is posted. - * @param FileNode - * The file node of the file or directory to test for deletion. + * @param FileContext + * The file context of the file or directory to test for deletion. * @param FileName * The name of the file or directory to test for deletion. * @return @@ -513,7 +533,7 @@ typedef struct _FSP_FILE_SYSTEM_INTERFACE * Cleanup */ NTSTATUS (*CanDelete)(FSP_FILE_SYSTEM *FileSystem, - PVOID FileNode, PWSTR FileName); + PVOID FileContext, PWSTR FileName); /** * Renames a file or directory. * @@ -528,8 +548,8 @@ typedef struct _FSP_FILE_SYSTEM_INTERFACE * * @param FileSystem * The file system on which this request is posted. - * @param FileNode - * The file node of the file or directory to be renamed. + * @param FileContext + * The file context of the file or directory to be renamed. * @param FileName * The current name of the file or directory to rename. * @param NewFileName @@ -540,15 +560,15 @@ typedef struct _FSP_FILE_SYSTEM_INTERFACE * STATUS_SUCCESS or error code. */ NTSTATUS (*Rename)(FSP_FILE_SYSTEM *FileSystem, - PVOID FileNode, + PVOID FileContext, PWSTR FileName, PWSTR NewFileName, BOOLEAN ReplaceIfExists); /** * Get file or directory security descriptor. * * @param FileSystem * The file system on which this request is posted. - * @param FileNode - * The file node of the file or directory to get the security descriptor for. + * @param FileContext + * The file context of the file or directory to get the security descriptor for. * @param SecurityDescriptor * Pointer to a buffer that will receive the file security descriptor on successful return * from this call. May be NULL. @@ -560,15 +580,15 @@ typedef struct _FSP_FILE_SYSTEM_INTERFACE * STATUS_SUCCESS or error code. */ NTSTATUS (*GetSecurity)(FSP_FILE_SYSTEM *FileSystem, - PVOID FileNode, + PVOID FileContext, PSECURITY_DESCRIPTOR SecurityDescriptor, SIZE_T *PSecurityDescriptorSize); /** * Set file or directory security descriptor. * * @param FileSystem * The file system on which this request is posted. - * @param FileNode - * The file node of the file or directory to set the security descriptor for. + * @param FileContext + * The file context of the file or directory to set the security descriptor for. * @param SecurityInformation * Describes what parts of the file or directory security descriptor should * be modified. @@ -584,7 +604,7 @@ typedef struct _FSP_FILE_SYSTEM_INTERFACE * FspDeleteSecurityDescriptor */ NTSTATUS (*SetSecurity)(FSP_FILE_SYSTEM *FileSystem, - PVOID FileNode, + PVOID FileContext, SECURITY_INFORMATION SecurityInformation, PSECURITY_DESCRIPTOR ModificationDescriptor, HANDLE AccessToken); /** @@ -592,8 +612,8 @@ typedef struct _FSP_FILE_SYSTEM_INTERFACE * * @param FileSystem * The file system on which this request is posted. - * @param FileNode - * The file node of the directory to be read. + * @param FileContext + * The file context of the directory to be read. * @param Buffer * Pointer to a buffer that will receive the results of the read operation. * @param Offset @@ -617,7 +637,7 @@ typedef struct _FSP_FILE_SYSTEM_INTERFACE * FspFileSystemAddDirInfo */ NTSTATUS (*ReadDirectory)(FSP_FILE_SYSTEM *FileSystem, - PVOID FileNode, PVOID Buffer, UINT64 Offset, ULONG Length, + PVOID FileContext, PVOID Buffer, UINT64 Offset, ULONG Length, PWSTR Pattern, PULONG PBytesTransferred); /** @@ -669,8 +689,8 @@ typedef struct _FSP_FILE_SYSTEM_INTERFACE * * @param FileSystem * The file system on which this request is posted. - * @param FileNode - * The file node of the reparse point. + * @param FileContext + * The file context of the reparse point. * @param FileName * The file name of the reparse point. * @param Buffer @@ -685,15 +705,15 @@ typedef struct _FSP_FILE_SYSTEM_INTERFACE * SetReparsePoint */ NTSTATUS (*GetReparsePoint)(FSP_FILE_SYSTEM *FileSystem, - PVOID FileNode, + PVOID FileContext, PWSTR FileName, PVOID Buffer, PSIZE_T PSize); /** * Set reparse point. * * @param FileSystem * The file system on which this request is posted. - * @param FileNode - * The file node of the reparse point. + * @param FileContext + * The file context of the reparse point. * @param FileName * The file name of the reparse point. * @param Buffer @@ -707,15 +727,15 @@ typedef struct _FSP_FILE_SYSTEM_INTERFACE * GetReparsePoint */ NTSTATUS (*SetReparsePoint)(FSP_FILE_SYSTEM *FileSystem, - PVOID FileNode, + PVOID FileContext, PWSTR FileName, PVOID Buffer, SIZE_T Size); /** * Delete reparse point. * * @param FileSystem * The file system on which this request is posted. - * @param FileNode - * The file node of the reparse point. + * @param FileContext + * The file context of the reparse point. * @param FileName * The file name of the reparse point. * @param Buffer @@ -726,15 +746,15 @@ typedef struct _FSP_FILE_SYSTEM_INTERFACE * STATUS_SUCCESS or error code. */ NTSTATUS (*DeleteReparsePoint)(FSP_FILE_SYSTEM *FileSystem, - PVOID FileNode, + PVOID FileContext, PWSTR FileName, PVOID Buffer, SIZE_T Size); /** * Get named streams information. * * @param FileSystem * The file system on which this request is posted. - * @param FileNode - * The file node of the file or directory to get stream information for. + * @param FileContext + * The file context of the file or directory to get stream information for. * @param Buffer * Pointer to a buffer that will receive the stream information. * @param Length @@ -747,7 +767,7 @@ typedef struct _FSP_FILE_SYSTEM_INTERFACE * FspFileSystemAddStreamInfo */ NTSTATUS (*GetStreamInfo)(FSP_FILE_SYSTEM *FileSystem, - PVOID FileNode, PVOID Buffer, ULONG Length, + PVOID FileContext, PVOID Buffer, ULONG Length, PULONG PBytesTransferred); /* @@ -775,7 +795,7 @@ typedef struct _FSP_FILE_SYSTEM UINT32 DebugLog; FSP_FILE_SYSTEM_OPERATION_GUARD_STRATEGY OpGuardStrategy; SRWLOCK OpGuardLock; - BOOLEAN UmFileNodeIsUserContext2; + BOOLEAN UmFileContextIsUserContext2, UmFileContextIsFullContext; } FSP_FILE_SYSTEM; typedef struct _FSP_FILE_SYSTEM_OPERATION_CONTEXT { diff --git a/src/dll/fs.c b/src/dll/fs.c index 203f2621..26cf94ef 100644 --- a/src/dll/fs.c +++ b/src/dll/fs.c @@ -82,6 +82,10 @@ FSP_API NTSTATUS FspFileSystemCreate(PWSTR DevicePath, *PFileSystem = 0; + if (VolumeParams->UmFileContextIsUserContext2 && + VolumeParams->UmFileContextIsFullContext) + return STATUS_INVALID_PARAMETER; + if (0 == Interface) Interface = &FspFileSystemNullInterface; @@ -126,7 +130,8 @@ FSP_API NTSTATUS FspFileSystemCreate(PWSTR DevicePath, FileSystem->EnterOperation = FspFileSystemOpEnter; FileSystem->LeaveOperation = FspFileSystemOpLeave; - FileSystem->UmFileNodeIsUserContext2 = !!VolumeParams->UmFileNodeIsUserContext2; + FileSystem->UmFileContextIsUserContext2 = !!VolumeParams->UmFileContextIsUserContext2; + FileSystem->UmFileContextIsFullContext = !!VolumeParams->UmFileContextIsFullContext; *PFileSystem = FileSystem; diff --git a/src/dll/fsop.c b/src/dll/fsop.c index be322b11..dc6ce481 100644 --- a/src/dll/fsop.c +++ b/src/dll/fsop.c @@ -17,8 +17,16 @@ #include -#define USERCONTEXT(s) \ - FSP_FSCTL_TRANSACT_USERCONTEXT(s, FileSystem->UmFileNodeIsUserContext2) +#define AddrOfFileContext(s) \ + ( \ + (PVOID)&(((PUINT64)&(s).UserContext)[FileSystem->UmFileContextIsUserContext2])\ + ) +#define ValOfFileContext(s) \ + ( \ + FileSystem->UmFileContextIsFullContext ?\ + (PVOID)(&(s)) : \ + (PVOID)(((PUINT64)&(s).UserContext)[FileSystem->UmFileContextIsUserContext2])\ + ) FSP_API NTSTATUS FspFileSystemOpEnter(FSP_FILE_SYSTEM *FileSystem, FSP_FSCTL_TRANSACT_REQ *Request, FSP_FSCTL_TRANSACT_RSP *Response) @@ -361,7 +369,7 @@ static NTSTATUS FspFileSystemOpCreate_FileCreate(FSP_FILE_SYSTEM *FileSystem, NTSTATUS Result; UINT32 GrantedAccess; PSECURITY_DESCRIPTOR ParentDescriptor, ObjectDescriptor; - PVOID FileNode; + FSP_FSCTL_TRANSACT_FULL_CONTEXT FullContext; FSP_FSCTL_OPEN_FILE_INFO OpenFileInfo; Result = FspFileSystemCreateCheck(FileSystem, Request, Response, TRUE, @@ -374,14 +382,15 @@ static NTSTATUS FspFileSystemOpCreate_FileCreate(FSP_FILE_SYSTEM *FileSystem, if (!NT_SUCCESS(Result)) return Result; - FileNode = 0; + FullContext.UserContext = 0; + FullContext.UserContext2 = 0; memset(&OpenFileInfo, 0, sizeof OpenFileInfo); OpenFileInfo.NormalizedName = (PVOID)Response->Buffer; OpenFileInfo.NormalizedNameSize = FSP_FSCTL_TRANSACT_RSP_BUFFER_SIZEMAX; Result = FileSystem->Interface->Create(FileSystem, (PWSTR)Request->Buffer, Request->Req.Create.CreateOptions, GrantedAccess, Request->Req.Create.FileAttributes, ObjectDescriptor, Request->Req.Create.AllocationSize, - &FileNode, &OpenFileInfo.FileInfo); + AddrOfFileContext(FullContext), &OpenFileInfo.FileInfo); FspDeleteSecurityDescriptor(ObjectDescriptor, FspCreateSecurityDescriptor); if (!NT_SUCCESS(Result)) return Result; @@ -394,7 +403,8 @@ static NTSTATUS FspFileSystemOpCreate_FileCreate(FSP_FILE_SYSTEM *FileSystem, } Response->IoStatus.Information = FILE_CREATED; - USERCONTEXT(Response->Rsp.Create.Opened) = (UINT_PTR)FileNode; + Response->Rsp.Create.Opened.UserContext = FullContext.UserContext; + Response->Rsp.Create.Opened.UserContext2 = FullContext.UserContext2; Response->Rsp.Create.Opened.GrantedAccess = GrantedAccess; memcpy(&Response->Rsp.Create.Opened.FileInfo, &OpenFileInfo.FileInfo, sizeof OpenFileInfo.FileInfo); @@ -406,20 +416,21 @@ static NTSTATUS FspFileSystemOpCreate_FileOpen(FSP_FILE_SYSTEM *FileSystem, { NTSTATUS Result; UINT32 GrantedAccess; - PVOID FileNode; + FSP_FSCTL_TRANSACT_FULL_CONTEXT FullContext; FSP_FSCTL_OPEN_FILE_INFO OpenFileInfo; Result = FspFileSystemOpenCheck(FileSystem, Request, Response, TRUE, &GrantedAccess); if (!NT_SUCCESS(Result) || STATUS_REPARSE == Result) return Result; - FileNode = 0; + FullContext.UserContext = 0; + FullContext.UserContext2 = 0; memset(&OpenFileInfo, 0, sizeof OpenFileInfo); OpenFileInfo.NormalizedName = (PVOID)Response->Buffer; OpenFileInfo.NormalizedNameSize = FSP_FSCTL_TRANSACT_RSP_BUFFER_SIZEMAX; Result = FileSystem->Interface->Open(FileSystem, (PWSTR)Request->Buffer, Request->Req.Create.CreateOptions, GrantedAccess, - &FileNode, &OpenFileInfo.FileInfo); + AddrOfFileContext(FullContext), &OpenFileInfo.FileInfo); if (!NT_SUCCESS(Result)) return Result; @@ -431,7 +442,8 @@ static NTSTATUS FspFileSystemOpCreate_FileOpen(FSP_FILE_SYSTEM *FileSystem, } Response->IoStatus.Information = FILE_OPENED; - USERCONTEXT(Response->Rsp.Create.Opened) = (UINT_PTR)FileNode; + Response->Rsp.Create.Opened.UserContext = FullContext.UserContext; + Response->Rsp.Create.Opened.UserContext2 = FullContext.UserContext2; Response->Rsp.Create.Opened.GrantedAccess = GrantedAccess; memcpy(&Response->Rsp.Create.Opened.FileInfo, &OpenFileInfo.FileInfo, sizeof OpenFileInfo.FileInfo); @@ -444,7 +456,7 @@ static NTSTATUS FspFileSystemOpCreate_FileOpenIf(FSP_FILE_SYSTEM *FileSystem, NTSTATUS Result; UINT32 GrantedAccess; PSECURITY_DESCRIPTOR ParentDescriptor, ObjectDescriptor; - PVOID FileNode; + FSP_FSCTL_TRANSACT_FULL_CONTEXT FullContext; FSP_FSCTL_OPEN_FILE_INFO OpenFileInfo; BOOLEAN Create = FALSE; @@ -458,13 +470,14 @@ static NTSTATUS FspFileSystemOpCreate_FileOpenIf(FSP_FILE_SYSTEM *FileSystem, if (!Create) { - FileNode = 0; + FullContext.UserContext = 0; + FullContext.UserContext2 = 0; memset(&OpenFileInfo, 0, sizeof OpenFileInfo); OpenFileInfo.NormalizedName = (PVOID)Response->Buffer; OpenFileInfo.NormalizedNameSize = FSP_FSCTL_TRANSACT_RSP_BUFFER_SIZEMAX; Result = FileSystem->Interface->Open(FileSystem, (PWSTR)Request->Buffer, Request->Req.Create.CreateOptions, GrantedAccess, - &FileNode, &OpenFileInfo.FileInfo); + AddrOfFileContext(FullContext), &OpenFileInfo.FileInfo); if (!NT_SUCCESS(Result)) { if (STATUS_OBJECT_NAME_NOT_FOUND != Result) @@ -485,14 +498,15 @@ static NTSTATUS FspFileSystemOpCreate_FileOpenIf(FSP_FILE_SYSTEM *FileSystem, if (!NT_SUCCESS(Result)) return Result; - FileNode = 0; + FullContext.UserContext = 0; + FullContext.UserContext2 = 0; memset(&OpenFileInfo, 0, sizeof OpenFileInfo); OpenFileInfo.NormalizedName = (PVOID)Response->Buffer; OpenFileInfo.NormalizedNameSize = FSP_FSCTL_TRANSACT_RSP_BUFFER_SIZEMAX; Result = FileSystem->Interface->Create(FileSystem, (PWSTR)Request->Buffer, Request->Req.Create.CreateOptions, GrantedAccess, Request->Req.Create.FileAttributes, ObjectDescriptor, Request->Req.Create.AllocationSize, - &FileNode, &OpenFileInfo.FileInfo); + AddrOfFileContext(FullContext), &OpenFileInfo.FileInfo); FspDeleteSecurityDescriptor(ObjectDescriptor, FspCreateSecurityDescriptor); if (!NT_SUCCESS(Result)) return Result; @@ -506,7 +520,8 @@ static NTSTATUS FspFileSystemOpCreate_FileOpenIf(FSP_FILE_SYSTEM *FileSystem, } Response->IoStatus.Information = Create ? FILE_CREATED : FILE_OPENED; - USERCONTEXT(Response->Rsp.Create.Opened) = (UINT_PTR)FileNode; + Response->Rsp.Create.Opened.UserContext = FullContext.UserContext; + Response->Rsp.Create.Opened.UserContext2 = FullContext.UserContext2; Response->Rsp.Create.Opened.GrantedAccess = GrantedAccess; memcpy(&Response->Rsp.Create.Opened.FileInfo, &OpenFileInfo.FileInfo, sizeof OpenFileInfo.FileInfo); @@ -518,7 +533,7 @@ static NTSTATUS FspFileSystemOpCreate_FileOverwrite(FSP_FILE_SYSTEM *FileSystem, { NTSTATUS Result; UINT32 GrantedAccess; - PVOID FileNode; + FSP_FSCTL_TRANSACT_FULL_CONTEXT FullContext; FSP_FSCTL_OPEN_FILE_INFO OpenFileInfo; BOOLEAN Supersede = FILE_SUPERSEDE == ((Request->Req.Create.CreateOptions >> 24) & 0xff); @@ -526,13 +541,14 @@ static NTSTATUS FspFileSystemOpCreate_FileOverwrite(FSP_FILE_SYSTEM *FileSystem, if (!NT_SUCCESS(Result) || STATUS_REPARSE == Result) return Result; - FileNode = 0; + FullContext.UserContext = 0; + FullContext.UserContext2 = 0; memset(&OpenFileInfo, 0, sizeof OpenFileInfo); OpenFileInfo.NormalizedName = (PVOID)Response->Buffer; OpenFileInfo.NormalizedNameSize = FSP_FSCTL_TRANSACT_RSP_BUFFER_SIZEMAX; Result = FileSystem->Interface->Open(FileSystem, (PWSTR)Request->Buffer, Request->Req.Create.CreateOptions, GrantedAccess, - &FileNode, &OpenFileInfo.FileInfo); + AddrOfFileContext(FullContext), &OpenFileInfo.FileInfo); if (!NT_SUCCESS(Result)) return Result; @@ -544,7 +560,8 @@ static NTSTATUS FspFileSystemOpCreate_FileOverwrite(FSP_FILE_SYSTEM *FileSystem, } Response->IoStatus.Information = Supersede ? FILE_SUPERSEDED : FILE_OVERWRITTEN; - USERCONTEXT(Response->Rsp.Create.Opened) = (UINT_PTR)FileNode; + Response->Rsp.Create.Opened.UserContext = FullContext.UserContext; + Response->Rsp.Create.Opened.UserContext2 = FullContext.UserContext2; Response->Rsp.Create.Opened.GrantedAccess = GrantedAccess; memcpy(&Response->Rsp.Create.Opened.FileInfo, &OpenFileInfo.FileInfo, sizeof OpenFileInfo.FileInfo); @@ -557,7 +574,7 @@ static NTSTATUS FspFileSystemOpCreate_FileOverwriteIf(FSP_FILE_SYSTEM *FileSyste NTSTATUS Result; UINT32 GrantedAccess; PSECURITY_DESCRIPTOR ParentDescriptor, ObjectDescriptor; - PVOID FileNode; + FSP_FSCTL_TRANSACT_FULL_CONTEXT FullContext; FSP_FSCTL_OPEN_FILE_INFO OpenFileInfo; BOOLEAN Create = FALSE; @@ -571,13 +588,14 @@ static NTSTATUS FspFileSystemOpCreate_FileOverwriteIf(FSP_FILE_SYSTEM *FileSyste if (!Create) { - FileNode = 0; + FullContext.UserContext = 0; + FullContext.UserContext2 = 0; memset(&OpenFileInfo, 0, sizeof OpenFileInfo); OpenFileInfo.NormalizedName = (PVOID)Response->Buffer; OpenFileInfo.NormalizedNameSize = FSP_FSCTL_TRANSACT_RSP_BUFFER_SIZEMAX; Result = FileSystem->Interface->Open(FileSystem, (PWSTR)Request->Buffer, Request->Req.Create.CreateOptions, GrantedAccess, - &FileNode, &OpenFileInfo.FileInfo); + AddrOfFileContext(FullContext), &OpenFileInfo.FileInfo); if (!NT_SUCCESS(Result)) { if (STATUS_OBJECT_NAME_NOT_FOUND != Result) @@ -598,14 +616,15 @@ static NTSTATUS FspFileSystemOpCreate_FileOverwriteIf(FSP_FILE_SYSTEM *FileSyste if (!NT_SUCCESS(Result)) return Result; - FileNode = 0; + FullContext.UserContext = 0; + FullContext.UserContext2 = 0; memset(&OpenFileInfo, 0, sizeof OpenFileInfo); OpenFileInfo.NormalizedName = (PVOID)Response->Buffer; OpenFileInfo.NormalizedNameSize = FSP_FSCTL_TRANSACT_RSP_BUFFER_SIZEMAX; Result = FileSystem->Interface->Create(FileSystem, (PWSTR)Request->Buffer, Request->Req.Create.CreateOptions, GrantedAccess, Request->Req.Create.FileAttributes, ObjectDescriptor, Request->Req.Create.AllocationSize, - &FileNode, &OpenFileInfo.FileInfo); + AddrOfFileContext(FullContext), &OpenFileInfo.FileInfo); FspDeleteSecurityDescriptor(ObjectDescriptor, FspCreateSecurityDescriptor); if (!NT_SUCCESS(Result)) return Result; @@ -619,7 +638,8 @@ static NTSTATUS FspFileSystemOpCreate_FileOverwriteIf(FSP_FILE_SYSTEM *FileSyste } Response->IoStatus.Information = Create ? FILE_CREATED : FILE_OVERWRITTEN; - USERCONTEXT(Response->Rsp.Create.Opened) = (UINT_PTR)FileNode; + Response->Rsp.Create.Opened.UserContext = FullContext.UserContext; + Response->Rsp.Create.Opened.UserContext2 = FullContext.UserContext2; Response->Rsp.Create.Opened.GrantedAccess = GrantedAccess; memcpy(&Response->Rsp.Create.Opened.FileInfo, &OpenFileInfo.FileInfo, sizeof OpenFileInfo.FileInfo); @@ -633,7 +653,7 @@ static NTSTATUS FspFileSystemOpCreate_FileOpenTargetDirectory(FSP_FILE_SYSTEM *F WCHAR Root[2] = L"\\"; PWSTR Parent, Suffix; UINT32 GrantedAccess; - PVOID FileNode; + FSP_FSCTL_TRANSACT_FULL_CONTEXT FullContext; FSP_FSCTL_OPEN_FILE_INFO OpenFileInfo; UINT32 Information; @@ -641,14 +661,15 @@ static NTSTATUS FspFileSystemOpCreate_FileOpenTargetDirectory(FSP_FILE_SYSTEM *F if (!NT_SUCCESS(Result) || STATUS_REPARSE == Result) return Result; - FileNode = 0; + FullContext.UserContext = 0; + FullContext.UserContext2 = 0; memset(&OpenFileInfo, 0, sizeof OpenFileInfo); OpenFileInfo.NormalizedName = (PVOID)Response->Buffer; OpenFileInfo.NormalizedNameSize = FSP_FSCTL_TRANSACT_RSP_BUFFER_SIZEMAX; FspPathSuffix((PWSTR)Request->Buffer, &Parent, &Suffix, Root); Result = FileSystem->Interface->Open(FileSystem, Parent, Request->Req.Create.CreateOptions, GrantedAccess, - &FileNode, &OpenFileInfo.FileInfo); + AddrOfFileContext(FullContext), &OpenFileInfo.FileInfo); FspPathCombine((PWSTR)Request->Buffer, Suffix); if (!NT_SUCCESS(Result)) return Result; @@ -668,7 +689,8 @@ static NTSTATUS FspFileSystemOpCreate_FileOpenTargetDirectory(FSP_FILE_SYSTEM *F } Response->IoStatus.Information = Information; - USERCONTEXT(Response->Rsp.Create.Opened) = (UINT_PTR)FileNode; + Response->Rsp.Create.Opened.UserContext = FullContext.UserContext; + Response->Rsp.Create.Opened.UserContext2 = FullContext.UserContext2; Response->Rsp.Create.Opened.GrantedAccess = GrantedAccess; memcpy(&Response->Rsp.Create.Opened.FileInfo, &OpenFileInfo.FileInfo, sizeof OpenFileInfo.FileInfo); @@ -816,7 +838,7 @@ FSP_API NTSTATUS FspFileSystemOpOverwrite(FSP_FILE_SYSTEM *FileSystem, memset(&FileInfo, 0, sizeof FileInfo); Result = FileSystem->Interface->Overwrite(FileSystem, - (PVOID)USERCONTEXT(Request->Req.Overwrite), + (PVOID)ValOfFileContext(Request->Req.Overwrite), Request->Req.Overwrite.FileAttributes, Request->Req.Overwrite.Supersede, &FileInfo); @@ -824,7 +846,7 @@ FSP_API NTSTATUS FspFileSystemOpOverwrite(FSP_FILE_SYSTEM *FileSystem, { if (0 != FileSystem->Interface->Close) FileSystem->Interface->Close(FileSystem, - (PVOID)USERCONTEXT(Request->Req.Overwrite)); + (PVOID)ValOfFileContext(Request->Req.Overwrite)); return Result; } @@ -837,7 +859,7 @@ FSP_API NTSTATUS FspFileSystemOpCleanup(FSP_FILE_SYSTEM *FileSystem, { if (0 != FileSystem->Interface->Cleanup) FileSystem->Interface->Cleanup(FileSystem, - (PVOID)USERCONTEXT(Request->Req.Cleanup), + (PVOID)ValOfFileContext(Request->Req.Cleanup), 0 != Request->FileName.Size ? (PWSTR)Request->Buffer : 0, 0 != Request->Req.Cleanup.Delete); @@ -849,7 +871,7 @@ FSP_API NTSTATUS FspFileSystemOpClose(FSP_FILE_SYSTEM *FileSystem, { if (0 != FileSystem->Interface->Close) FileSystem->Interface->Close(FileSystem, - (PVOID)USERCONTEXT(Request->Req.Close)); + (PVOID)ValOfFileContext(Request->Req.Close)); return STATUS_SUCCESS; } @@ -865,7 +887,7 @@ FSP_API NTSTATUS FspFileSystemOpRead(FSP_FILE_SYSTEM *FileSystem, BytesTransferred = 0; Result = FileSystem->Interface->Read(FileSystem, - (PVOID)USERCONTEXT(Request->Req.Read), + (PVOID)ValOfFileContext(Request->Req.Read), (PVOID)Request->Req.Read.Address, Request->Req.Read.Offset, Request->Req.Read.Length, @@ -891,7 +913,7 @@ FSP_API NTSTATUS FspFileSystemOpWrite(FSP_FILE_SYSTEM *FileSystem, BytesTransferred = 0; Result = FileSystem->Interface->Write(FileSystem, - (PVOID)USERCONTEXT(Request->Req.Write), + (PVOID)ValOfFileContext(Request->Req.Write), (PVOID)Request->Req.Write.Address, Request->Req.Write.Offset, Request->Req.Write.Length, @@ -918,7 +940,7 @@ FSP_API NTSTATUS FspFileSystemOpFlushBuffers(FSP_FILE_SYSTEM *FileSystem, return STATUS_SUCCESS; /* liar! */ return FileSystem->Interface->Flush(FileSystem, - (PVOID)USERCONTEXT(Request->Req.FlushBuffers)); + (PVOID)ValOfFileContext(Request->Req.FlushBuffers)); } FSP_API NTSTATUS FspFileSystemOpQueryInformation(FSP_FILE_SYSTEM *FileSystem, @@ -932,7 +954,7 @@ FSP_API NTSTATUS FspFileSystemOpQueryInformation(FSP_FILE_SYSTEM *FileSystem, memset(&FileInfo, 0, sizeof FileInfo); Result = FileSystem->Interface->GetFileInfo(FileSystem, - (PVOID)USERCONTEXT(Request->Req.QueryInformation), &FileInfo); + (PVOID)ValOfFileContext(Request->Req.QueryInformation), &FileInfo); if (!NT_SUCCESS(Result)) return Result; @@ -953,7 +975,7 @@ FSP_API NTSTATUS FspFileSystemOpSetInformation(FSP_FILE_SYSTEM *FileSystem, case 4/*FileBasicInformation*/: if (0 != FileSystem->Interface->SetBasicInfo) Result = FileSystem->Interface->SetBasicInfo(FileSystem, - (PVOID)USERCONTEXT(Request->Req.SetInformation), + (PVOID)ValOfFileContext(Request->Req.SetInformation), Request->Req.SetInformation.Info.Basic.FileAttributes, Request->Req.SetInformation.Info.Basic.CreationTime, Request->Req.SetInformation.Info.Basic.LastAccessTime, @@ -963,14 +985,14 @@ FSP_API NTSTATUS FspFileSystemOpSetInformation(FSP_FILE_SYSTEM *FileSystem, case 19/*FileAllocationInformation*/: if (0 != FileSystem->Interface->SetFileSize) Result = FileSystem->Interface->SetFileSize(FileSystem, - (PVOID)USERCONTEXT(Request->Req.SetInformation), + (PVOID)ValOfFileContext(Request->Req.SetInformation), Request->Req.SetInformation.Info.Allocation.AllocationSize, TRUE, &FileInfo); break; case 20/*FileEndOfFileInformation*/: if (0 != FileSystem->Interface->SetFileSize) Result = FileSystem->Interface->SetFileSize(FileSystem, - (PVOID)USERCONTEXT(Request->Req.SetInformation), + (PVOID)ValOfFileContext(Request->Req.SetInformation), Request->Req.SetInformation.Info.EndOfFile.FileSize, FALSE, &FileInfo); break; @@ -978,7 +1000,7 @@ FSP_API NTSTATUS FspFileSystemOpSetInformation(FSP_FILE_SYSTEM *FileSystem, if (0 != FileSystem->Interface->GetFileInfo) { Result = FileSystem->Interface->GetFileInfo(FileSystem, - (PVOID)USERCONTEXT(Request->Req.SetInformation), &FileInfo); + (PVOID)ValOfFileContext(Request->Req.SetInformation), &FileInfo); if (NT_SUCCESS(Result) && 0 != (FileInfo.FileAttributes & FILE_ATTRIBUTE_READONLY)) { Result = STATUS_CANNOT_DELETE; @@ -988,7 +1010,7 @@ FSP_API NTSTATUS FspFileSystemOpSetInformation(FSP_FILE_SYSTEM *FileSystem, if (0 != FileSystem->Interface->CanDelete) if (Request->Req.SetInformation.Info.Disposition.Delete) Result = FileSystem->Interface->CanDelete(FileSystem, - (PVOID)USERCONTEXT(Request->Req.SetInformation), + (PVOID)ValOfFileContext(Request->Req.SetInformation), (PWSTR)Request->Buffer); else Result = STATUS_SUCCESS; @@ -1005,7 +1027,7 @@ FSP_API NTSTATUS FspFileSystemOpSetInformation(FSP_FILE_SYSTEM *FileSystem, break; } Result = FileSystem->Interface->Rename(FileSystem, - (PVOID)USERCONTEXT(Request->Req.SetInformation), + (PVOID)ValOfFileContext(Request->Req.SetInformation), (PWSTR)Request->Buffer, (PWSTR)(Request->Buffer + Request->Req.SetInformation.Info.Rename.NewFileName.Offset), 0 != Request->Req.SetInformation.Info.Rename.AccessToken); @@ -1074,7 +1096,7 @@ FSP_API NTSTATUS FspFileSystemOpQueryDirectory(FSP_FILE_SYSTEM *FileSystem, BytesTransferred = 0; Result = FileSystem->Interface->ReadDirectory(FileSystem, - (PVOID)USERCONTEXT(Request->Req.QueryDirectory), + (PVOID)ValOfFileContext(Request->Req.QueryDirectory), (PVOID)Request->Req.QueryDirectory.Address, Request->Req.QueryDirectory.Offset, Request->Req.QueryDirectory.Length, @@ -1108,7 +1130,7 @@ FSP_API NTSTATUS FspFileSystemOpFileSystemControl(FSP_FILE_SYSTEM *FileSystem, Size = FSP_FSCTL_TRANSACT_RSP_BUFFER_SIZEMAX; Result = FileSystem->Interface->GetReparsePoint(FileSystem, - (PVOID)USERCONTEXT(Request->Req.FileSystemControl), + (PVOID)ValOfFileContext(Request->Req.FileSystemControl), (PWSTR)Request->Buffer, ReparseData, &Size); if (NT_SUCCESS(Result)) { @@ -1125,7 +1147,7 @@ FSP_API NTSTATUS FspFileSystemOpFileSystemControl(FSP_FILE_SYSTEM *FileSystem, (Request->Buffer + Request->Req.FileSystemControl.Buffer.Offset); Result = FileSystem->Interface->SetReparsePoint(FileSystem, - (PVOID)USERCONTEXT(Request->Req.FileSystemControl), + (PVOID)ValOfFileContext(Request->Req.FileSystemControl), (PWSTR)Request->Buffer, ReparseData, Request->Req.FileSystemControl.Buffer.Size); @@ -1138,7 +1160,7 @@ FSP_API NTSTATUS FspFileSystemOpFileSystemControl(FSP_FILE_SYSTEM *FileSystem, (Request->Buffer + Request->Req.FileSystemControl.Buffer.Offset); Result = FileSystem->Interface->DeleteReparsePoint(FileSystem, - (PVOID)USERCONTEXT(Request->Req.FileSystemControl), + (PVOID)ValOfFileContext(Request->Req.FileSystemControl), (PWSTR)Request->Buffer, ReparseData, Request->Req.FileSystemControl.Buffer.Size); @@ -1160,7 +1182,7 @@ FSP_API NTSTATUS FspFileSystemOpQuerySecurity(FSP_FILE_SYSTEM *FileSystem, SecurityDescriptorSize = FSP_FSCTL_TRANSACT_RSP_BUFFER_SIZEMAX; Result = FileSystem->Interface->GetSecurity(FileSystem, - (PVOID)USERCONTEXT(Request->Req.QuerySecurity), + (PVOID)ValOfFileContext(Request->Req.QuerySecurity), Response->Buffer, &SecurityDescriptorSize); if (!NT_SUCCESS(Result)) return STATUS_BUFFER_OVERFLOW != Result ? Result : STATUS_INVALID_SECURITY_DESCR; @@ -1178,7 +1200,7 @@ FSP_API NTSTATUS FspFileSystemOpSetSecurity(FSP_FILE_SYSTEM *FileSystem, return STATUS_INVALID_DEVICE_REQUEST; return FileSystem->Interface->SetSecurity(FileSystem, - (PVOID)USERCONTEXT(Request->Req.SetSecurity), + (PVOID)ValOfFileContext(Request->Req.SetSecurity), Request->Req.SetSecurity.SecurityInformation, (PSECURITY_DESCRIPTOR)Request->Buffer, (HANDLE)Request->Req.SetSecurity.AccessToken); @@ -1195,7 +1217,7 @@ FSP_API NTSTATUS FspFileSystemOpQueryStreamInformation(FSP_FILE_SYSTEM *FileSyst BytesTransferred = 0; Result = FileSystem->Interface->GetStreamInfo(FileSystem, - (PVOID)USERCONTEXT(Request->Req.QueryStreamInformation), + (PVOID)ValOfFileContext(Request->Req.QueryStreamInformation), Response->Buffer, FSP_FSCTL_TRANSACT_RSP_BUFFER_SIZEMAX, &BytesTransferred); diff --git a/src/dll/fuse/fuse.c b/src/dll/fuse/fuse.c index 84de2836..3b08e35f 100644 --- a/src/dll/fuse/fuse.c +++ b/src/dll/fuse/fuse.c @@ -524,7 +524,7 @@ FSP_FUSE_API struct fuse *fsp_fuse_new(struct fsp_fuse_env *env, opt_data.VolumeParams.NamedStreams = FALSE; opt_data.VolumeParams.ReadOnlyVolume = !!opt_data.ReadOnlyVolume; opt_data.VolumeParams.PostCleanupOnDeleteOnly = TRUE; - opt_data.VolumeParams.UmFileNodeIsUserContext2 = TRUE; + opt_data.VolumeParams.UmFileContextIsUserContext2 = TRUE; if (L'\0' == opt_data.VolumeParams.FileSystemName[0]) memcpy(opt_data.VolumeParams.FileSystemName, L"FUSE", 5 * sizeof(WCHAR));