AC_MSG_RESULT([no])])
])
+AS_IF([test "x$build_fallocate" = xyes], [
+ dnl check for valid posix_fallocate() function
+ AC_MSG_CHECKING([for valid posix_fallocate() function])
+ AC_LINK_IFELSE([AC_LANG_PROGRAM([[
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif
+#ifdef HAVE_SYS_TYPES_H
+# include <sys/types.h>
+#endif
+#ifdef HAVE_LINUX_FALLOC_H
+# include <linux/falloc.h>
+#endif
+#ifdef HAVE_FCNTL_H
+# include <fcntl.h>
+#endif
+]],[[
+ long ret;
+ ret = posix_fallocate(0, 0xfffffffful, 0xfffffffful);
+ if (ret != 0) {
+ return 1;
+ }
+ ]])],[
+ AC_MSG_RESULT([yes])
+ AC_DEFINE([HAVE_POSIX_FALLOCATE], [1], [Have valid posix_fallocate() function])],[
+ AC_MSG_RESULT([no])])
+])
+
AC_ARG_ENABLE([unshare],
AS_HELP_STRING([--disable-unshare], [do not build unshare]),
fputs(_(" -o, --offset <num> offset for range operations, in bytes\n"), out);
fputs(_(" -p, --punch-hole replace a range with a hole (implies -n)\n"), out);
fputs(_(" -z, --zero-range zero 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(_(" -v, --verbose verbose mode\n"), out);
fputs(USAGE_SEPARATOR, out);
}
}
+#ifdef HAVE_POSIX_FALLOCATE
+static void xposix_fallocate(int fd, off_t offset, off_t length)
+{
+ int error = posix_fallocate(fd, offset, length);
+ if (error < 0) {
+ err(EXIT_FAILURE, _("fallocate failed"));
+ }
+}
+#endif
static int skip_hole(int fd, off_t *off)
{
int fd;
int mode = 0;
int dig = 0;
+ int posix = 0;
loff_t length = -2LL;
loff_t offset = 0;
{ "zero-range", 0, 0, 'z' },
{ "offset", 1, 0, 'o' },
{ "length", 1, 0, 'l' },
+ { "posix", 0, 0, 'x' },
{ "verbose", 0, 0, 'v' },
{ NULL, 0, 0, 0 }
};
static const ul_excl_t excl[] = { /* rows and cols in in ASCII order */
{ 'c', 'd', 'p', 'z' },
{ 'c', 'n' },
+ { 'x', 'c', 'd', 'i', 'n', 'p', 'z'},
{ 0 }
};
int excl_st[ARRAY_SIZE(excl)] = UL_EXCL_STATUS_INIT;
textdomain(PACKAGE);
atexit(close_stdout);
- while ((c = getopt_long(argc, argv, "hvVncpdizl:o:", longopts, NULL))
+ while ((c = getopt_long(argc, argv, "hvVncpdizxl:o:", longopts, NULL))
!= -1) {
err_exclusive_options(c, longopts, excl, excl_st);
case 'z':
mode |= FALLOC_FL_ZERO_RANGE;
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;
if (dig)
dig_holes(fd, offset, length);
+#ifdef HAVE_POSIX_FALLOCATE
+ else if (posix)
+ xposix_fallocate(fd, offset, length);
+#endif
else
xfallocate(fd, mode, offset, length);