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;
else if (0 == _wcsicmp(L"ExtendedAttributes", OptionString))
FsAttributeMask |= PtfsExtendedAttributes;
else if (0 == _wcsicmp(L"FlushAndPurgeOnCleanup", OptionString))
FsAttributeMask |= PtfsFlushAndPurgeOnCleanup;
else if (0 == _wcsicmp(L"WslFeatures", OptionString))
FsAttributeMask |= PtfsWslFeatures;
else if (0 == _wcsicmp(L"FlushAndPurgeOnCleanup", OptionString))
FsAttributeMask |= PtfsFlushAndPurgeOnCleanup;
else if (0 == _wcsicmp(L"SetAllocationSizeOnCleanup", OptionString))
FsAttributeMask |= PtfsSetAllocationSizeOnCleanup;
else
goto usage;
break;
@ -247,6 +249,7 @@ usage:
" -o ExtendedAttributes\n"
" -o WslFeatures\n"
" -o FlushAndPurgeOnCleanup\n"
" -o SetAllocationSizeOnCleanup\n"
" -u \\Server\\Share [UNC prefix (single backslash)]\n"
" -p Directory [directory to expose as pass through file system]\n"
" -m MountPoint [X:|*|directory]\n";

View File

@ -343,6 +343,7 @@ exit:
static VOID Cleanup(FSP_FILE_SYSTEM *FileSystem,
PVOID FileContext, PWSTR FileName, ULONG Flags)
{
PTFS *Ptfs = FileSystemContext;
HANDLE Handle = FileContextHandle;
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 */
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,
@ -1138,6 +1165,15 @@ NTSTATUS PtfsCreate(
goto exit;
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);
VolumeParams.SectorSize = (UINT16)FsSizeInfo.BytesPerSector;
@ -1150,20 +1186,15 @@ NTSTATUS PtfsCreate(
VolumeParams.CasePreservedNames = !!(FsAttrInfo.V.FileSystemAttributes & FILE_CASE_PRESERVED_NAMES);
VolumeParams.UnicodeOnDisk = !!(FsAttrInfo.V.FileSystemAttributes & FILE_UNICODE_ON_DISK);
VolumeParams.PersistentAcls = !!(FsAttrInfo.V.FileSystemAttributes & FILE_PERSISTENT_ACLS);
VolumeParams.ReparsePoints = (FsAttributeMask & PtfsReparsePoints) ?
!!(FsAttrInfo.V.FileSystemAttributes & FILE_SUPPORTS_REPARSE_POINTS) : 0;
VolumeParams.NamedStreams = (FsAttributeMask & PtfsNamedStreams) ?
!!(FsAttrInfo.V.FileSystemAttributes & FILE_NAMED_STREAMS) : 0;
VolumeParams.ExtendedAttributes = (FsAttributeMask & PtfsExtendedAttributes) ?
!!(FsAttrInfo.V.FileSystemAttributes & FILE_SUPPORTS_EXTENDED_ATTRIBUTES) : 0;
VolumeParams.ReparsePoints = !!(FsAttrInfo.V.FileSystemAttributes & FILE_SUPPORTS_REPARSE_POINTS);
VolumeParams.NamedStreams = !!(FsAttrInfo.V.FileSystemAttributes & FILE_NAMED_STREAMS);
VolumeParams.ExtendedAttributes = !!(FsAttrInfo.V.FileSystemAttributes & FILE_SUPPORTS_EXTENDED_ATTRIBUTES);
VolumeParams.SupportsPosixUnlinkRename = !!(FsAttrInfo.V.FileSystemAttributes & FILE_SUPPORTS_POSIX_UNLINK_RENAME);
VolumeParams.ReadOnlyVolume = !!(FsAttrInfo.V.FileSystemAttributes & FILE_READ_ONLY_VOLUME);
VolumeParams.PostCleanupWhenModifiedOnly = 1;
VolumeParams.PassQueryDirectoryPattern = 1;
VolumeParams.FlushAndPurgeOnCleanup = (FsAttributeMask & PtfsFlushAndPurgeOnCleanup) ?
1 : 0;
VolumeParams.WslFeatures = (FsAttributeMask & PtfsWslFeatures) ?
1 : 0;
VolumeParams.FlushAndPurgeOnCleanup = !!(FsAttributeMask & PtfsFlushAndPurgeOnCleanup);
VolumeParams.WslFeatures = !!(FsAttributeMask & PtfsWslFeatures);
VolumeParams.AllowOpenInKernelMode = 1;
VolumeParams.RejectIrpPriorToTransact0 = 1;
VolumeParams.UmFileContextIsUserContext2 = 1;
@ -1194,6 +1225,7 @@ NTSTATUS PtfsCreate(
Ptfs->FileSystem = FileSystem;
Ptfs->RootHandle = RootHandle;
Ptfs->RootPrefixLength = FileAllInfo.NameInformation.FileNameLength;
Ptfs->FsAttributeMask = FsAttributeMask;
Ptfs->FsAttributes = FsAttrInfo.V.FileSystemAttributes;
Ptfs->AllocationUnit = VolumeParams.SectorSize * VolumeParams.SectorsPerAllocationUnit;
FileSystem->UserContext = Ptfs;

View File

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