]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
fallocate: require posix_fallocate() from libc
authorThomas Weißschuh <thomas@t-8ch.de>
Sat, 1 Nov 2025 15:55:49 +0000 (16:55 +0100)
committerThomas Weißschuh <thomas@t-8ch.de>
Sat, 8 Nov 2025 14:08:27 +0000 (15:08 +0100)
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 <thomas@t-8ch.de>
configure.ac
meson.build
sys-utils/fallocate.c

index fc66f21495205e396d29fd29188dcf6737e14de5..cf415f5ed463ff2f4154c20c0dd1456dacb95706 100644 (file)
@@ -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])
 
 
index 9d520615459cfced344a4d37eea7602739d1c8fa..cac8bb57869d856dcdca3039e81badc8ea805c6c 100644 (file)
@@ -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',
index 244c1dfa4daefc701e370c6de187b8473f5a7643..aedb091cfbdbbf9745f1d5cfaf889c3d4e48ea44 100644 (file)
@@ -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) {