tst: ntptfs: SetAllocationSizeOnCleanup

This commit is contained in:
Bill Zissimopoulos 2022-01-21 16:00:52 +00:00
parent f28902dd7b
commit 1ef85d5d3a
No known key found for this signature in database
GPG Key ID: 3D4F95D52C7B3EA3
3 changed files with 52 additions and 14 deletions

View File

@ -122,10 +122,12 @@ static NTSTATUS SvcStart(FSP_SERVICE *Service, ULONG argc, PWSTR *argv)
FsAttributeMask |= PtfsNamedStreams; FsAttributeMask |= PtfsNamedStreams;
else if (0 == _wcsicmp(L"ExtendedAttributes", OptionString)) else if (0 == _wcsicmp(L"ExtendedAttributes", OptionString))
FsAttributeMask |= PtfsExtendedAttributes; FsAttributeMask |= PtfsExtendedAttributes;
else if (0 == _wcsicmp(L"FlushAndPurgeOnCleanup", OptionString))
FsAttributeMask |= PtfsFlushAndPurgeOnCleanup;
else if (0 == _wcsicmp(L"WslFeatures", OptionString)) else if (0 == _wcsicmp(L"WslFeatures", OptionString))
FsAttributeMask |= PtfsWslFeatures; FsAttributeMask |= PtfsWslFeatures;
else if (0 == _wcsicmp(L"FlushAndPurgeOnCleanup", OptionString))
FsAttributeMask |= PtfsFlushAndPurgeOnCleanup;
else if (0 == _wcsicmp(L"SetAllocationSizeOnCleanup", OptionString))
FsAttributeMask |= PtfsSetAllocationSizeOnCleanup;
else else
goto usage; goto usage;
break; break;
@ -247,6 +249,7 @@ usage:
" -o ExtendedAttributes\n" " -o ExtendedAttributes\n"
" -o WslFeatures\n" " -o WslFeatures\n"
" -o FlushAndPurgeOnCleanup\n" " -o FlushAndPurgeOnCleanup\n"
" -o SetAllocationSizeOnCleanup\n"
" -u \\Server\\Share [UNC prefix (single backslash)]\n" " -u \\Server\\Share [UNC prefix (single backslash)]\n"
" -p Directory [directory to expose as pass through file system]\n" " -p Directory [directory to expose as pass through file system]\n"
" -m MountPoint [X:|*|directory]\n"; " -m MountPoint [X:|*|directory]\n";

View File

