summaryrefslogtreecommitdiff
path: root/src/cow-dedupe-range.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/cow-dedupe-range.c')
-rw-r--r--src/cow-dedupe-range.c26
1 files changed, 14 insertions, 12 deletions
diff --git a/src/cow-dedupe-range.c b/src/cow-dedupe-range.c
index bffa8f1..b96ead1 100644
--- a/src/cow-dedupe-range.c
+++ b/src/cow-dedupe-range.c
@@ -34,9 +34,9 @@ bool atou64(const char *str, uint64_t *ret) {
}
void usage() {
- printf("Usage: %2$*1$s [OPTIONS] SRC_FILENAME SRC_OFFSET SRC_LENGTH \\\n"
- " %3$*1$s DST_FILENAME DST_OFFSET \\\n"
- " %3$*1$s [DST_FILENAME DST_OFFSET]...\n"
+ printf("Usage: %2$*1$s [OPTIONS] LENGTH SRC_FILENAME SRC_OFFSET \\\n"
+ " %3$*1$s DST_FILENAME DST_OFFSET \\\n"
+ " %3$*1$s [DST_FILENAME DST_OFFSET]...\n"
"Submit a file deduplication request to the kernel.\n"
"If the file ranges are not duplicates, the kernel will ignore this request.\n"
"\n"
@@ -76,19 +76,21 @@ int main(int argc, char *argv[]) {
}
if (argc - optind < 5)
errusage("too few arguments");
- if ((argc - optind - 3) % 2 != 0)
+ if ((argc - optind - 1) % 2 != 0)
errusage("wrong number of arguments");
- struct range src;
- src.filename = argv[optind];
+ uint64_t src_length;
+ if (!atou64(argv[optind], &src_length))
+ error(2, errno, "invalid length '%s'", argv[optind]);
+
+ struct filepos src;
+ src.filename = argv[optind+1];
src.flags = O_RDONLY;
- if (!atou64(argv[optind+1], &src.offset))
- error(2, errno, "invalid offset '%s'", argv[optind+1]);
- if (!atou64(argv[optind+2], &src.length))
- error(2, errno, "invalid length '%s'", argv[optind+2]);
+ if (!atou64(argv[optind+2], &src.offset))
+ error(2, errno, "invalid offset '%s'", argv[optind+2]);
const size_t dst_count = (argc - optind - 3) / 2;
- struct range *dsts = calloc(dst_count + 1, sizeof(struct range));
+ struct filepos *dsts = calloc(dst_count + 1, sizeof(struct filepos));
for (size_t i = 0; i < dst_count; i++) {
dsts[i].filename = argv[optind+3+(i*2)];
dsts[i].flags = ro ? O_RDONLY : O_RDWR;
@@ -96,7 +98,7 @@ int main(int argc, char *argv[]) {
error(2, errno, "invalid offset '%s'", argv[optind+3+(i*2)+1]);
}
- dedupe_range(src, dsts);
+ dedupe_range(src_length, src, dsts);
free(dsts);
return EXIT_SUCCESS;
}