[PATCH 1/2] ntdll: Use posix_fallocate(2/3) instead of fallocate(2).
Chip Davis
cdavis at codeweavers.com
Mon Sep 13 16:35:02 CDT 2021
From: Charles Davis <cdavis5x at gmail.com>
The fallocate(2) call only exists on Linux. posix_fallocate() is more
portable.
Signed-off-by: Chip Davis <cdavis at 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 );
}
--
2.33.0
More information about the wine-devel
mailing list