From: Thomas Weißschuh Date: Sat, 1 Nov 2025 15:55:49 +0000 (+0100) Subject: fallocate: require posix_fallocate() from libc X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=13b4a466cef2ff9176cb40eaaf0a82f42c1f0f71;p=thirdparty%2Futil-linux.git fallocate: require posix_fallocate() from libc Recent libcs implement posix_fallocate() properly. The fallback logic should never be used. Furthermore unconditional support for posix_fallocate() will enable some further cleanup and fixes. Signed-off-by: Thomas Weißschuh --- diff --git a/configure.ac b/configure.ac index fc66f2149..cf415f5ed 100644 --- a/configure.ac +++ b/configure.ac @@ -652,7 +652,6 @@ AC_CHECK_FUNCS([ \ pidfd_open \ pidfd_send_signal \ posix_fadvise \ - posix_fallocate \ prctl \ qsort_r \ reallocarray \ @@ -693,6 +692,7 @@ AC_CHECK_FUNCS([inotify_init1], [have_inotify_init1=yes]) AC_CHECK_FUNCS([ioperm iopl], [have_io=yes]) AC_CHECK_FUNCS([openat fstatat unlinkat], [have_openat=yes], [have_openat=no]) AC_CHECK_FUNCS([open_memstream], [have_open_memstream=yes],[have_open_memstream=no]) +AC_CHECK_FUNCS([posix_fallocate], [have_posix_fallocate=yes], [have_posix_fallocate=no]) AC_CHECK_FUNCS([reboot], [have_reboot=yes],[have_reboot=no]) AC_CHECK_FUNCS([updwtmpx updwtmpx], [have_gnu_utmpx=yes], [have_gnu_utmpx=no]) @@ -1590,6 +1590,7 @@ AC_ARG_ENABLE([fallocate], UL_BUILD_INIT([fallocate]) UL_REQUIRES_LINUX([fallocate]) UL_REQUIRES_HAVE([fallocate], [fallocate], [fallocate functions]) +UL_REQUIRES_HAVE([fallocate], [posix_fallocate], [posix_fallocate functions]) AM_CONDITIONAL([BUILD_FALLOCATE], [test "x$build_fallocate" = xyes]) diff --git a/meson.build b/meson.build index 9d5206154..cac8bb578 100644 --- a/meson.build +++ b/meson.build @@ -2044,6 +2044,7 @@ endif opt = get_option('build-fallocate') \ .require(LINUX) \ .require(conf.get('HAVE_FALLOCATE').to_string() == '1') \ + .require(conf.get('HAVE_POSIX_FALLOCATE').to_string() == '1') \ .allowed() exe = executable( 'fallocate', diff --git a/sys-utils/fallocate.c b/sys-utils/fallocate.c index 244c1dfa4..aedb091cf 100644 --- a/sys-utils/fallocate.c +++ b/sys-utils/fallocate.c @@ -95,9 +95,7 @@ static void __attribute__((__noreturn__)) usage(void) fputs(_(" -p, --punch-hole replace a range with a hole (implies -n)\n"), out); fputs(_(" -v, --verbose verbose mode\n"), out); fputs(_(" -w, --write-zeroes write zeroes and ensure allocation of a range\n"), out); -#ifdef HAVE_POSIX_FALLOCATE fputs(_(" -x, --posix use posix_fallocate(3) instead of fallocate(2)\n"), out); -#endif fputs(_(" -z, --zero-range zero and ensure allocation of a range\n"), out); fputs(USAGE_SEPARATOR, out); @@ -138,7 +136,6 @@ static void xfallocate(int fd, int mode, off_t offset, off_t length) } } -#ifdef HAVE_POSIX_FALLOCATE static void xposix_fallocate(int fd, off_t offset, off_t length) { errno = posix_fallocate(fd, offset, length); @@ -146,7 +143,6 @@ static void xposix_fallocate(int fd, off_t offset, off_t length) err(EXIT_FAILURE, _("fallocate failed")); } } -#endif /* The real buffer size has to be bufsize + sizeof(uintptr_t) */ static int is_nul(void *buf, size_t bufsize) @@ -287,9 +283,7 @@ int main(int argc, char **argv) int fd; int mode = 0; int dig = 0; -#ifdef HAVE_POSIX_FALLOCATE int posix = 0; -#endif loff_t length = -2LL; loff_t offset = 0; @@ -356,12 +350,8 @@ int main(int argc, char **argv) mode |= FALLOC_FL_WRITE_ZEROES; break; case 'x': -#ifdef HAVE_POSIX_FALLOCATE posix = 1; break; -#else - errx(EXIT_FAILURE, _("posix_fallocate support is not compiled")); -#endif case 'v': verbose++; break; @@ -409,11 +399,9 @@ int main(int argc, char **argv) if (dig) dig_holes(fd, offset, length); else { -#ifdef HAVE_POSIX_FALLOCATE if (posix) xposix_fallocate(fd, offset, length); else -#endif xfallocate(fd, mode, offset, length); if (verbose) {