mirror of
https://github.com/winfsp/winfsp.git
synced 2025-04-22 16:33:02 -05:00
tst: passthrough: use FspFileSystem*DirectoryBuffer API's
This commit is contained in:
parent
55a7864173
commit
7288605f65
@ -39,7 +39,6 @@ typedef struct
|
|||||||
{
|
{
|
||||||
HANDLE Handle;
|
HANDLE Handle;
|
||||||
PVOID DirBuffer;
|
PVOID DirBuffer;
|
||||||
ULONG DirBufferCapacity, DirBufferLength;
|
|
||||||
} PTFS_FILE_CONTEXT;
|
} PTFS_FILE_CONTEXT;
|
||||||
|
|
||||||
static NTSTATUS GetFileInfoInternal(HANDLE Handle, FSP_FSCTL_FILE_INFO *FileInfo)
|
static NTSTATUS GetFileInfoInternal(HANDLE Handle, FSP_FSCTL_FILE_INFO *FileInfo)
|
||||||
@ -299,13 +298,14 @@ static VOID Cleanup(FSP_FILE_SYSTEM *FileSystem,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static VOID Close(FSP_FILE_SYSTEM *FileSystem,
|
static VOID Close(FSP_FILE_SYSTEM *FileSystem,
|
||||||
PVOID FileContext)
|
PVOID FileContext0)
|
||||||
{
|
{
|
||||||
|
PTFS_FILE_CONTEXT *FileContext = FileContext0;
|
||||||
HANDLE Handle = HandleFromContext(FileContext);
|
HANDLE Handle = HandleFromContext(FileContext);
|
||||||
|
|
||||||
CloseHandle(Handle);
|
CloseHandle(Handle);
|
||||||
|
|
||||||
free(((PTFS_FILE_CONTEXT *)FileContext)->DirBuffer);
|
FspFileSystemDeleteDirectoryBuffer(&FileContext->DirBuffer);
|
||||||
free(FileContext);
|
free(FileContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -510,29 +510,9 @@ static NTSTATUS SetSecurity(FSP_FILE_SYSTEM *FileSystem,
|
|||||||
return STATUS_SUCCESS;
|
return STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static BOOLEAN AddDirInfo(PTFS_FILE_CONTEXT *FileContext, FSP_FSCTL_DIR_INFO *DirInfo)
|
|
||||||
{
|
|
||||||
while (!FspFileSystemAddDirInfo(DirInfo,
|
|
||||||
FileContext->DirBuffer, FileContext->DirBufferCapacity, &FileContext->DirBufferLength))
|
|
||||||
{
|
|
||||||
PVOID Buffer;
|
|
||||||
ULONG Capacity = FileContext->DirBufferCapacity ? FileContext->DirBufferCapacity * 2 : 256;
|
|
||||||
|
|
||||||
Buffer = realloc(FileContext->DirBuffer, Capacity);
|
|
||||||
if (0 == Buffer)
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
FileContext->DirBuffer = Buffer;
|
|
||||||
FileContext->DirBufferCapacity = Capacity;
|
|
||||||
}
|
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static NTSTATUS ReadDirectory(FSP_FILE_SYSTEM *FileSystem,
|
static NTSTATUS ReadDirectory(FSP_FILE_SYSTEM *FileSystem,
|
||||||
PVOID FileContext0, PVOID Buffer, UINT64 Offset, ULONG BufferLength,
|
PVOID FileContext0, PWSTR Pattern, PWSTR Marker,
|
||||||
PWSTR Pattern,
|
PVOID Buffer, ULONG BufferLength, PULONG PBytesTransferred)
|
||||||
PULONG PBytesTransferred)
|
|
||||||
{
|
{
|
||||||
PTFS *Ptfs = (PTFS *)FileSystem->UserContext;
|
PTFS *Ptfs = (PTFS *)FileSystem->UserContext;
|
||||||
PTFS_FILE_CONTEXT *FileContext = FileContext0;
|
PTFS_FILE_CONTEXT *FileContext = FileContext0;
|
||||||
@ -547,9 +527,10 @@ static NTSTATUS ReadDirectory(FSP_FILE_SYSTEM *FileSystem,
|
|||||||
FSP_FSCTL_DIR_INFO D;
|
FSP_FSCTL_DIR_INFO D;
|
||||||
} DirInfoBuf;
|
} DirInfoBuf;
|
||||||
FSP_FSCTL_DIR_INFO *DirInfo = &DirInfoBuf.D;
|
FSP_FSCTL_DIR_INFO *DirInfo = &DirInfoBuf.D;
|
||||||
UINT64 NextOffset = 0;
|
NTSTATUS DirBufferResult;
|
||||||
|
|
||||||
if (0 == Offset)
|
DirBufferResult = STATUS_SUCCESS;
|
||||||
|
if (FspFileSystemAcquireDirectoryBuffer(&FileContext->DirBuffer, 0 == Marker, &DirBufferResult))
|
||||||
{
|
{
|
||||||
if (0 == Pattern)
|
if (0 == Pattern)
|
||||||
Pattern = L"*";
|
Pattern = L"*";
|
||||||
@ -586,33 +567,24 @@ static NTSTATUS ReadDirectory(FSP_FILE_SYSTEM *FileSystem,
|
|||||||
DirInfo->FileInfo.ChangeTime = DirInfo->FileInfo.LastWriteTime;
|
DirInfo->FileInfo.ChangeTime = DirInfo->FileInfo.LastWriteTime;
|
||||||
DirInfo->FileInfo.IndexNumber = 0;
|
DirInfo->FileInfo.IndexNumber = 0;
|
||||||
DirInfo->FileInfo.HardLinks = 0;
|
DirInfo->FileInfo.HardLinks = 0;
|
||||||
DirInfo->NextOffset = (NextOffset += FSP_FSCTL_DEFAULT_ALIGN_UP(DirInfo->Size));
|
|
||||||
memcpy(DirInfo->FileNameBuf, FindData.cFileName, Length * sizeof(WCHAR));
|
memcpy(DirInfo->FileNameBuf, FindData.cFileName, Length * sizeof(WCHAR));
|
||||||
|
|
||||||
if (!AddDirInfo(FileContext, DirInfo))
|
if (!FspFileSystemFillDirectoryBuffer(&FileContext->DirBuffer, DirInfo, &DirBufferResult))
|
||||||
break;
|
break;
|
||||||
} while (FindNextFileW(FindHandle, &FindData));
|
} while (FindNextFileW(FindHandle, &FindData));
|
||||||
|
|
||||||
FindClose(FindHandle);
|
FindClose(FindHandle);
|
||||||
|
|
||||||
if (!AddDirInfo(FileContext, 0))
|
|
||||||
return STATUS_INSUFFICIENT_RESOURCES;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FspFileSystemReleaseDirectoryBuffer(&FileContext->DirBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (0 != FileContext->DirBuffer)
|
if (!NT_SUCCESS(DirBufferResult))
|
||||||
{
|
return DirBufferResult;
|
||||||
for (DirInfo = (PVOID)((PUINT8)FileContext->DirBuffer + Offset);
|
|
||||||
0 != DirInfo->Size;
|
FspFileSystemReadDirectoryBuffer(&FileContext->DirBuffer,
|
||||||
DirInfo = (PVOID)((PUINT8)DirInfo + FSP_FSCTL_DEFAULT_ALIGN_UP(DirInfo->Size)))
|
Marker, Buffer, BufferLength, PBytesTransferred);
|
||||||
{
|
|
||||||
if (!FspFileSystemAddDirInfo(DirInfo, Buffer, BufferLength, PBytesTransferred))
|
|
||||||
return STATUS_SUCCESS;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* add "End-Of-Listing" marker */
|
|
||||||
FspFileSystemAddDirInfo(0, Buffer, BufferLength, PBytesTransferred);
|
|
||||||
return STATUS_SUCCESS;
|
return STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user