aboutsummaryrefslogtreecommitdiff
path: root/difftool/compare_files_sqfs.c
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-08-07 11:09:34 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-08-07 11:24:20 +0200
commitd6149732b67fbedc7ac2d2ba984c07ab466392f1 (patch)
tree80e0fd22e6110fb1c5b977ac687479d9f7a9a21a /difftool/compare_files_sqfs.c
parent73b4ec8392541a27815bccbaeccbdf1cdd5e19dd (diff)
Extend filesystem diff utility to work on squashfs images
Since it already works on an fstree_t instance (constructed from the input paths), and we now have a handy sqfs_reader_t, it is quite simple to extend. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'difftool/compare_files_sqfs.c')
-rw-r--r--difftool/compare_files_sqfs.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/difftool/compare_files_sqfs.c b/difftool/compare_files_sqfs.c
new file mode 100644
index 0000000..d8bef83
--- /dev/null
+++ b/difftool/compare_files_sqfs.c
@@ -0,0 +1,45 @@
+/* SPDX-License-Identifier: GPL-3.0-or-later */
+/*
+ * compare_file_sfqs.c
+ *
+ * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
+ */
+#include "difftool.h"
+
+static unsigned char a_buf[MAX_WINDOW_SIZE];
+static unsigned char b_buf[MAX_WINDOW_SIZE];
+
+int compare_files(file_info_t *a, file_info_t *b, const char *path)
+{
+ uint64_t offset, diff;
+ ssize_t ret;
+
+ if (a->size != b->size)
+ return 1;
+
+ for (offset = 0; offset < a->size; offset += diff) {
+ diff = a->size - offset;
+
+ if (diff > MAX_WINDOW_SIZE)
+ diff = MAX_WINDOW_SIZE;
+
+ ret = data_reader_read(sqfs_a.data, a, offset, a_buf, diff);
+ if (ret < 0 || (size_t)ret < diff) {
+ fprintf(stderr, "Failed to read %s from %s\n",
+ path, first_path);
+ return -1;
+ }
+
+ ret = data_reader_read(sqfs_b.data, b, offset, b_buf, diff);
+ if (ret < 0 || (size_t)ret < diff) {
+ fprintf(stderr, "Failed to read %s from %s\n",
+ path, second_path);
+ return -1;
+ }
+
+ if (memcmp(a_buf, b_buf, diff) != 0)
+ return 1;
+ }
+
+ return 0;
+}