.RB [ \-n ]
.RB [ \-p ]
.RB [ \-c ]
+.RB [ \-z ]
.RB [ \-o
.IR offset ]
.B \-l
blocks past EOF, which can be removed with a truncate.
.IP "\fB\-p, \-\-punch-hole\fP"
Punch holes in the file, the range should not exceed the length of the file.
+This option may not be specified at the same time as the
+.B \-z
+option.
.IP "\fB\-d, \-\-dig-holes\fP"
Detect and dig holes. Makes the file sparse in-place, without using extra disk
space. The minimal size of the hole depends on filesystem I/O block size
command does not leave a hole, while \fI\-\-punch-hole\fP leaves a hole
instead of shifting extents. Both offset and length should be aligned to
the block size of filesystem.
+.IP "\fB\-z, \-\-zero-range\fP"
+Zero range in the file. Regions that span holes in the file will be
+preallocated, this includes areas past EOF. Option
+.B \-n
+can be specified to prevent file length modification. Reads from the range
+will return zeros. This option may not be specified at the same time as the
+.B \-p
+or
+.B \-c
+option.
.IP "\fB\-o, \-\-offset\fP \fIoffset\fP
Specifies the beginning offset of the allocation, in bytes.
.IP "\fB\-l, \-\-length\fP \fIlength\fP
#if defined(HAVE_LINUX_FALLOC_H) && \
(!defined(FALLOC_FL_KEEP_SIZE) || !defined(FALLOC_FL_PUNCH_HOLE) || \
- !defined(FALLOC_FL_COLLAPSE_RANGE))
+ !defined(FALLOC_FL_COLLAPSE_RANGE) || !defined(FALLOC_FL_ZERO_RANGE))
# include <linux/falloc.h> /* non-libc fallback for FALLOC_FL_* flags */
#endif
#ifndef FALLOC_FL_KEEP_SIZE
-# define FALLOC_FL_KEEP_SIZE 1
+# define FALLOC_FL_KEEP_SIZE 0x1
#endif
#ifndef FALLOC_FL_PUNCH_HOLE
-# define FALLOC_FL_PUNCH_HOLE 2
+# define FALLOC_FL_PUNCH_HOLE 0x2
#endif
#ifndef FALLOC_FL_COLLAPSE_RANGE
-# define FALLOC_FL_COLLAPSE_RANGE 8
+# define FALLOC_FL_COLLAPSE_RANGE 0x8
+#endif
+
+#ifndef FALLOC_FL_ZERO_RANGE
+# define FALLOC_FL_ZERO_RANGE 0x10
#endif
#include "nls.h"
fputs(_(" -n, --keep-size don't modify the length of the file\n"), out);
fputs(_(" -o, --offset <num> offset of the (de)allocation, in bytes\n"), out);
fputs(_(" -p, --punch-hole punch holes in the file\n"), out);
+ fputs(_(" -z, --zero-range zeroes a range in the file\n"), out);
fputs(_(" -v, --verbose verbose mode\n"), out);
fputs(USAGE_SEPARATOR, out);
{ "punch-hole", 0, 0, 'p' },
{ "collapse-range", 0, 0, 'c' },
{ "dig-holes", 0, 0, 'd' },
+ { "zero-range", 0, 0, 'z' },
{ "offset", 1, 0, 'o' },
{ "length", 1, 0, 'l' },
{ "verbose", 0, 0, 'v' },
textdomain(PACKAGE);
atexit(close_stdout);
- while ((c = getopt_long(argc, argv, "hvVncpdl:o:", longopts, NULL))
+ while ((c = getopt_long(argc, argv, "hvVncpdzl:o:", longopts, NULL))
!= -1) {
switch(c) {
case 'h':
case 'd':
dig = 1;
break;
+ case 'z':
+ mode |= FALLOC_FL_ZERO_RANGE;
+ break;
case 'l':
length = cvtnum(optarg);
break;
}
if (dig) {
if (mode != 0)
- errx(EXIT_FAILURE, _("Can't use -p or -n with --dig-holes"));
+ errx(EXIT_FAILURE,
+ _("Can't use other modes with --dig-holes"));
if (length == -2LL)
length = 0;
if (length < 0)
errx(EXIT_FAILURE, _("invalid offset value specified"));
if (optind == argc)
errx(EXIT_FAILURE, _("no filename specified."));
+ if (mode & ~(FALLOC_FL_ZERO_RANGE | FALLOC_FL_KEEP_SIZE))
+ errx(EXIT_FAILURE, _("only -n mode can be used with "
+ "--zero-range"));
filename = argv[optind++];