@ -343,6 +343,7 @@ exit:
static VOID Cleanup(FSP_FILE_SYSTEM *FileSystem, static VOID Cleanup(FSP_FILE_SYSTEM *FileSystem,
PVOID FileContext, PWSTR FileName, ULONG Flags) PVOID FileContext, PWSTR FileName, ULONG Flags)
{ {
PTFS *Ptfs = FileSystemContext;
HANDLE Handle = FileContextHandle; HANDLE Handle = FileContextHandle;
if (Flags & FspCleanupDelete) if (Flags & FspCleanupDelete)
@ -353,6 +354,32 @@ static VOID Cleanup(FSP_FILE_SYSTEM *FileSystem,
/* this will make all future uses of Handle to fail with STATUS_INVALID_HANDLE */ /* this will make all future uses of Handle to fail with STATUS_INVALID_HANDLE */
FileContextHandle = 0; FileContextHandle = 0;
} }
else if ((Flags & FspCleanupSetAllocationSize) &&
(Ptfs->FsAttributeMask & PtfsSetAllocationSizeOnCleanup))
{
IO_STATUS_BLOCK Iosb;
FILE_STANDARD_INFORMATION FileStdInfo;
FILE_ALLOCATION_INFORMATION FileAllocInfo;
NTSTATUS Result;
Result = NtQueryInformationFile(
Handle,
&Iosb,
&FileStdInfo,
sizeof FileStdInfo,
5/*FileStandardInformation*/);
if (NT_SUCCESS(Result))
{
FileAllocInfo.AllocationSize.QuadPart = FileStdInfo.EndOfFile.QuadPart;
Result = NtSetInformationFile(
Handle,
&Iosb,
&FileAllocInfo,
sizeof FileAllocInfo,
19/*FileAllocationInformation*/);
}
}
} }
static VOID Close(FSP_FILE_SYSTEM *FileSystem, static VOID Close(FSP_FILE_SYSTEM *FileSystem,
@ -1138,6 +1165,15 @@ NTSTATUS PtfsCreate(
goto exit; goto exit;
FsAttributeMask &= PtfsAttributesMask; FsAttributeMask &= PtfsAttributesMask;
FsAttrInfo.V.FileSystemAttributes &=
FILE_CASE_PRESERVED_NAMES |
FILE_UNICODE_ON_DISK |
FILE_PERSISTENT_ACLS |
((FsAttributeMask & PtfsReparsePoints) ? FILE_SUPPORTS_REPARSE_POINTS : 0) |
((FsAttributeMask & PtfsNamedStreams) ? FILE_NAMED_STREAMS : 0) |
((FsAttributeMask & PtfsExtendedAttributes) ? FILE_SUPPORTS_EXTENDED_ATTRIBUTES : 0) |
FILE_SUPPORTS_POSIX_UNLINK_RENAME |
FILE_READ_ONLY_VOLUME;
memset(&VolumeParams, 0, sizeof VolumeParams); memset(&VolumeParams, 0, sizeof VolumeParams);
VolumeParams.SectorSize = (UINT16)FsSizeInfo.BytesPerSector; VolumeParams.SectorSize = (UINT16)FsSizeInfo.BytesPerSector;
@ -1150,20 +1186,15 @@ NTSTATUS PtfsCreate(
VolumeParams.CasePreservedNames = !!(FsAttrInfo.V.FileSystemAttributes & FILE_CASE_PRESERVED_NAMES); VolumeParams.CasePreservedNames = !!(FsAttrInfo.V.FileSystemAttributes & FILE_CASE_PRESERVED_NAMES);
VolumeParams.UnicodeOnDisk = !!(FsAttrInfo.V.FileSystemAttributes & FILE_UNICODE_ON_DISK); VolumeParams.UnicodeOnDisk = !!(FsAttrInfo.V.FileSystemAttributes & FILE_UNICODE_ON_DISK);
VolumeParams.PersistentAcls = !!(FsAttrInfo.V.FileSystemAttributes & FILE_PERSISTENT_ACLS); VolumeParams.PersistentAcls = !!(FsAttrInfo.V.FileSystemAttributes & FILE_PERSISTENT_ACLS);
VolumeParams.ReparsePoints = (FsAttributeMask & PtfsReparsePoints) ? VolumeParams.ReparsePoints = !!(FsAttrInfo.V.FileSystemAttributes & FILE_SUPPORTS_REPARSE_POINTS);
!!(FsAttrInfo.V.FileSystemAttributes & FILE_SUPPORTS_REPARSE_POINTS) : 0; VolumeParams.NamedStreams = !!(FsAttrInfo.V.FileSystemAttributes & FILE_NAMED_STREAMS);
VolumeParams.NamedStreams = (FsAttributeMask & PtfsNamedStreams) ? VolumeParams.ExtendedAttributes = !!(FsAttrInfo.V.FileSystemAttributes & FILE_SUPPORTS_EXTENDED_ATTRIBUTES);
!!(FsAttrInfo.V.FileSystemAttributes & FILE_NAMED_STREAMS) : 0;
VolumeParams.ExtendedAttributes = (FsAttributeMask & PtfsExtendedAttributes) ?
!!(FsAttrInfo.V.FileSystemAttributes & FILE_SUPPORTS_EXTENDED_ATTRIBUTES) : 0;
VolumeParams.SupportsPosixUnlinkRename = !!(FsAttrInfo.V.FileSystemAttributes & FILE_SUPPORTS_POSIX_UNLINK_RENAME); VolumeParams.SupportsPosixUnlinkRename = !!(FsAttrInfo.V.FileSystemAttributes & FILE_SUPPORTS_POSIX_UNLINK_RENAME);
VolumeParams.ReadOnlyVolume = !!(FsAttrInfo.V.FileSystemAttributes & FILE_READ_ONLY_VOLUME); VolumeParams.ReadOnlyVolume = !!(FsAttrInfo.V.FileSystemAttributes & FILE_READ_ONLY_VOLUME);
VolumeParams.PostCleanupWhenModifiedOnly = 1; VolumeParams.PostCleanupWhenModifiedOnly = 1;
VolumeParams.PassQueryDirectoryPattern = 1; VolumeParams.PassQueryDirectoryPattern = 1;
VolumeParams.FlushAndPurgeOnCleanup = (FsAttributeMask & PtfsFlushAndPurgeOnCleanup) ? VolumeParams.FlushAndPurgeOnCleanup = !!(FsAttributeMask & PtfsFlushAndPurgeOnCleanup);
1 : 0; VolumeParams.WslFeatures = !!(FsAttributeMask & PtfsWslFeatures);
VolumeParams.WslFeatures = (FsAttributeMask & PtfsWslFeatures) ?
1 : 0;
VolumeParams.AllowOpenInKernelMode = 1; VolumeParams.AllowOpenInKernelMode = 1;
VolumeParams.RejectIrpPriorToTransact0 = 1; VolumeParams.RejectIrpPriorToTransact0 = 1;
VolumeParams.UmFileContextIsUserContext2 = 1; VolumeParams.UmFileContextIsUserContext2 = 1;
@ -1194,6 +1225,7 @@ NTSTATUS PtfsCreate(
Ptfs->FileSystem = FileSystem; Ptfs->FileSystem = FileSystem;
Ptfs->RootHandle = RootHandle; Ptfs->RootHandle = RootHandle;
Ptfs->RootPrefixLength = FileAllInfo.NameInformation.FileNameLength; Ptfs->RootPrefixLength = FileAllInfo.NameInformation.FileNameLength;
Ptfs->FsAttributeMask = FsAttributeMask;
Ptfs->FsAttributes = FsAttrInfo.V.FileSystemAttributes; Ptfs->FsAttributes = FsAttrInfo.V.FileSystemAttributes;
Ptfs->AllocationUnit = VolumeParams.SectorSize * VolumeParams.SectorsPerAllocationUnit; Ptfs->AllocationUnit = VolumeParams.SectorSize * VolumeParams.SectorsPerAllocationUnit;
FileSystem->UserContext = Ptfs; FileSystem->UserContext = Ptfs;

View File

@ -41,20 +41,23 @@ enum
PtfsReparsePoints = 0x00000010, PtfsReparsePoints = 0x00000010,
PtfsNamedStreams = 0x00000040, PtfsNamedStreams = 0x00000040,
PtfsExtendedAttributes = 0x00000100, PtfsExtendedAttributes = 0x00000100,
PtfsFlushAndPurgeOnCleanup = 0x00004000,
PtfsWslFeatures = 0x04000000, PtfsWslFeatures = 0x04000000,
PtfsFlushAndPurgeOnCleanup = 0x00004000,
PtfsSetAllocationSizeOnCleanup = 0x00010000, // reuse UmFileContextIsUserContext2
PtfsAttributesMask = PtfsAttributesMask =
PtfsReparsePoints | PtfsReparsePoints |
PtfsNamedStreams | PtfsNamedStreams |
PtfsExtendedAttributes | PtfsExtendedAttributes |
PtfsWslFeatures |
PtfsFlushAndPurgeOnCleanup | PtfsFlushAndPurgeOnCleanup |
PtfsWslFeatures, PtfsSetAllocationSizeOnCleanup,
}; };
typedef struct typedef struct
{ {
FSP_FILE_SYSTEM *FileSystem; FSP_FILE_SYSTEM *FileSystem;
HANDLE RootHandle; HANDLE RootHandle;
ULONG RootPrefixLength; ULONG RootPrefixLength;
ULONG FsAttributeMask;
ULONG FsAttributes; ULONG FsAttributes;
UINT64 AllocationUnit; UINT64 AllocationUnit;
} PTFS; } PTFS;