diff options
author | Fabian Frederick <fabf@skynet.be> | 2016-11-15 19:52:26 +0100 |
---|---|---|
committer | Karel Zak <kzak@redhat.com> | 2016-12-02 13:56:32 +0100 |
commit | b439065634e693dda385a6e5269e1d9258d6d471 (patch) | |
tree | d0eda2a77120848b0b3a888028fa58b6b238d2f2 | |
parent | 01544c52f86166a4a5dc81835027e412580396b2 (diff) | |
download | util-linux-b439065634e693dda385a6e5269e1d9258d6d471.tar.gz |
fallocate: add insert range support
Based on patch 83cc932d7412
("fallocate: introduce an option -c to support COLLAPSE_RANGE")
This patch includes FALLOC_FL_INSERT_RANGE flag
added to Linux kernel v4.1
Thanks to Pádraig Brady for insert range definition
Signed-off-by: Fabian Frederick <fabf@skynet.be>
-rw-r--r-- | sys-utils/fallocate.1 | 3 | ||||
-rw-r--r-- | sys-utils/fallocate.c | 14 |
2 files changed, 15 insertions, 2 deletions
diff --git a/sys-utils/fallocate.1 b/sys-utils/fallocate.1 index f533e1aed6..9f24ce6ba0 100644 --- a/sys-utils/fallocate.1 +++ b/sys-utils/fallocate.1 @@ -60,6 +60,9 @@ the destination file to the original, without the need for extra disk space. .sp See \fB\-\-punch\-hole\fP for a list of supported filesystems. .TP +.BR \-i , " \-\-insert\-range" +Insert a hole of \fIlength\fR bytes from \fIoffset\fR, shifting existing data. +.TP .BR \-l , " \-\-length " \fIlength Specifies the length of the range, in bytes. .TP diff --git a/sys-utils/fallocate.c b/sys-utils/fallocate.c index 4f2f74ea86..1663a8e7ec 100644 --- a/sys-utils/fallocate.c +++ b/sys-utils/fallocate.c @@ -40,7 +40,8 @@ #if defined(HAVE_LINUX_FALLOC_H) && \ (!defined(FALLOC_FL_KEEP_SIZE) || !defined(FALLOC_FL_PUNCH_HOLE) || \ - !defined(FALLOC_FL_COLLAPSE_RANGE) || !defined(FALLOC_FL_ZERO_RANGE)) + !defined(FALLOC_FL_COLLAPSE_RANGE) || !defined(FALLOC_FL_ZERO_RANGE) || \ + !defined(FALLOC_FL_INSERT_RANGE)) # include <linux/falloc.h> /* non-libc fallback for FALLOC_FL_* flags */ #endif @@ -61,6 +62,10 @@ # define FALLOC_FL_ZERO_RANGE 0x10 #endif +#ifndef FALLOC_FL_INSERT_RANGE +# define FALLOC_FL_INSERT_RANGE 0x20 +#endif + #include "nls.h" #include "strutils.h" #include "c.h" @@ -83,6 +88,7 @@ static void __attribute__((__noreturn__)) usage(FILE *out) fputs(USAGE_OPTIONS, out); fputs(_(" -c, --collapse-range remove a range from the file\n"), out); fputs(_(" -d, --dig-holes detect zeroes and replace with holes\n"), out); + fputs(_(" -i, --insert-range insert a hole at range, shifting existing data\n"), out); fputs(_(" -l, --length <num> length for range operations, in bytes\n"), out); fputs(_(" -n, --keep-size maintain the apparent size of the file\n"), out); fputs(_(" -o, --offset <num> offset for range operations, in bytes\n"), out); @@ -281,6 +287,7 @@ int main(int argc, char **argv) { "punch-hole", 0, 0, 'p' }, { "collapse-range", 0, 0, 'c' }, { "dig-holes", 0, 0, 'd' }, + { "insert-range", 0, 0, 'i' }, { "zero-range", 0, 0, 'z' }, { "offset", 1, 0, 'o' }, { "length", 1, 0, 'l' }, @@ -300,7 +307,7 @@ int main(int argc, char **argv) textdomain(PACKAGE); atexit(close_stdout); - while ((c = getopt_long(argc, argv, "hvVncpdzl:o:", longopts, NULL)) + while ((c = getopt_long(argc, argv, "hvVncpdizl:o:", longopts, NULL)) != -1) { err_exclusive_options(c, longopts, excl, excl_st); @@ -315,6 +322,9 @@ int main(int argc, char **argv) case 'd': dig = 1; break; + case 'i': + mode |= FALLOC_FL_INSERT_RANGE; + break; case 'l': length = cvtnum(optarg); break; |