diff options
author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2019-10-06 19:01:11 +0200 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2019-10-06 19:08:01 +0200 |
commit | 41ddda0c732d916a6962c54a3a974a8b753f194b (patch) | |
tree | 5ea74ef79c89d41e936dfbb8dc4d65ddbcde1a7d | |
parent | 19b7609586aac382f21bdc5c7369c56417775d6d (diff) |
Improve error reporting for sqfs2tar, rdsquashfs, sqfsdiff
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
-rw-r--r-- | difftool/extract.c | 2 | ||||
-rw-r--r-- | difftool/node_compare.c | 4 | ||||
-rw-r--r-- | difftool/sqfsdiff.c | 40 | ||||
-rw-r--r-- | difftool/sqfsdiff.h | 1 | ||||
-rw-r--r-- | include/highlevel.h | 2 | ||||
-rw-r--r-- | lib/sqfshelper/data_reader_dump.c | 10 | ||||
-rw-r--r-- | tar/sqfs2tar.c | 90 | ||||
-rw-r--r-- | unpack/fill_files.c | 3 | ||||
-rw-r--r-- | unpack/rdsquashfs.c | 56 | ||||
-rw-r--r-- | unpack/rdsquashfs.h | 1 |
10 files changed, 139 insertions, 70 deletions
diff --git a/difftool/extract.c b/difftool/extract.c index c0cebfd..df00977 100644 --- a/difftool/extract.c +++ b/difftool/extract.c @@ -27,7 +27,7 @@ static int extract(sqfs_data_reader_t *data, const sqfs_inode_generic_t *inode, return -1; } - if (sqfs_data_reader_dump(data, inode, fd, block_size, true)) { + if (sqfs_data_reader_dump(path, data, inode, fd, block_size, true)) { close(fd); return -1; } diff --git a/difftool/node_compare.c b/difftool/node_compare.c index 7638805..1612d34 100644 --- a/difftool/node_compare.c +++ b/difftool/node_compare.c @@ -12,8 +12,10 @@ int node_compare(sqfsdiff_t *sd, sqfs_tree_node_t *a, sqfs_tree_node_t *b) sqfs_tree_node_t *ait, *bit; int ret, status = 0; - if (path == NULL) + if (path == NULL) { + perror("constructing absolute file path"); return -1; + } if (a->inode->base.type != b->inode->base.type) { fprintf(stdout, "%s has a different type\n", path); diff --git a/difftool/sqfsdiff.c b/difftool/sqfsdiff.c index 4209c9a..7479938 100644 --- a/difftool/sqfsdiff.c +++ b/difftool/sqfsdiff.c @@ -8,15 +8,17 @@ static int open_sfqs(sqfs_state_t *state, const char *path) { + int ret; + state->file = sqfs_open_file(path, SQFS_FILE_OPEN_READ_ONLY); if (state->file == NULL) { perror(path); return -1; } - if (sqfs_super_read(&state->super, state->file)) { - fprintf(stderr, "error reading super block from %s\n", - path); + ret = sqfs_super_read(&state->super, state->file); + if (ret) { + sqfs_perror(path, "reading super block", ret); goto fail_file; } @@ -37,35 +39,38 @@ static int open_sfqs(sqfs_state_t *state, const char *path) } if (state->super.flags & SQFS_FLAG_COMPRESSOR_OPTIONS) { - if (state->cmp->read_options(state->cmp, state->file)) { - fprintf(stderr, "%s: error loading compressor " - "options.\n", path); + ret = state->cmp->read_options(state->cmp, state->file); + if (ret) { + sqfs_perror(path, "reading compressor options", ret); goto fail_cmp; } } state->idtbl = sqfs_id_table_create(); if (state->idtbl == NULL) { - perror("error creating ID table"); + sqfs_perror(path, "creating ID table", SQFS_ERROR_ALLOC); goto fail_cmp; } - if (sqfs_id_table_read(state->idtbl, state->file, - &state->super, state->cmp)) { - fprintf(stderr, "%s: error loading ID table\n", path); + ret = sqfs_id_table_read(state->idtbl, state->file, + &state->super, state->cmp); + if (ret) { + sqfs_perror(path, "loading ID table", ret); goto fail_id; } state->dr = sqfs_dir_reader_create(&state->super, state->cmp, state->file); if (state->dr == NULL) { - perror("creating directory reader"); + sqfs_perror(path, "creating directory reader", + SQFS_ERROR_ALLOC); goto fail_id; } - if (sqfs_dir_reader_get_full_hierarchy(state->dr, state->idtbl, - NULL, 0, &state->root)) { - fprintf(stderr, "%s: error loading file system tree\n", path); + ret = sqfs_dir_reader_get_full_hierarchy(state->dr, state->idtbl, + NULL, 0, &state->root); + if (ret) { + sqfs_perror(path, "loading filesystem tree", ret); goto fail_dr; } @@ -73,12 +78,15 @@ static int open_sfqs(sqfs_state_t *state, const char *path) state->super.block_size, state->cmp); if (state->data == NULL) { - fprintf(stderr, "%s: error loading file system tree\n", path); + sqfs_perror(path, "creating data reader", SQFS_ERROR_ALLOC); goto fail_tree; } - if (sqfs_data_reader_load_fragment_table(state->data, &state->super)) + ret = sqfs_data_reader_load_fragment_table(state->data, &state->super); + if (ret) { + sqfs_perror(path, "loading fragment table", ret); goto fail_data; + } return 0; fail_data: diff --git a/difftool/sqfsdiff.h b/difftool/sqfsdiff.h index e274353..2b3f2bd 100644 --- a/difftool/sqfsdiff.h +++ b/difftool/sqfsdiff.h @@ -9,6 +9,7 @@ #include "config.h" +#include "sqfs/error.h" #include "highlevel.h" #include "fstree.h" #include "util.h" diff --git a/include/highlevel.h b/include/highlevel.h index 068ae01..be2302b 100644 --- a/include/highlevel.h +++ b/include/highlevel.h @@ -112,7 +112,7 @@ int inode_stat(const sqfs_tree_node_t *node, struct stat *sb); char *sqfs_tree_node_get_path(const sqfs_tree_node_t *node); -int sqfs_data_reader_dump(sqfs_data_reader_t *data, +int sqfs_data_reader_dump(const char *name, sqfs_data_reader_t *data, const sqfs_inode_generic_t *inode, int outfd, size_t block_size, bool allow_sparse); diff --git a/lib/sqfshelper/data_reader_dump.c b/lib/sqfshelper/data_reader_dump.c index 160f7f0..1a4ca65 100644 --- a/lib/sqfshelper/data_reader_dump.c +++ b/lib/sqfshelper/data_reader_dump.c @@ -16,7 +16,7 @@ #include <string.h> #include <stdio.h> -int sqfs_data_reader_dump(sqfs_data_reader_t *data, +int sqfs_data_reader_dump(const char *name, sqfs_data_reader_t *data, const sqfs_inode_generic_t *inode, int outfd, size_t block_size, bool allow_sparse) { @@ -46,8 +46,7 @@ int sqfs_data_reader_dump(sqfs_data_reader_t *data, } else { err = sqfs_data_reader_get_block(data, inode, i, &blk); if (err) { - fprintf(stderr, "error reading " - "data block: %d\n", err); + sqfs_perror(name, "reading data block", err); return -1; } @@ -63,8 +62,9 @@ int sqfs_data_reader_dump(sqfs_data_reader_t *data, } if (filesz > 0) { - if (sqfs_data_reader_get_fragment(data, inode, &blk)) { - fputs("error reading fragment block", stderr); + err = sqfs_data_reader_get_fragment(data, inode, &blk); + if (err) { + sqfs_perror(name, "reading fragment block", err); return -1; } diff --git a/tar/sqfs2tar.c b/tar/sqfs2tar.c index cfc3b7f..7b306f9 100644 --- a/tar/sqfs2tar.c +++ b/tar/sqfs2tar.c @@ -10,6 +10,7 @@ #include "sqfs/compressor.h" #include "sqfs/data_reader.h" #include "sqfs/xattr_reader.h" +#include "sqfs/error.h" #include "highlevel.h" #include "util.h" #include "tar.h" @@ -184,7 +185,8 @@ static int terminate_archive(void) buffer, sizeof(buffer)); } -static int get_xattrs(const sqfs_inode_generic_t *inode, tar_xattr_t **out) +static int get_xattrs(const char *name, const sqfs_inode_generic_t *inode, + tar_xattr_t **out) { tar_xattr_t *list = NULL, *ent; sqfs_xattr_value_t *value; @@ -192,6 +194,7 @@ static int get_xattrs(const sqfs_inode_generic_t *inode, tar_xattr_t **out) sqfs_xattr_id_t desc; sqfs_u32 index; size_t i; + int ret; if (xr == NULL) return 0; @@ -201,24 +204,28 @@ static int get_xattrs(const sqfs_inode_generic_t *inode, tar_xattr_t **out) if (index == 0xFFFFFFFF) return 0; - if (sqfs_xattr_reader_get_desc(xr, index, &desc)) { - fputs("Error resolving xattr index\n", stderr); + ret = sqfs_xattr_reader_get_desc(xr, index, &desc); + if (ret) { + sqfs_perror(name, "resolving xattr index", ret); return -1; } - if (sqfs_xattr_reader_seek_kv(xr, &desc)) { - fputs("Error locating xattr key-value pairs\n", stderr); + ret = sqfs_xattr_reader_seek_kv(xr, &desc); + if (ret) { + sqfs_perror(name, "locating xattr key-value pairs", ret); return -1; } for (i = 0; i < desc.count; ++i) { - if (sqfs_xattr_reader_read_key(xr, &key)) { - fputs("Error reading xattr key\n", stderr); + ret = sqfs_xattr_reader_read_key(xr, &key); + if (ret) { + sqfs_perror(name, "reading xattr key", ret); goto fail; } - if (sqfs_xattr_reader_read_value(xr, key, &value)) { - fputs("Error reading xattr value\n", stderr); + ret = sqfs_xattr_reader_read_value(xr, key, &value); + if (ret) { + sqfs_perror(name, "reading xattr value", ret); free(key); goto fail; } @@ -278,7 +285,7 @@ static int write_tree_dfs(const sqfs_tree_node_t *n) inode_stat(n, &sb); if (!no_xattr) { - if (get_xattrs(n->inode, &xattr)) { + if (get_xattrs(name, n->inode, &xattr)) { free(name); return -1; } @@ -297,18 +304,25 @@ static int write_tree_dfs(const sqfs_tree_node_t *n) if (ret > 0) goto out_skip; - free(name); - if (ret < 0) + if (ret < 0) { + free(name); return -1; + } if (S_ISREG(sb.st_mode)) { - if (sqfs_data_reader_dump(data, n->inode, STDOUT_FILENO, - super.block_size, false)) + if (sqfs_data_reader_dump(name, data, n->inode, STDOUT_FILENO, + super.block_size, false)) { + free(name); return -1; + } - if (padd_file(STDOUT_FILENO, sb.st_size, 512)) + if (padd_file(STDOUT_FILENO, sb.st_size, 512)) { + free(name); return -1; + } } + + free(name); skip_hdr: for (n = n->children; n != NULL; n = n->next) { if (write_tree_dfs(n)) @@ -384,8 +398,9 @@ int main(int argc, char **argv) goto out_dirs; } - if (sqfs_super_read(&super, file)) { - fprintf(stderr, "%s: error reading super block.\n", filename); + ret = sqfs_super_read(&super, file); + if (ret) { + sqfs_perror(filename, "reading super block", ret); goto out_fd; } @@ -399,12 +414,18 @@ int main(int argc, char **argv) SQFS_COMP_FLAG_UNCOMPRESS); cmp = sqfs_compressor_create(&cfg); - if (cmp == NULL) + if (cmp == NULL) { + fputs("Error creating compressor.\n", stderr); goto out_fd; + } if (super.flags & SQFS_FLAG_COMPRESSOR_OPTIONS) { - if (cmp->read_options(cmp, file)) + ret = cmp->read_options(cmp, file); + if (ret) { + sqfs_perror(filename, "reading compressor options", + ret); goto out_cmp; + } } idtbl = sqfs_id_table_create(); @@ -414,32 +435,43 @@ int main(int argc, char **argv) goto out_cmp; } - if (sqfs_id_table_read(idtbl, file, &super, cmp)) { - fputs("error loading ID table\n", stderr); + ret = sqfs_id_table_read(idtbl, file, &super, cmp); + if (ret) { + sqfs_perror(filename, "loading ID table", ret); goto out_id; } data = sqfs_data_reader_create(file, super.block_size, cmp); - if (data == NULL) + if (data == NULL) { + sqfs_perror(filename, "creating data reader", + SQFS_ERROR_ALLOC); goto out_id; + } - if (sqfs_data_reader_load_fragment_table(data, &super)) + ret = sqfs_data_reader_load_fragment_table(data, &super); + if (ret) { + sqfs_perror(filename, "loading fragment table", ret); goto out_data; + } dr = sqfs_dir_reader_create(&super, cmp, file); if (dr == NULL) { - perror("creating dir reader"); + sqfs_perror(filename, "creating dir reader", + SQFS_ERROR_ALLOC); goto out_data; } if (!no_xattr && !(super.flags & SQFS_FLAG_NO_XATTRS)) { xr = sqfs_xattr_reader_create(file, &super, cmp); if (xr == NULL) { + sqfs_perror(filename, "creating xattr reader", + SQFS_ERROR_ALLOC); goto out_dr; } - if (sqfs_xattr_reader_load_locations(xr)) { - fputs("error loading xattr table\n", stderr); + ret = sqfs_xattr_reader_load_locations(xr); + if (ret) { + sqfs_perror(filename, "loading xattr table", ret); goto out_xr; } } @@ -448,7 +480,7 @@ int main(int argc, char **argv) ret = sqfs_dir_reader_get_full_hierarchy(dr, idtbl, NULL, 0, &root); if (ret) { - fputs("error loading file system tree", stderr); + sqfs_perror(filename, "loading filesystem tree", ret); goto out; } } else { @@ -463,8 +495,8 @@ int main(int argc, char **argv) flags, &subtree); if (ret) { - fprintf(stderr, "error loading '%s'\n", - subdirs[i]); + sqfs_perror(subdirs[i], "loading filesystem " + "tree", ret); goto out; } diff --git a/unpack/fill_files.c b/unpack/fill_files.c index 12b39fb..481c398 100644 --- a/unpack/fill_files.c +++ b/unpack/fill_files.c @@ -143,7 +143,8 @@ static int fill_files(sqfs_data_reader_t *data, int flags) if (!(flags & UNPACK_QUIET)) printf("unpacking %s\n", files[i].path); - if (sqfs_data_reader_dump(data, files[i].inode, fd, block_size, + if (sqfs_data_reader_dump(files[i].path, data, files[i].inode, + fd, block_size, (flags & UNPACK_NO_SPARSE) == 0)) { close(fd); return -1; diff --git a/unpack/rdsquashfs.c b/unpack/rdsquashfs.c index 7bb1ab4..5ef367b 100644 --- a/unpack/rdsquashfs.c +++ b/unpack/rdsquashfs.c @@ -29,9 +29,9 @@ int main(int argc, char **argv) goto out_cmd; } - if (sqfs_super_read(&super, file)) { - fprintf(stderr, "%s: error reading super block.\n", - opt.image_name); + ret = sqfs_super_read(&super, file); + if (ret) { + sqfs_perror(opt.image_name, "reading super block", ret); goto out_file; } @@ -46,51 +46,73 @@ int main(int argc, char **argv) SQFS_COMP_FLAG_UNCOMPRESS); cmp = sqfs_compressor_create(&cfg); - if (cmp == NULL) + if (cmp == NULL) { + fputs("Error creating compressor.\n", stderr); goto out_file; + } if (super.flags & SQFS_FLAG_COMPRESSOR_OPTIONS) { - if (cmp->read_options(cmp, file)) + ret = cmp->read_options(cmp, file); + if (ret) { + sqfs_perror(opt.image_name, "reading compressor " + "options", ret); goto out_cmp; + } } if (!(super.flags & SQFS_FLAG_NO_XATTRS)) { xattr = sqfs_xattr_reader_create(file, &super, cmp); + if (xattr == NULL) { + sqfs_perror(opt.image_name, "creating xattr reader", + SQFS_ERROR_ALLOC); + goto out_cmp; + } - if (sqfs_xattr_reader_load_locations(xattr)) { - fputs("Error loading xattr table\n", stderr); + ret = sqfs_xattr_reader_load_locations(xattr); + if (ret) { + sqfs_perror(opt.image_name, "loading xattr table", + ret); goto out_xr; } } idtbl = sqfs_id_table_create(); if (idtbl == NULL) { - perror("creating ID table"); + sqfs_perror(opt.image_name, "creating ID table", + SQFS_ERROR_ALLOC); goto out_xr; } - if (sqfs_id_table_read(idtbl, file, &super, cmp)) { - fputs("error loading ID table\n", stderr); + ret = sqfs_id_table_read(idtbl, file, &super, cmp); + if (ret) { + sqfs_perror(opt.image_name, "loading ID table", ret); goto out_id; } dirrd = sqfs_dir_reader_create(&super, cmp, file); if (dirrd == NULL) { - perror("creating dir reader"); + sqfs_perror(opt.image_name, "creating dir reader", + SQFS_ERROR_ALLOC); goto out_id; } data = sqfs_data_reader_create(file, super.block_size, cmp); - if (data == NULL) + if (data == NULL) { + sqfs_perror(opt.image_name, "creating data reader", + SQFS_ERROR_ALLOC); goto out_dr; + } - if (sqfs_data_reader_load_fragment_table(data, &super)) + ret = sqfs_data_reader_load_fragment_table(data, &super); + if (ret) { + sqfs_perror(opt.image_name, "loading fragment table", ret); goto out_data; + } ret = sqfs_dir_reader_get_full_hierarchy(dirrd, idtbl, opt.cmdpath, opt.rdtree_flags, &n); if (ret) { - fprintf(stderr, "error reading hierarchy: %d\n", ret); + sqfs_perror(opt.image_name, "reading filesystem tree", ret); goto out_data; } @@ -105,9 +127,11 @@ int main(int argc, char **argv) goto out; } - if (sqfs_data_reader_dump(data, n->inode, STDOUT_FILENO, - super.block_size, false)) + if (sqfs_data_reader_dump(opt.cmdpath, data, n->inode, + STDOUT_FILENO, + super.block_size, false)) { goto out; + } break; case OP_UNPACK: if (opt.unpack_root != NULL) { diff --git a/unpack/rdsquashfs.h b/unpack/rdsquashfs.h index 5de89be..572a48b 100644 --- a/unpack/rdsquashfs.h +++ b/unpack/rdsquashfs.h @@ -16,6 +16,7 @@ #include "sqfs/id_table.h" #include "sqfs/xattr.h" #include "sqfs/block.h" +#include "sqfs/error.h" #include "highlevel.h" #include "fstree.h" |