summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@beefcake.parabola.nu>2018-08-11 19:33:38 -0400
committerLuke Shumaker <lukeshu@beefcake.parabola.nu>2018-08-11 19:33:38 -0400
commit779fc0a3e637fe8b339c04b7a79984a324edfcf8 (patch)
treec1e3be469e7438068d0bc26cd167ed26230a1d03
parent1ff3ecb5b08b40686b0e03cf79c4233c5bf99396 (diff)
fastsumsystemd
-rw-r--r--.gitignore1
-rw-r--r--Makefile1
-rw-r--r--go/src/cow-dedupe/dedupe.go2
-rw-r--r--src/fastsum.c53
4 files changed, 56 insertions, 1 deletions
diff --git a/.gitignore b/.gitignore
index 59a4ba5..0f4733c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,3 @@
/cow-*
*.o
+/fastsum
diff --git a/Makefile b/Makefile
index fe3d2ca..2d52dd6 100644
--- a/Makefile
+++ b/Makefile
@@ -11,6 +11,7 @@ CPPFLAGS += -O2 -D_FORTIFY_SOURCE=2
all: cow-dedupe-range
all: cow-extent-map
all: cow-dedupe
+all: fastsum
.PHONY: all
%: src/%.o
diff --git a/go/src/cow-dedupe/dedupe.go b/go/src/cow-dedupe/dedupe.go
index 0c40d4a..42a0178 100644
--- a/go/src/cow-dedupe/dedupe.go
+++ b/go/src/cow-dedupe/dedupe.go
@@ -264,7 +264,7 @@ func main() {
sl = myStatusLine()
size2filenames := getChecksums(sl, "Getting sizes for files... %v/%v",
- []string{"stat", "--printf=%s %n\\n", "--"}, spanningFiles)
+ []string{"./fastsum"}, spanningFiles)
sl.End(true)
fmt.Fprintf(os.Stderr, " -> %d sets", len(size2filenames))
diff --git a/src/fastsum.c b/src/fastsum.c
new file mode 100644
index 0000000..4578ff2
--- /dev/null
+++ b/src/fastsum.c
@@ -0,0 +1,53 @@
+#include <errno.h> /* for errno */
+#include <error.h> /* for error(3gnu) */
+#include <fcntl.h> /* for O_RDONLY */
+#include <inttypes.h> /* for PRI*, uint*_t, int*_t */
+#include <stdbool.h> /* for bool */
+#include <stdio.h> /* for printf */
+#include <sys/stat.h> /* for open(2), fstat(2) and struct stat */
+#include <unistd.h> /* for close(2), read(2), lseek(2), SEEK_SET */
+
+int main(int argc, char *argv[]) {
+ bool err = false;
+ for (int i = 1; i < argc; i++) {
+ const char *filename = argv[i];
+
+ int fd = open(filename, O_RDONLY);
+ if (fd < 0) {
+ err = true;
+ error(0, errno, "open %s", filename);
+ continue;
+ }
+
+ struct stat st;
+ if (fstat(fd, &st) < 0) {
+ err = true;
+ error(0, errno, "fstat %s", filename);
+ close(fd);
+ continue;
+ }
+
+ if (lseek(fd, st.st_size/2, SEEK_SET) < 0) {
+ err = true;
+ error(0, errno, "lseek %s", filename);
+ close(fd);
+ continue;
+ }
+
+ uint8_t b;
+ int n = read(fd, &b, sizeof(b));
+ if (n <= 0) {
+ if (n == 0)
+ error(0, 0, "read %s: unexpected end of file", filename);
+ else
+ error(0, errno, "read %s", filename);
+ err = true;
+ close(fd);
+ continue;
+ }
+
+ printf("%"PRId64":%"PRIx8" %s\n", (int64_t)st.st_size, b, filename);
+ close(fd);
+ }
+ return err ? 1 : 0;
+}