From: Charles Davis cdavis5x@gmail.com
The fallocate(2) call only exists on Linux. posix_fallocate() is more portable.
Signed-off-by: Chip Davis cdavis@codeweavers.com --- v2: Don't fall back to fallocate(2). --- configure.ac | 10 +--------- dlls/ntdll/unix/file.c | 9 +++++---- 2 files changed, 6 insertions(+), 13 deletions(-)
diff --git a/configure.ac b/configure.ac index fec39b6f2ac..cc8a4b79aaf 100644 --- a/configure.ac +++ b/configure.ac @@ -2183,6 +2183,7 @@ AC_CHECK_FUNCS(\ poll \ port_create \ posix_fadvise \ + posix_fallocate \ prctl \ proc_pidinfo \ readlink \ @@ -2274,15 +2275,6 @@ then AC_DEFINE(HAVE_SCHED_SETAFFINITY, 1, [Define to 1 if you have the `sched_setaffinity' function.]) fi
-AC_CACHE_CHECK([for fallocate],wine_cv_have_fallocate, - AC_LINK_IFELSE([AC_LANG_PROGRAM( -[[#define _GNU_SOURCE -#include <fcntl.h>]], [[fallocate(-1, 0, 0, 0);]])],[wine_cv_have_fallocate=yes],[wine_cv_have_fallocate=no])) -if test "$wine_cv_have_fallocate" = "yes" -then - AC_DEFINE(HAVE_FALLOCATE, 1, [Define to 1 if you have the `fallocate' function.]) -fi - dnl **** Check for types ****
AC_C_INLINE diff --git a/dlls/ntdll/unix/file.c b/dlls/ntdll/unix/file.c index 046338b2a82..e10c79cb846 100644 --- a/dlls/ntdll/unix/file.c +++ b/dlls/ntdll/unix/file.c @@ -4574,11 +4574,12 @@ NTSTATUS WINAPI NtSetInformationFile( HANDLE handle, IO_STATUS_BLOCK *io, status = STATUS_INVALID_PARAMETER; else { -#ifdef HAVE_FALLOCATE - if (fallocate( fd, 0, 0, (off_t)info->ValidDataLength.QuadPart ) == -1) +#ifdef HAVE_POSIX_ALLOCATE + int err; + if ((err = posix_fallocate( fd, 0, (off_t)info->ValidDataLength.QuadPart )) != 0) { - if (errno == EOPNOTSUPP) WARN( "fallocate not supported on this filesystem\n" ); - else status = errno_to_status( errno ); + if (err == EOPNOTSUPP) WARN( "posix_fallocate not supported on this filesystem\n" ); + else status = errno_to_status( err ); } #else FIXME( "setting valid data length not supported\n" );
From: Charles Davis cdavis5x@gmail.com
Signed-off-by: Chip Davis cdavis@codeweavers.com --- 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 e10c79cb846..b3a4c2149cb 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
September 14, 2021 4:54 PM, "Chip Davis" cdavis@codeweavers.com wrote:
+#ifdef HAVE_POSIX_ALLOCATE
D'oh! Let me resend that...
Chip