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 --- configure.ac | 1 + dlls/ntdll/unix/file.c | 25 ++++++++++++++++++------- 2 files changed, 19 insertions(+), 7 deletions(-)
diff --git a/configure.ac b/configure.ac index fec39b6f2ac..53656685bff 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 \ diff --git a/dlls/ntdll/unix/file.c b/dlls/ntdll/unix/file.c index 833266ddf3f..4286b81aa1f 100644 --- a/dlls/ntdll/unix/file.c +++ b/dlls/ntdll/unix/file.c @@ -135,6 +135,19 @@ WINE_DECLARE_DEBUG_CHANNEL(winediag);
#define MAX_DOS_DRIVES 26
+#ifndef HAVE_POSIX_FALLOCATE +static int posix_fallocate( int fd, off_t offset, off_t len ) +{ +#ifdef HAVE_FALLOCATE + if (fallocate( fd, 0, offset, len ) < 0) + return errno; + return 0; +#else + return ENOSYS; +#endif +} +#endif /* HAVE_POSIX_FALLOCATE */ + /* just in case... */ #undef VFAT_IOCTL_READDIR_BOTH #undef EXT2_IOC_GETFLAGS @@ -4574,15 +4587,13 @@ 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) + 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 == ENOSYS) FIXME( "setting valid data length not supported\n" ); + else 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" ); -#endif } if (needs_close) close( fd ); }
From: Charles Davis cdavis5x@gmail.com
Signed-off-by: Chip Davis cdavis@codeweavers.com --- dlls/ntdll/unix/file.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
diff --git a/dlls/ntdll/unix/file.c b/dlls/ntdll/unix/file.c index 4286b81aa1f..ea3c947da73 100644 --- a/dlls/ntdll/unix/file.c +++ b/dlls/ntdll/unix/file.c @@ -142,6 +142,20 @@ static int posix_fallocate( int fd, off_t offset, off_t len ) if (fallocate( fd, 0, offset, len ) < 0) return errno; return 0; +#elif defined(F_PREALLOCATE) + struct fstore fst; + struct stat st; + + if (fstat( fd, &st ) < 0) + return errno; + + fst.fst_flags = F_ALLOCATECONTIG|F_ALLOCATEALL; + fst.fst_posmode = F_PEOFPOSMODE; + fst.fst_offset = 0; + fst.fst_length = len + offset - st.st_blocks * 512; + if (fcntl( fd, F_PREALLOCATE, &fst ) < 0) + return errno; + return 0; #else return ENOSYS; #endif
Chip Davis cdavis@codeweavers.com writes:
From: Charles Davis cdavis5x@gmail.com
The fallocate(2) call only exists on Linux. posix_fallocate() is more portable.
I'd suggest to always use posix_fallocate() then, and don't worry about adding fallbacks. We can simply skip the call if it's missing.