summaryrefslogtreecommitdiff
path: root/difftool
diff options
context:
space:
mode:
Diffstat (limited to 'difftool')
-rw-r--r--difftool/compare_files.c72
-rw-r--r--difftool/difftool.h12
-rw-r--r--difftool/extract.c10
-rw-r--r--difftool/sqfsdiff.c36
4 files changed, 66 insertions, 64 deletions
diff --git a/difftool/compare_files.c b/difftool/compare_files.c
index 89c5f5c..04749c3 100644
--- a/difftool/compare_files.c
+++ b/difftool/compare_files.c
@@ -6,90 +6,92 @@
*/
#include "difftool.h"
-static unsigned char a_buf[MAX_WINDOW_SIZE];
-static unsigned char b_buf[MAX_WINDOW_SIZE];
+static unsigned char old_buf[MAX_WINDOW_SIZE];
+static unsigned char new_buf[MAX_WINDOW_SIZE];
-int compare_files(file_info_t *a, file_info_t *b, const char *path)
+int compare_files(file_info_t *old, file_info_t *new, const char *path)
{
- char second_name[strlen(second_path) + strlen(path) + 2];
- char first_name[strlen(first_path) + strlen(path) + 2];
- int afd = -1, bfd = -1, status = 0;
+ char new_name[strlen(new_path) + strlen(path) + 2];
+ char old_name[strlen(old_path) + strlen(path) + 2];
+ int old_fd = -1, new_fd = -1, status = 0;
uint64_t offset, diff;
ssize_t ret;
- if (a->size != b->size)
+ if (old->size != new->size)
goto out_different;
if (compare_flags & COMPARE_NO_CONTENTS)
return 0;
- if (a_is_dir) {
- sprintf(first_name, "%s/%s", first_path, path);
+ if (old_is_dir) {
+ sprintf(old_name, "%s/%s", old_path, path);
- afd = open(first_name, O_RDONLY);
- if (afd < 0) {
- perror(first_name);
+ old_fd = open(old_name, O_RDONLY);
+ if (old_fd < 0) {
+ perror(old_name);
goto fail;
}
}
- if (b_is_dir) {
- sprintf(second_name, "%s/%s", second_path, path);
+ if (new_is_dir) {
+ sprintf(new_name, "%s/%s", new_path, path);
- bfd = open(second_name, O_RDONLY);
- if (bfd < 0) {
- perror(second_name);
+ new_fd = open(new_name, O_RDONLY);
+ if (new_fd < 0) {
+ perror(new_name);
goto fail;
}
}
- for (offset = 0; offset < a->size; offset += diff) {
- diff = a->size - offset;
+ for (offset = 0; offset < old->size; offset += diff) {
+ diff = old->size - offset;
if (diff > MAX_WINDOW_SIZE)
diff = MAX_WINDOW_SIZE;
- if (a_is_dir) {
- if (read_data_at(first_name, offset, afd, a_buf, diff))
+ if (old_is_dir) {
+ if (read_data_at(old_name, offset, old_fd,
+ old_buf, diff))
goto out;
} else {
- ret = data_reader_read(sqfs_a.data, a, offset,
- a_buf, diff);
+ ret = data_reader_read(sqfs_old.data, old, offset,
+ old_buf, diff);
if (ret < 0 || (size_t)ret < diff) {
fprintf(stderr, "Failed to read %s from %s\n",
- path, first_path);
+ path, old_path);
return -1;
}
}
- if (b_is_dir) {
- if (read_data_at(second_name, offset, bfd, b_buf, diff))
+ if (new_is_dir) {
+ if (read_data_at(new_name, offset, new_fd,
+ new_buf, diff))
goto out;
} else {
- ret = data_reader_read(sqfs_b.data, b, offset,
- b_buf, diff);
+ ret = data_reader_read(sqfs_new.data, new, offset,
+ new_buf, diff);
if (ret < 0 || (size_t)ret < diff) {
fprintf(stderr, "Failed to read %s from %s\n",
- path, second_path);
+ path, new_path);
return -1;
}
}
- if (memcmp(a_buf, b_buf, diff) != 0)
+ if (memcmp(old_buf, new_buf, diff) != 0)
goto out_different;
}
out:
- if (afd >= 0)
- close(afd);
- if (bfd >= 0)
- close(bfd);
+ if (old_fd >= 0)
+ close(old_fd);
+ if (new_fd >= 0)
+ close(new_fd);
return status;
fail:
status = -1;
goto out;
out_different:
if (compare_flags & COMPARE_EXTRACT_FILES) {
- if (extract_files(a, b, path))
+ if (extract_files(old, new, path))
goto fail;
}
status = 1;
diff --git a/difftool/difftool.h b/difftool/difftool.h
index 56f727a..bf63faf 100644
--- a/difftool/difftool.h
+++ b/difftool/difftool.h
@@ -23,13 +23,13 @@
#define MAX_WINDOW_SIZE (1024 * 1024 * 4)
-extern const char *first_path;
-extern const char *second_path;
+extern const char *old_path;
+extern const char *new_path;
extern int compare_flags;
-extern sqfs_reader_t sqfs_a;
-extern sqfs_reader_t sqfs_b;
-extern bool a_is_dir;
-extern bool b_is_dir;
+extern sqfs_reader_t sqfs_old;
+extern sqfs_reader_t sqfs_new;
+extern bool old_is_dir;
+extern bool new_is_dir;
enum {
COMPARE_NO_PERM = 0x01,
diff --git a/difftool/extract.c b/difftool/extract.c
index 9fee46d..7d4fc1c 100644
--- a/difftool/extract.c
+++ b/difftool/extract.c
@@ -37,15 +37,15 @@ static int extract(data_reader_t *data, file_info_t *fi,
return 0;
}
-int extract_files(file_info_t *a, file_info_t *b, const char *path)
+int extract_files(file_info_t *old, file_info_t *new, const char *path)
{
- if (a != NULL && !a_is_dir) {
- if (extract(sqfs_a.data, a, path, 'a'))
+ if (old != NULL && !old_is_dir) {
+ if (extract(sqfs_old.data, old, path, 'a'))
return -1;
}
- if (b != NULL && !b_is_dir) {
- if (extract(sqfs_b.data, b, path, 'b'))
+ if (new != NULL && !new_is_dir) {
+ if (extract(sqfs_new.data, new, path, 'b'))
return -1;
}
return 0;
diff --git a/difftool/sqfsdiff.c b/difftool/sqfsdiff.c
index 9197430..a065a8f 100644
--- a/difftool/sqfsdiff.c
+++ b/difftool/sqfsdiff.c
@@ -61,12 +61,12 @@ static const char *usagestr =
"\n";
int compare_flags = 0;
-const char *first_path;
-const char *second_path;
-sqfs_reader_t sqfs_a;
-sqfs_reader_t sqfs_b;
-bool a_is_dir;
-bool b_is_dir;
+const char *old_path;
+const char *new_path;
+sqfs_reader_t sqfs_old;
+sqfs_reader_t sqfs_new;
+bool old_is_dir;
+bool new_is_dir;
static bool compare_super = false;
static const char *extract_dir;
@@ -81,10 +81,10 @@ static void process_options(int argc, char **argv)
switch (i) {
case 'a':
- first_path = optarg;
+ old_path = optarg;
break;
case 'b':
- second_path = optarg;
+ new_path = optarg;
break;
case 'O':
compare_flags |= COMPARE_NO_OWNER;
@@ -119,12 +119,12 @@ static void process_options(int argc, char **argv)
}
}
- if (first_path == NULL) {
+ if (old_path == NULL) {
fputs("Missing arguments: first filesystem\n", stderr);
goto fail_arg;
}
- if (second_path == NULL) {
+ if (new_path == NULL) {
fputs("Missing arguments: second filesystem\n", stderr);
goto fail_arg;
}
@@ -150,12 +150,12 @@ int main(int argc, char **argv)
return EXIT_FAILURE;
}
- if (sqfs_reader_open(&sqfs_a, first_path, 0))
+ if (sqfs_reader_open(&sqfs_old, old_path, 0))
return 2;
- if (sqfs_reader_open(&sqfs_b, second_path, 0)) {
+ if (sqfs_reader_open(&sqfs_new, new_path, 0)) {
status = 2;
- goto out_sqfs_a;
+ goto out_sqfs_old;
}
if (extract_dir != NULL) {
@@ -166,12 +166,12 @@ int main(int argc, char **argv)
}
}
- ret = node_compare(sqfs_a.fs.root, sqfs_b.fs.root);
+ ret = node_compare(sqfs_old.fs.root, sqfs_new.fs.root);
if (ret != 0)
goto out;
if (compare_super) {
- ret = compare_super_blocks(&sqfs_a.super, &sqfs_b.super);
+ ret = compare_super_blocks(&sqfs_old.super, &sqfs_new.super);
if (ret != 0)
goto out;
}
@@ -183,8 +183,8 @@ out:
} else {
status = 0;
}
- sqfs_reader_close(&sqfs_b);
-out_sqfs_a:
- sqfs_reader_close(&sqfs_a);
+ sqfs_reader_close(&sqfs_new);
+out_sqfs_old:
+ sqfs_reader_close(&sqfs_old);
return status;
}