HAVE_SENDFILE = @have_sendfile@
HAVE_GETMNTENT = @have_getmntent@
HAVE_GETMNTINFO = @have_getmntinfo@
+HAVE_FALLOCATE = @have_fallocate@
GCCFLAGS = -funsigned-char -fno-strict-aliasing -Wall
# -Wbitwise -Wno-transparent-union -Wno-old-initializer -Wno-decl
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#if defined(HAVE_FALLOCATE)
+#include <linux/falloc.h>
+#endif
#include <xfs/xfs.h>
#include <xfs/command.h>
#include <xfs/input.h>
static cmdinfo_t freesp_cmd;
static cmdinfo_t resvsp_cmd;
static cmdinfo_t unresvsp_cmd;
+#if defined(HAVE_FALLOCATE)
+static cmdinfo_t falloc_cmd;
+#endif
static int
offset_length(
return 0;
}
+#if defined (HAVE_FALLOCATE)
+static int
+fallocate_f(
+ int argc,
+ char **argv)
+{
+ xfs_flock64_t segment;
+ int mode = 0;
+ int c;
+
+ while ((c = getopt(argc, argv, "k")) != EOF) {
+ switch (c) {
+ case 'k':
+ mode = FALLOC_FL_KEEP_SIZE;
+ break;
+ default:
+ command_usage(&falloc_cmd);
+ }
+ }
+ if (optind != argc - 2)
+ return command_usage(&falloc_cmd);
+
+ if (!offset_length(argv[optind], argv[optind+1], &segment))
+ return 0;
+
+ if (fallocate(file->fd, mode,
+ segment.l_start, segment.l_len)) {
+ perror("fallocate");
+ return 0;
+ }
+ return 0;
+}
+#endif
+
void
prealloc_init(void)
{
add_command(&freesp_cmd);
add_command(&resvsp_cmd);
add_command(&unresvsp_cmd);
+
+#if defined (HAVE_FALLOCATE)
+ falloc_cmd.name = _("falloc");
+ falloc_cmd.cfunc = fallocate_f;
+ falloc_cmd.argmin = 2;
+ falloc_cmd.argmax = -1;
+ falloc_cmd.flags = CMD_NOMAP_OK | CMD_FOREIGN_OK;
+ falloc_cmd.args = _("[-k] off len");
+ falloc_cmd.oneline =
+ _("allocates space associated with part of a file via fallocate");
+
+ add_command(&falloc_cmd);
+#endif
}
AC_MSG_RESULT(no))
AC_SUBST(have_getmntinfo)
])
+
+#
+# Check if we have a fallocate libc call (Linux)
+#
+AC_DEFUN([AC_HAVE_FALLOCATE],
+ [ AC_MSG_CHECKING([for fallocate])
+ AC_TRY_LINK([
+#include <linux/falloc.h>
+ ], [
+ fallocate(0, 0, 0, 0);
+ ], have_fallocate=yes
+ AC_MSG_RESULT(yes),
+ AC_MSG_RESULT(no))
+ AC_SUBST(have_fallocate)
+ ])
.BR xfsctl (3)
manual page.
.TP
+.BI "falloc [ \-k ]" " offset length"
+Allocates reserved, unwritten space for part of a file using the
+fallocate routine as described in the
+.BR fallocate (3)
+manual page.
+.RS 1.0i
+.PD 0
+.TP 0.4i
+.B \-k
+will set the FALLOC_FL_KEEP_SIZE flag as described in
+.BR fallocate (3).
+.PD
+.RE
+.TP
.BI truncate " offset"
Truncates the current file at the given offset using
.BR ftruncate (2).