diff options
-rw-r--r-- | sys-utils/fallocate.1 | 10 | ||||
-rw-r--r-- | sys-utils/fallocate.c | 44 |
2 files changed, 31 insertions, 23 deletions
diff --git a/sys-utils/fallocate.1 b/sys-utils/fallocate.1 index 0496d4a48..b03f19b59 100644 --- a/sys-utils/fallocate.1 +++ b/sys-utils/fallocate.1 @@ -38,6 +38,10 @@ The \fIlength\fR and \fIoffset\fR arguments may be followed by the multiplicativ suffixes KiB=1024, MiB=1024*1024, and so on for GiB, TiB, PiB, EiB, ZiB and YiB (the "iB" is optional, e.g. "K" has the same meaning as "KiB") or the suffixes KB=1000, MB=1000*1000, and so on for GB, TB, PB, EB, ZB and YB. + +The options \fB\-\-collapse-range\fP, \fB\-\-dig-holes\fP, \fB\-\-punch-hole\fP and +\fB\-\-zero-range\fP are mutually exclusive. + .IP "\fB\-n, \-\-keep-size\fP" Do not modify the apparent length of the file. This may effectively allocate blocks past EOF, which can be removed with a truncate. @@ -68,7 +72,8 @@ Removes a byte range from a file, without leaving a hole. The byte range to be collapsed starts at \fIoffset\fP and continues for \fIlength\fR bytes. At the completion of the operation, the contents of the file starting at the location offset+length will be appended at the -location offset, and the file will be \fIlength\fR bytes smaller. +location offset, and the file will be \fIlength\fR bytes smaller. The option +\fB\-\-keep\-size\fR may not be specified for colapse range operation. Available since Linux 3.15 for ext4 (only for extent-based files) and XFS. .IP "\fB\-z, \-\-zero-range\fP" @@ -84,8 +89,7 @@ partial blocks at the either end of the range), and I/O is (otherwise) required only to update metadata. Option \fB\-\-keep\-size\fP can be specified to prevent file length -modification. This option may not be specified at the same time as the -\fB\-\-punch-hole\fP or \fB\-\-collapse-range\fP option. +modification. Available since Linux 3.14 for ext4 (only for extent-based files) and XFS. .IP "\fB\-o, \-\-offset\fP \fIoffset\fP diff --git a/sys-utils/fallocate.c b/sys-utils/fallocate.c index d950f9c57..512757f70 100644 --- a/sys-utils/fallocate.c +++ b/sys-utils/fallocate.c @@ -44,6 +44,7 @@ # include <linux/falloc.h> /* non-libc fallback for FALLOC_FL_* flags */ #endif + #ifndef FALLOC_FL_KEEP_SIZE # define FALLOC_FL_KEEP_SIZE 0x1 #endif @@ -65,6 +66,7 @@ #include "c.h" #include "closestream.h" #include "xalloc.h" +#include "optutils.h" static int verbose; static char *filename; @@ -282,6 +284,13 @@ int main(int argc, char **argv) { NULL, 0, 0, 0 } }; + static const ul_excl_t excl[] = { /* rows and cols in in ASCII order */ + { 'c', 'd', 'p', 'z' }, + { 'c', 'n' }, + { 0 } + }; + int excl_st[ARRAY_SIZE(excl)] = UL_EXCL_STATUS_INIT; + setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); @@ -289,37 +298,40 @@ int main(int argc, char **argv) while ((c = getopt_long(argc, argv, "hvVncpdzl:o:", longopts, NULL)) != -1) { + + err_exclusive_options(c, longopts, excl, excl_st); + switch(c) { case 'h': usage(stdout); break; - case 'V': - printf(UTIL_LINUX_VERSION); - return EXIT_SUCCESS; case 'c': mode |= FALLOC_FL_COLLAPSE_RANGE; break; - case 'p': - mode |= FALLOC_FL_PUNCH_HOLE; - /* fall through */ - case 'n': - mode |= FALLOC_FL_KEEP_SIZE; - break; case 'd': dig = 1; break; - case 'z': - mode |= FALLOC_FL_ZERO_RANGE; - break; case 'l': length = cvtnum(optarg); break; + case 'n': + mode |= FALLOC_FL_KEEP_SIZE; + break; case 'o': offset = cvtnum(optarg); break; + case 'p': + mode |= FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE; + break; + case 'z': + mode |= FALLOC_FL_ZERO_RANGE; + break; case 'v': verbose++; break; + case 'V': + printf(UTIL_LINUX_VERSION); + return EXIT_SUCCESS; default: usage(stderr); break; @@ -327,9 +339,6 @@ int main(int argc, char **argv) } if (dig) { /* for --dig-holes the default is analyze all file */ - if (mode != 0) - errx(EXIT_FAILURE, - _("Can't use other modes with --dig-holes")); if (length == -2LL) length = 0; if (length < 0) @@ -346,11 +355,6 @@ int main(int argc, char **argv) if (optind == argc) errx(EXIT_FAILURE, _("no filename specified.")); - if ((mode & FALLOC_FL_ZERO_RANGE) && - (mode & ~(FALLOC_FL_ZERO_RANGE | FALLOC_FL_KEEP_SIZE))) - errx(EXIT_FAILURE, _("only --keep-size mode can be used with " - "--zero-range")); - filename = argv[optind++]; if (optind != argc) { |