From 68795652b31f24b8f6370a920a892cc390693533 Mon Sep 17 00:00:00 2001 From: Bill Zissimopoulos Date: Fri, 22 Jan 2016 16:39:46 -0800 Subject: [PATCH] sys: Create requests now send additional information on response --- inc/winfsp/fsctl.h | 9 +++++- inc/winfsp/winfsp.h | 6 ++++ src/dll/create.c | 6 ++++ tst/winfsp-tests/memfs.cpp | 57 +++++++++++++++++++++++--------------- 4 files changed, 54 insertions(+), 24 deletions(-) diff --git a/inc/winfsp/fsctl.h b/inc/winfsp/fsctl.h index 8cc102f7..d9a74d22 100644 --- a/inc/winfsp/fsctl.h +++ b/inc/winfsp/fsctl.h @@ -164,12 +164,19 @@ typedef struct /* IoStatus.Status == STATUS_SUCCESS */ struct { - UINT64 UserContext; /* user context (unique file id) associated with file node */ + UINT64 UserContext; /* user context associated with file node */ UINT64 UserContext2; /* user context associated with file descriptor (handle) */ UINT32 FileAttributes; /* file attributes of opened file */ + UINT32 ReparseTag; /* reparse tag of opened file (FILE_ATTRIBUTE_REPARSE_POINT) */ UINT64 AllocationSize; /* file allocation size */ UINT64 FileSize; /* file size */ + UINT64 CreationTime; + UINT64 LastAccessTime; + UINT64 LastWriteTime; + UINT64 ChangeTime; + UINT64 IndexNumber; /* unique file id */ UINT32 GrantedAccess; /* FILE_{READ_DATA,WRITE_DATA,etc.} */ + } Opened; /* IoStatus.Status == STATUS_REPARSE */ struct diff --git a/inc/winfsp/winfsp.h b/inc/winfsp/winfsp.h index 8410e5af..ebdc487d 100644 --- a/inc/winfsp/winfsp.h +++ b/inc/winfsp/winfsp.h @@ -35,8 +35,14 @@ typedef struct _FSP_FILE_NODE_INFO { PVOID FileNode; DWORD FileAttributes; + DWORD ReparseTag; UINT64 AllocationSize; UINT64 FileSize; + UINT64 CreationTime; + UINT64 LastAccessTime; + UINT64 LastWriteTime; + UINT64 ChangeTime; + UINT64 IndexNumber; } FSP_FILE_NODE_INFO; typedef struct _FSP_FILE_SIZE_INFO { diff --git a/src/dll/create.c b/src/dll/create.c index 0b1ba07b..1abcd48b 100644 --- a/src/dll/create.c +++ b/src/dll/create.c @@ -574,8 +574,14 @@ FSP_API NTSTATUS FspFileSystemSendCreateResponse(FSP_FILE_SYSTEM *FileSystem, Response.IoStatus.Information = Information; Response.Rsp.Create.Opened.UserContext = (UINT_PTR)NodeInfo->FileNode; Response.Rsp.Create.Opened.FileAttributes = NodeInfo->FileAttributes; + Response.Rsp.Create.Opened.ReparseTag = NodeInfo->ReparseTag; Response.Rsp.Create.Opened.AllocationSize = NodeInfo->AllocationSize; Response.Rsp.Create.Opened.FileSize = NodeInfo->FileSize; + Response.Rsp.Create.Opened.CreationTime = NodeInfo->CreationTime; + Response.Rsp.Create.Opened.LastAccessTime = NodeInfo->LastAccessTime; + Response.Rsp.Create.Opened.LastWriteTime = NodeInfo->LastWriteTime; + Response.Rsp.Create.Opened.ChangeTime = NodeInfo->ChangeTime; + Response.Rsp.Create.Opened.IndexNumber = NodeInfo->IndexNumber; Response.Rsp.Create.Opened.GrantedAccess = GrantedAccess; return FspFileSystemSendResponse(FileSystem, &Response); } diff --git a/tst/winfsp-tests/memfs.cpp b/tst/winfsp-tests/memfs.cpp index fc9bd854..501277fd 100644 --- a/tst/winfsp-tests/memfs.cpp +++ b/tst/winfsp-tests/memfs.cpp @@ -10,6 +10,14 @@ #define MEMFS_SECTOR_SIZE 512 +static inline +UINT64 MemfsGetSystemTime(VOID) +{ + FILETIME FileTime; + GetSystemTimeAsFileTime(&FileTime); + return ((PLARGE_INTEGER)&FileTime)->QuadPart; +} + static inline int MemfsFileNameCompare(PWSTR a, PWSTR b) { @@ -19,11 +27,9 @@ int MemfsFileNameCompare(PWSTR a, PWSTR b) typedef struct _MEMFS_FILE_NODE { WCHAR FileName[MAX_PATH]; - DWORD FileAttributes; + FSP_FILE_NODE_INFO NodeInfo; SIZE_T FileSecuritySize; PVOID FileSecurity; - ULONG AllocationSize; - ULONG FileSize; PVOID FileData; ULONG RefCount; } MEMFS_FILE_NODE; @@ -49,6 +55,7 @@ typedef struct _MEMFS static inline NTSTATUS MemfsFileNodeCreate(PWSTR FileName, MEMFS_FILE_NODE **PFileNode) { + static UINT64 IndexNumber = 1; MEMFS_FILE_NODE *FileNode; *PFileNode = 0; @@ -62,6 +69,12 @@ NTSTATUS MemfsFileNodeCreate(PWSTR FileName, MEMFS_FILE_NODE **PFileNode) memset(FileNode, 0, sizeof *FileNode); wcscpy_s(FileNode->FileName, sizeof FileNode->FileName / sizeof(WCHAR), FileName); + FileNode->NodeInfo.FileNode = FileNode; + FileNode->NodeInfo.CreationTime = + FileNode->NodeInfo.LastAccessTime = + FileNode->NodeInfo.LastWriteTime = + FileNode->NodeInfo.ChangeTime = MemfsGetSystemTime(); + FileNode->NodeInfo.IndexNumber = IndexNumber++; *PFileNode = FileNode; @@ -128,7 +141,7 @@ MEMFS_FILE_NODE *MemfsFileNodeMapGetParent(MEMFS_FILE_NODE_MAP *FileNodeMap, PWS *PResult = STATUS_OBJECT_PATH_NOT_FOUND; return 0; } - if (0 == (iter->second->FileAttributes & FILE_ATTRIBUTE_DIRECTORY)) + if (0 == (iter->second->NodeInfo.FileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { *PResult = STATUS_NOT_A_DIRECTORY; return 0; @@ -192,7 +205,7 @@ static NTSTATUS GetSecurity(FSP_FILE_SYSTEM *FileSystem, } if (0 != PFileAttributes) - *PFileAttributes = FileNode->FileAttributes; + *PFileAttributes = FileNode->NodeInfo.FileAttributes; if (0 != PSecurityDescriptorSize) { @@ -241,7 +254,7 @@ static NTSTATUS Create(FSP_FILE_SYSTEM *FileSystem, if (!NT_SUCCESS(Result)) return Result; - FileNode->FileAttributes = FileAttributes; + FileNode->NodeInfo.FileAttributes = FileAttributes; if (0 != SecurityDescriptor) { @@ -255,10 +268,10 @@ static NTSTATUS Create(FSP_FILE_SYSTEM *FileSystem, memcpy(FileNode->FileSecurity, SecurityDescriptor, FileNode->FileSecuritySize); } - FileNode->AllocationSize = FSP_FSCTL_ALIGN_UP((ULONG)AllocationSize, MEMFS_SECTOR_SIZE); - if (0 != FileNode->AllocationSize) + FileNode->NodeInfo.AllocationSize = FSP_FSCTL_ALIGN_UP((ULONG)AllocationSize, MEMFS_SECTOR_SIZE); + if (0 != FileNode->NodeInfo.AllocationSize) { - FileNode->FileData = malloc(FileNode->AllocationSize); + FileNode->FileData = malloc(FileNode->NodeInfo.AllocationSize); if (0 == FileNode->FileData) { MemfsFileNodeDelete(FileNode); @@ -276,10 +289,7 @@ static NTSTATUS Create(FSP_FILE_SYSTEM *FileSystem, } FileNode->RefCount++; - NodeInfo->FileAttributes = FileNode->FileAttributes; - NodeInfo->AllocationSize = FileNode->AllocationSize; - NodeInfo->FileSize = FileNode->FileSize; - NodeInfo->FileNode = FileNode; + memcpy(NodeInfo, &FileNode->NodeInfo, sizeof *NodeInfo); return STATUS_SUCCESS; } @@ -301,11 +311,10 @@ static NTSTATUS Open(FSP_FILE_SYSTEM *FileSystem, return Result; } + FileNode->NodeInfo.LastAccessTime = MemfsGetSystemTime(); + FileNode->RefCount++; - NodeInfo->FileAttributes = FileNode->FileAttributes; - NodeInfo->AllocationSize = FileNode->AllocationSize; - NodeInfo->FileSize = FileNode->FileSize; - NodeInfo->FileNode = FileNode; + memcpy(NodeInfo, &FileNode->NodeInfo, sizeof *NodeInfo); return STATUS_SUCCESS; } @@ -319,14 +328,16 @@ static NTSTATUS Overwrite(FSP_FILE_SYSTEM *FileSystem, MEMFS_FILE_NODE *FileNode = (MEMFS_FILE_NODE *)FileNode0; if (ReplaceFileAttributes) - FileNode->FileAttributes = FileAttributes; + FileNode->NodeInfo.FileAttributes = FileAttributes; else - FileNode->FileAttributes |= FileAttributes; + FileNode->NodeInfo.FileAttributes |= FileAttributes; - FileNode->FileSize = 0; + FileNode->NodeInfo.FileSize = 0; + FileNode->NodeInfo.LastWriteTime = + FileNode->NodeInfo.LastAccessTime = MemfsGetSystemTime(); - SizeInfo->AllocationSize = FileNode->AllocationSize; - SizeInfo->FileSize = FileNode->FileSize; + SizeInfo->AllocationSize = FileNode->NodeInfo.AllocationSize; + SizeInfo->FileSize = FileNode->NodeInfo.FileSize; return STATUS_SUCCESS; } @@ -435,7 +446,7 @@ NTSTATUS MemfsCreate(ULONG Flags, ULONG MaxFileNodes, ULONG MaxFileSize, return Result; } - RootNode->FileAttributes = FILE_ATTRIBUTE_DIRECTORY; + RootNode->NodeInfo.FileAttributes = FILE_ATTRIBUTE_DIRECTORY; Result = MemfsFileNodeMapInsert(Memfs->FileNodeMap, RootNode, &Inserted); if (!NT_SUCCESS(Result))