summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Cady <d@cryptonomic.net>2022-01-10 22:42:19 -0500
committerAndrew Cady <d@cryptonomic.net>2022-01-10 22:45:56 -0500
commitaef91306e38b72a9704c056e4c951c04b8843ca9 (patch)
tree68ad3e65c6f44a6e6424195dd131f7629cd9e3bd
parent21349c6f71eb1aa0a36a5adcd22248a249114ca7 (diff)
switch to C ficlonerange instead of Python
-rw-r--r--Makefile4
-rwxr-xr-xsrc/partvi2
-rw-r--r--src/samizdat-ficlonerange.c51
3 files changed, 55 insertions, 2 deletions
diff --git a/Makefile b/Makefile
index bb35b13..3445d1f 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
1prefix?=/usr/local 1prefix?=/usr/local
2 2
3cc_files=wait_for_files samizdat-pinentry krng-add-entropy 3cc_files=wait_for_files samizdat-pinentry krng-add-entropy samizdat-ficlonerange
4cpp_files=dynmenu 4cpp_files=dynmenu
5 5
6compiled_programs=${cc_files} ${cpp_files} 6compiled_programs=${cc_files} ${cpp_files}
@@ -34,6 +34,8 @@ krng-add-entropy: src/krng-add-entropy.c | build-deps
34 $(CC) $(CFLAGS) $< -o $@ 34 $(CC) $(CFLAGS) $< -o $@
35wait_for_files: src/wait_for_files.c | build-deps 35wait_for_files: src/wait_for_files.c | build-deps
36 $(CC) $(CFLAGS) $< -o $@ 36 $(CC) $(CFLAGS) $< -o $@
37%: src/%.c | build-deps
38 $(CC) $(CFLAGS) $< -o $@
37 39
38dyndns_realprog = dyndns.ssh-rsa.cryptonomic.net 40dyndns_realprog = dyndns.ssh-rsa.cryptonomic.net
39dyndns_links = dyndns.ssh-dss.cryptonomic.net \ 41dyndns_links = dyndns.ssh-dss.cryptonomic.net \
diff --git a/src/partvi b/src/partvi
index a0ac679..3b622ed 100755
--- a/src/partvi
+++ b/src/partvi
@@ -272,7 +272,7 @@ clone_parts_to_target()
272{ 272{
273 273
274 f=$(readlink -e "$builddir"/"${f%.conf}") || return 274 f=$(readlink -e "$builddir"/"${f%.conf}") || return
275 ficlonerange.py "$f" "$target" 275 samizdat-ficlonerange "$f" "$target" 0 0 0
276} 276}
277 277
278cleanup() 278cleanup()
diff --git a/src/samizdat-ficlonerange.c b/src/samizdat-ficlonerange.c
new file mode 100644
index 0000000..a620cbf
--- /dev/null
+++ b/src/samizdat-ficlonerange.c
@@ -0,0 +1,51 @@
1#include <fcntl.h>
2#include <linux/fs.h>
3#include <stdio.h>
4#include <stdlib.h>
5#include <sys/ioctl.h>
6#include <sys/stat.h>
7#include <sys/types.h>
8
9int main(int argc, char **argv)
10{
11 if (argc != 6)
12 {
13 fputs("Error: usage: wrong number of arguments\n", stderr);
14 return -1;
15 }
16 char *src_name = argv[1];
17 char *dest_name = argv[2];
18 u_int64_t src_offset = atoll(argv[3]);
19 u_int64_t src_length = atoll(argv[4]);
20 u_int64_t dest_offset = atoll(argv[5]);
21
22 int src, dest;
23 if ((src = open(src_name, O_RDONLY)) < 0)
24 {
25 perror("Error opening input file");
26 return 1;
27 }
28 if ((dest = open(dest_name, O_RDWR | O_CREAT)) < 0)
29 {
30 perror("Error opening output file");
31 return 2;
32 }
33 if (dest_offset == 0)
34 {
35 struct stat buf;
36 stat(dest_name, &buf);
37 dest_offset = buf.st_size;
38 }
39
40 struct file_clone_range s = {src, src_offset, src_length, dest_offset};
41 if (ioctl(dest, FICLONERANGE, &s))
42 {
43 perror("ioctl FICLONERANGE failed");
44 return 3;
45 }
46 else
47 {
48 return 0;
49 }
50}
51