diff options
| author | Dan Engelbrecht <[email protected]> | 2025-05-16 12:03:21 +0200 |
|---|---|---|
| committer | GitHub Enterprise <[email protected]> | 2025-05-16 12:03:21 +0200 |
| commit | f3d794f2a8f8ae96760bcab4880d34c589250b6a (patch) | |
| tree | 4da325ef30788e399b017077ea7e589a56cb6013 /src/zencore/filesystem.cpp | |
| parent | Merge pull request #396 from ue-foundation/zs/config-retention-8days (diff) | |
| download | zen-f3d794f2a8f8ae96760bcab4880d34c589250b6a.tar.xz zen-f3d794f2a8f8ae96760bcab4880d34c589250b6a.zip | |
sparse win file write (#398)
* Added `--use-sparse-files` option to `zen builds` command improving write performance of large files. Enabled by default.
Diffstat (limited to 'src/zencore/filesystem.cpp')
| -rw-r--r-- | src/zencore/filesystem.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/zencore/filesystem.cpp b/src/zencore/filesystem.cpp index 018330d9b..c1df6d53e 100644 --- a/src/zencore/filesystem.cpp +++ b/src/zencore/filesystem.cpp @@ -2158,6 +2158,34 @@ MaximizeOpenFileCount() #endif } +bool +PrepareFileForScatteredWrite(void* FileHandle, uint64_t FinalSize) +{ + bool Result = true; +#if ZEN_PLATFORM_WINDOWS + DWORD _ = 0; + BOOL Ok = DeviceIoControl(FileHandle, FSCTL_SET_SPARSE, nullptr, 0, nullptr, 0, &_, nullptr); + if (!Ok) + { + std::error_code DummyEc; + ZEN_DEBUG("Unable to set sparse mode for file '{}'", PathFromHandle(FileHandle, DummyEc)); + Result = false; + } + + FILE_ALLOCATION_INFO AllocationInfo = {}; + AllocationInfo.AllocationSize.QuadPart = FinalSize; + if (!SetFileInformationByHandle(FileHandle, FileAllocationInfo, &AllocationInfo, DWORD(sizeof(AllocationInfo)))) + { + std::error_code DummyEc; + ZEN_DEBUG("Unable to set file allocation size to {} for file '{}'", FinalSize, PathFromHandle(FileHandle, DummyEc)); + Result = false; + } +#else // ZEN_PLATFORM_WINDOWS + ZEN_UNUSED(FileHandle, FinalSize); +#endif // ZEN_PLATFORM_WINDOWS + return Result; +} + void GetDirectoryContent(const std::filesystem::path& RootDir, DirectoryContentFlags Flags, DirectoryContent& OutContent) { |