From: Chip Davis Subject: [PATCH v3 2/2] ntdll: Use the F_PREALLOCATE fcntl(2) on Mac OS when posix_fallocate(2/3) isn't available. Message-Id: <20210914215742.95299-2-cdavis@codeweavers.com> Date: Tue, 14 Sep 2021 16:57:42 -0500 In-Reply-To: <20210914215742.95299-1-cdavis@codeweavers.com> References: <20210914215742.95299-1-cdavis@codeweavers.com> From: Charles Davis Signed-off-by: Chip Davis --- dlls/ntdll/unix/file.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/dlls/ntdll/unix/file.c b/dlls/ntdll/unix/file.c index c92cbd1db4a..899cdc9868a 100644 --- a/dlls/ntdll/unix/file.c +++ b/dlls/ntdll/unix/file.c @@ -4581,6 +4581,22 @@ NTSTATUS WINAPI NtSetInformationFile( HANDLE handle, IO_STATUS_BLOCK *io, if (err == EOPNOTSUPP) WARN( "posix_fallocate not supported on this filesystem\n" ); else status = errno_to_status( err ); } +#elif defined(F_PREALLOCATE) + struct stat st; + + if (fstat( fd, &st ) < 0) + status = errno_to_status( errno ); + else + { + struct fstore fst; + + fst.fst_flags = F_ALLOCATECONTIG|F_ALLOCATEALL; + fst.fst_posmode = F_PEOFPOSMODE; + fst.fst_offset = 0; + fst.fst_length = (off_t)info->ValidDataLength.QuadPart - st.st_blocks * 512; + if (fcntl( fd, F_PREALLOCATE, &fst ) < 0) + status = errno_to_status( errno ); + } #else FIXME( "setting valid data length not supported\n" ); #endif -- 2.33.0