aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--difftool/compare_files.c60
-rw-r--r--difftool/extract.c13
-rw-r--r--difftool/options.c8
-rw-r--r--difftool/sqfsdiff.c81
-rw-r--r--difftool/sqfsdiff.h7
-rw-r--r--doc/sqfsdiff.18
6 files changed, 30 insertions, 147 deletions
diff --git a/difftool/compare_files.c b/difftool/compare_files.c
index df767c1..6138569 100644
--- a/difftool/compare_files.c
+++ b/difftool/compare_files.c
@@ -9,30 +9,14 @@
static unsigned char old_buf[MAX_WINDOW_SIZE];
static unsigned char new_buf[MAX_WINDOW_SIZE];
-static int open_file(int dirfd, const char *prefix, const char *path)
-{
- int fd = openat(dirfd, path, O_RDONLY);
-
- if (fd < 0) {
- fprintf(stderr, "open %s/%s: %s\n",
- prefix, path, strerror(errno));
- }
-
- return fd;
-}
-
-static int read_blob(const char *prefix, const char *path, bool is_dir,
- int fd, data_reader_t *rd, file_info_t *fi, void *buffer,
+static int read_blob(const char *prefix, const char *path,
+ data_reader_t *rd, file_info_t *fi, void *buffer,
off_t offset, size_t size)
{
ssize_t ret;
- if (is_dir) {
- ret = read_data_at(path, offset, fd, buffer, size);
- } else {
- ret = data_reader_read(rd, fi, offset, buffer, size);
- ret = (ret < 0 || (size_t)ret < size) ? -1 : 0;
- }
+ ret = data_reader_read(rd, fi, offset, buffer, size);
+ ret = (ret < 0 || (size_t)ret < size) ? -1 : 0;
if (ret) {
fprintf(stderr, "Failed to read %s from %s\n",
@@ -46,8 +30,8 @@ static int read_blob(const char *prefix, const char *path, bool is_dir,
int compare_files(sqfsdiff_t *sd, file_info_t *old, file_info_t *new,
const char *path)
{
- int old_fd = -1, new_fd = -1, status = 0, ret;
uint64_t offset, diff;
+ int status = 0, ret;
if (old->size != new->size)
goto out_different;
@@ -55,51 +39,31 @@ int compare_files(sqfsdiff_t *sd, file_info_t *old, file_info_t *new,
if (sd->compare_flags & COMPARE_NO_CONTENTS)
return 0;
- if (sd->old_is_dir) {
- old_fd = open_file(sd->old_fd, sd->old_path, path);
- if (old_fd < 0)
- goto fail;
- }
-
- if (sd->new_is_dir) {
- new_fd = open_file(sd->new_fd, sd->new_path, path);
- if (new_fd < 0)
- goto fail;
- }
-
for (offset = 0; offset < old->size; offset += diff) {
diff = old->size - offset;
if (diff > MAX_WINDOW_SIZE)
diff = MAX_WINDOW_SIZE;
- ret = read_blob(sd->old_path, path, sd->old_is_dir, old_fd,
+ ret = read_blob(sd->old_path, path,
sd->sqfs_old.data, old, old_buf, offset, diff);
if (ret)
- goto fail;
+ return -1;
- ret = read_blob(sd->new_path, path, sd->new_is_dir, new_fd,
+ ret = read_blob(sd->new_path, path,
sd->sqfs_new.data, new, new_buf, offset, diff);
if (ret)
- goto fail;
+ return -1;
if (memcmp(old_buf, new_buf, diff) != 0)
goto out_different;
}
-out:
- if (old_fd >= 0)
- close(old_fd);
- if (new_fd >= 0)
- close(new_fd);
+
return status;
-fail:
- status = -1;
- goto out;
out_different:
if (sd->compare_flags & COMPARE_EXTRACT_FILES) {
if (extract_files(sd, old, new, path))
- goto fail;
+ return -1;
}
- status = 1;
- goto out;
+ return 1;
}
diff --git a/difftool/extract.c b/difftool/extract.c
index 9fec818..2e92710 100644
--- a/difftool/extract.c
+++ b/difftool/extract.c
@@ -39,14 +39,11 @@ static int extract(data_reader_t *data, file_info_t *fi,
int extract_files(sqfsdiff_t *sd, file_info_t *old, file_info_t *new,
const char *path)
{
- if (old != NULL && !sd->old_is_dir) {
- if (extract(sd->sqfs_old.data, old, "old", path))
- return -1;
- }
+ if (extract(sd->sqfs_old.data, old, "old", path))
+ return -1;
+
+ if (extract(sd->sqfs_new.data, new, "new", path))
+ return -1;
- if (new != NULL && !sd->new_is_dir) {
- if (extract(sd->sqfs_new.data, new, "new", path))
- return -1;
- }
return 0;
}
diff --git a/difftool/options.c b/difftool/options.c
index 82b6ddc..37465e8 100644
--- a/difftool/options.c
+++ b/difftool/options.c
@@ -29,12 +29,8 @@ static const char *usagestr =
"images, this actually parses the filesystems and generates a more\n"
"meaningful difference report.\n"
"\n"
-"The tool can also compare the contents of a squashfs image to a directory.\n"
-"This case is detected transparently if --new or --old referes to a directory\n"
-"instead of a squashfs image.\n"
-"\n"
"If only contents are compared, any differences in packed file layout,\n"
-"ordering, compression, inode allocation and so on is ignored and the two\n"
+"ordering, compression, inode meta data and so on is ignored and the two\n"
"images are considered equal if each directory contains the same entries,\n"
"symlink with the same paths have the same targets, device nodes the same\n"
"device number and files the same size and contents.\n"
@@ -53,7 +49,7 @@ static const char *usagestr =
"\n"
" --timestamps, -T Compare file timestamps.\n"
" --inode-num, -I Compare inode numbers of all files.\n"
-" --super, -S Also compare metadata in super blocks.\n"
+" --super, -S Also compare meta data in super blocks.\n"
"\n"
" --extract, -e <path> Extract files that differ to the specified\n"
" directory. Contents of the first filesystem\n"
diff --git a/difftool/sqfsdiff.c b/difftool/sqfsdiff.c
index 777678b..a661223 100644
--- a/difftool/sqfsdiff.c
+++ b/difftool/sqfsdiff.c
@@ -8,7 +8,7 @@
int main(int argc, char **argv)
{
- int status, dirscan_flags = 0, ret = 0;
+ int status, ret = 0;
sqfsdiff_t sd;
memset(&sd, 0, sizeof(sd));
@@ -19,65 +19,12 @@ int main(int argc, char **argv)
return 2;
}
- if (sd.compare_flags & COMPARE_TIMESTAMP)
- dirscan_flags |= DIR_SCAN_READ_XATTR;
+ if (sqfs_reader_open(&sd.sqfs_old, sd.old_path))
+ return 2;
- /* open first source */
- sd.old_fd = open(sd.old_path, O_DIRECTORY | O_PATH | O_RDONLY);
- if (sd.old_fd < 0) {
- if (errno == ENOTDIR) {
- sd.old_is_dir = false;
-
- if (sqfs_reader_open(&sd.sqfs_old, sd.old_path))
- return 2;
- } else {
- perror(sd.old_path);
- return 2;
- }
- } else {
- sd.old_is_dir = true;
- if (fstree_init(&sd.sqfs_old.fs, 512, NULL))
- return 2;
-
- if (fstree_from_dir(&sd.sqfs_old.fs, sd.old_path,
- dirscan_flags)) {
- fstree_cleanup(&sd.sqfs_old.fs);
- return 2;
- }
-
- tree_node_sort_recursive(sd.sqfs_old.fs.root);
- }
-
- /* open second source */
- sd.new_fd = open(sd.new_path, O_DIRECTORY | O_PATH | O_RDONLY);
- if (sd.new_fd < 0) {
- if (errno == ENOTDIR) {
- sd.new_is_dir = false;
-
- if (sqfs_reader_open(&sd.sqfs_new, sd.new_path)) {
- status = 2;
- goto out_sqfs_old;
- }
- } else {
- status = 2;
- perror(sd.new_path);
- goto out_sqfs_old;
- }
- } else {
- sd.new_is_dir = true;
- if (fstree_init(&sd.sqfs_new.fs, 512, NULL)) {
- status = 2;
- goto out_sqfs_old;
- }
-
- if (fstree_from_dir(&sd.sqfs_new.fs, sd.new_path,
- dirscan_flags)) {
- status = 2;
- fstree_cleanup(&sd.sqfs_old.fs);
- goto out_sqfs_old;
- }
-
- tree_node_sort_recursive(sd.sqfs_new.fs.root);
+ if (sqfs_reader_open(&sd.sqfs_new, sd.new_path)) {
+ status = 2;
+ goto out_sqfs_old;
}
if (sd.extract_dir != NULL) {
@@ -92,7 +39,7 @@ int main(int argc, char **argv)
if (ret != 0)
goto out;
- if (sd.compare_super && !sd.old_is_dir && !sd.new_is_dir) {
+ if (sd.compare_super) {
ret = compare_super_blocks(&sd.sqfs_old.super,
&sd.sqfs_new.super);
if (ret != 0)
@@ -106,18 +53,8 @@ out:
} else {
status = 0;
}
- if (sd.new_is_dir) {
- close(sd.new_fd);
- fstree_cleanup(&sd.sqfs_new.fs);
- } else {
- sqfs_reader_close(&sd.sqfs_new);
- }
+ sqfs_reader_close(&sd.sqfs_new);
out_sqfs_old:
- if (sd.old_is_dir) {
- close(sd.old_fd);
- fstree_cleanup(&sd.sqfs_old.fs);
- } else {
- sqfs_reader_close(&sd.sqfs_old);
- }
+ sqfs_reader_close(&sd.sqfs_old);
return status;
}
diff --git a/difftool/sqfsdiff.h b/difftool/sqfsdiff.h
index 36b97b6..d9a01c2 100644
--- a/difftool/sqfsdiff.h
+++ b/difftool/sqfsdiff.h
@@ -13,7 +13,6 @@
#include "fstree.h"
#include "util.h"
-#include <sys/mman.h>
#include <unistd.h>
#include <stdlib.h>
#include <getopt.h>
@@ -29,14 +28,8 @@ typedef struct {
int compare_flags;
sqfs_reader_t sqfs_old;
sqfs_reader_t sqfs_new;
- bool old_is_dir;
- bool new_is_dir;
bool compare_super;
const char *extract_dir;
-
- /* holds the coresponding dirfds if old or new is a directory */
- int old_fd;
- int new_fd;
} sqfsdiff_t;
enum {
diff --git a/doc/sqfsdiff.1 b/doc/sqfsdiff.1
index 3822308..c0ee550 100644
--- a/doc/sqfsdiff.1
+++ b/doc/sqfsdiff.1
@@ -9,12 +9,8 @@ Compare two squashfs images. In contrast to doing a direct diff of the
images, this actually parses the filesystems and generates a more
meaningful difference report.
.PP
-The tool can also compare the contents of a squashfs image to a directory.
-This case is detected transparently if \fB\-\-new\fR or \fB\-\-old\fR referes
-to a directory instead of a squashfs image.
-.PP
If only contents are compared, any differences in packed file layout,
-ordering, compression, inode allocation and so on is ignored and the two
+ordering, compression, inode meta data and so on is ignored and the two
images are considered equal if each directory contains the same entries,
symlink with the same paths have the same targets, device nodes the same
device number and files the same size and contents.
@@ -48,7 +44,7 @@ Compare file timestamps.
Compare inode numbers of all files.
.TP
\fB\-\-super\fR, \fB\-S\fR
-Also compare metadata in super blocks.
+Also compare meta data in super blocks.
.TP
\fB\-\-extract\fR, \fB\-e\fR <path>
Extract files that exist in both images but have different contents to the