diff options
Diffstat (limited to 'bin')
-rw-r--r-- | bin/rdsquashfs/rdsquashfs.c | 54 | ||||
-rw-r--r-- | bin/sqfs2tar/sqfs2tar.c | 43 | ||||
-rw-r--r-- | bin/sqfsdiff/sqfsdiff.c | 52 |
3 files changed, 61 insertions, 88 deletions
diff --git a/bin/rdsquashfs/rdsquashfs.c b/bin/rdsquashfs/rdsquashfs.c index a18ac7f..bdcc5a0 100644 --- a/bin/rdsquashfs/rdsquashfs.c +++ b/bin/rdsquashfs/rdsquashfs.c @@ -100,15 +100,15 @@ static int tree_sort(sqfs_tree_node_t *root) int main(int argc, char **argv) { sqfs_xattr_reader_t *xattr = NULL; + sqfs_data_reader_t *data = NULL; + sqfs_dir_reader_t *dirrd = NULL; + sqfs_compressor_t *cmp = NULL; + sqfs_id_table_t *idtbl = NULL; sqfs_compressor_config_t cfg; + sqfs_tree_node_t *n = NULL; int status = EXIT_FAILURE; - sqfs_data_reader_t *data; - sqfs_dir_reader_t *dirrd; - sqfs_compressor_t *cmp; - sqfs_id_table_t *idtbl; - sqfs_tree_node_t *n; + sqfs_file_t *file = NULL; sqfs_super_t super; - sqfs_file_t *file; options_t opt; int ret; @@ -117,13 +117,13 @@ int main(int argc, char **argv) file = sqfs_open_file(opt.image_name, SQFS_FILE_OPEN_READ_ONLY); if (file == NULL) { perror(opt.image_name); - goto out_cmd; + goto out; } ret = sqfs_super_read(&super, file); if (ret) { sqfs_perror(opt.image_name, "reading super block", ret); - goto out_file; + goto out; } sqfs_compressor_config_init(&cfg, super.compression_id, @@ -139,7 +139,7 @@ int main(int argc, char **argv) if (ret != 0) { sqfs_perror(opt.image_name, "creating compressor", ret); - goto out_file; + goto out; } if (!(super.flags & SQFS_FLAG_NO_XATTRS)) { @@ -147,14 +147,14 @@ int main(int argc, char **argv) if (xattr == NULL) { sqfs_perror(opt.image_name, "creating xattr reader", SQFS_ERROR_ALLOC); - goto out_cmp; + goto out; } ret = sqfs_xattr_reader_load(xattr, &super, file, cmp); if (ret) { sqfs_perror(opt.image_name, "loading xattr table", ret); - goto out_xr; + goto out; } } @@ -162,40 +162,40 @@ int main(int argc, char **argv) if (idtbl == NULL) { sqfs_perror(opt.image_name, "creating ID table", SQFS_ERROR_ALLOC); - goto out_xr; + goto out; } ret = sqfs_id_table_read(idtbl, file, &super, cmp); if (ret) { sqfs_perror(opt.image_name, "loading ID table", ret); - goto out_id; + goto out; } dirrd = sqfs_dir_reader_create(&super, cmp, file, 0); if (dirrd == NULL) { sqfs_perror(opt.image_name, "creating dir reader", SQFS_ERROR_ALLOC); - goto out_id; + goto out; } data = sqfs_data_reader_create(file, super.block_size, cmp, 0); if (data == NULL) { sqfs_perror(opt.image_name, "creating data reader", SQFS_ERROR_ALLOC); - goto out_dr; + goto out; } ret = sqfs_data_reader_load_fragment_table(data, &super); if (ret) { sqfs_perror(opt.image_name, "loading fragment table", ret); - goto out_data; + goto out; } ret = sqfs_dir_reader_get_full_hierarchy(dirrd, idtbl, opt.cmdpath, opt.rdtree_flags, &n); if (ret) { sqfs_perror(opt.image_name, "reading filesystem tree", ret); - goto out_data; + goto out; } switch (opt.op) { @@ -219,13 +219,11 @@ int main(int argc, char **argv) if (fp == NULL) goto out; - if (sqfs_data_reader_dump(opt.cmdpath, data, n->inode, - fp, super.block_size)) { - sqfs_drop(fp); - goto out; - } - + ret = sqfs_data_reader_dump(opt.cmdpath, data, n->inode, + fp, super.block_size); sqfs_drop(fp); + if (ret) + goto out; break; } case OP_UNPACK: @@ -266,20 +264,12 @@ int main(int argc, char **argv) status = EXIT_SUCCESS; out: sqfs_dir_tree_destroy(n); -out_data: sqfs_drop(data); -out_dr: sqfs_drop(dirrd); -out_id: sqfs_drop(idtbl); -out_xr: - if (xattr != NULL) - sqfs_drop(xattr); -out_cmp: + sqfs_drop(xattr); sqfs_drop(cmp); -out_file: sqfs_drop(file); -out_cmd: free(opt.cmdpath); return status; } diff --git a/bin/sqfs2tar/sqfs2tar.c b/bin/sqfs2tar/sqfs2tar.c index 9dfa41e..f8d3173 100644 --- a/bin/sqfs2tar/sqfs2tar.c +++ b/bin/sqfs2tar/sqfs2tar.c @@ -107,12 +107,12 @@ static sqfs_tree_node_t *tree_merge(sqfs_tree_node_t *lhs, int main(int argc, char **argv) { - sqfs_tree_node_t *root = NULL, *subtree; + sqfs_tree_node_t *root = NULL, *subtree = NULL; int flags, ret, status = EXIT_FAILURE; + sqfs_compressor_t *cmp = NULL; + sqfs_id_table_t *idtbl = NULL; + sqfs_dir_reader_t *dr = NULL; sqfs_compressor_config_t cfg; - sqfs_compressor_t *cmp; - sqfs_id_table_t *idtbl; - sqfs_dir_reader_t *dr; size_t i; process_args(argc, argv); @@ -120,7 +120,7 @@ int main(int argc, char **argv) out_file = ostream_open_stdout(); if (out_file == NULL) { perror("changing stdout to binary mode"); - goto out_dirs; + goto out; } if (compressor > 0) { @@ -130,19 +130,19 @@ int main(int argc, char **argv) out_file = strm; if (out_file == NULL) - goto out_dirs; + goto out; } file = sqfs_open_file(filename, SQFS_FILE_OPEN_READ_ONLY); if (file == NULL) { perror(filename); - goto out_ostrm; + goto out; } ret = sqfs_super_read(&super, file); if (ret) { sqfs_perror(filename, "reading super block", ret); - goto out_fd; + goto out; } sqfs_compressor_config_init(&cfg, super.compression_id, @@ -158,40 +158,40 @@ int main(int argc, char **argv) if (ret != 0) { sqfs_perror(filename, "creating compressor", ret); - goto out_fd; + goto out; } idtbl = sqfs_id_table_create(0); if (idtbl == NULL) { perror("creating ID table"); - goto out_cmp; + goto out; } ret = sqfs_id_table_read(idtbl, file, &super, cmp); if (ret) { sqfs_perror(filename, "loading ID table", ret); - goto out_id; + goto out; } data = sqfs_data_reader_create(file, super.block_size, cmp, 0); if (data == NULL) { sqfs_perror(filename, "creating data reader", SQFS_ERROR_ALLOC); - goto out_id; + goto out; } ret = sqfs_data_reader_load_fragment_table(data, &super); if (ret) { sqfs_perror(filename, "loading fragment table", ret); - goto out_data; + goto out; } dr = sqfs_dir_reader_create(&super, cmp, file, 0); if (dr == NULL) { sqfs_perror(filename, "creating dir reader", SQFS_ERROR_ALLOC); - goto out_data; + goto out; } if (!no_xattr && !(super.flags & SQFS_FLAG_NO_XATTRS)) { @@ -199,13 +199,13 @@ int main(int argc, char **argv) if (xr == NULL) { sqfs_perror(filename, "creating xattr reader", SQFS_ERROR_ALLOC); - goto out_dr; + goto out; } ret = sqfs_xattr_reader_load(xr, &super, file, cmp); if (ret) { sqfs_perror(filename, "loading xattr table", ret); - goto out_xr; + goto out; } } @@ -252,23 +252,14 @@ int main(int argc, char **argv) status = EXIT_SUCCESS; out: - if (root != NULL) - sqfs_dir_tree_destroy(root); -out_xr: + sqfs_dir_tree_destroy(root); sqfs_drop(xr); -out_dr: sqfs_drop(dr); -out_data: sqfs_drop(data); -out_id: sqfs_drop(idtbl); -out_cmp: sqfs_drop(cmp); -out_fd: sqfs_drop(file); -out_ostrm: sqfs_drop(out_file); -out_dirs: for (i = 0; i < num_subdirs; ++i) free(subdirs[i]); free(subdirs); diff --git a/bin/sqfsdiff/sqfsdiff.c b/bin/sqfsdiff/sqfsdiff.c index 9d29332..d789fe1 100644 --- a/bin/sqfsdiff/sqfsdiff.c +++ b/bin/sqfsdiff/sqfsdiff.c @@ -6,10 +6,22 @@ */ #include "sqfsdiff.h" +static void close_sfqs(sqfs_state_t *state) +{ + sqfs_drop(state->data); + sqfs_dir_tree_destroy(state->root); + sqfs_drop(state->dr); + sqfs_drop(state->idtbl); + sqfs_drop(state->cmp); + sqfs_drop(state->file); +} + static int open_sfqs(sqfs_state_t *state, const char *path) { int ret; + memset(state, 0, sizeof(*state)); + state->file = sqfs_open_file(path, SQFS_FILE_OPEN_READ_ONLY); if (state->file == NULL) { perror(path); @@ -19,7 +31,7 @@ static int open_sfqs(sqfs_state_t *state, const char *path) ret = sqfs_super_read(&state->super, state->file); if (ret) { sqfs_perror(path, "reading super block", ret); - goto fail_file; + goto fail; } sqfs_compressor_config_init(&state->cfg, state->super.compression_id, @@ -35,7 +47,7 @@ static int open_sfqs(sqfs_state_t *state, const char *path) if (ret != 0) { sqfs_perror(path, "creating compressor", ret); - goto fail_file; + goto fail; } if (state->super.flags & SQFS_FLAG_COMPRESSOR_OPTIONS) { @@ -56,14 +68,14 @@ static int open_sfqs(sqfs_state_t *state, const char *path) state->idtbl = sqfs_id_table_create(0); if (state->idtbl == NULL) { sqfs_perror(path, "creating ID table", SQFS_ERROR_ALLOC); - goto fail_cmp; + goto fail; } 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; + goto fail; } state->dr = sqfs_dir_reader_create(&state->super, state->cmp, @@ -71,14 +83,14 @@ static int open_sfqs(sqfs_state_t *state, const char *path) if (state->dr == NULL) { sqfs_perror(path, "creating directory reader", SQFS_ERROR_ALLOC); - goto fail_id; + goto fail; } 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; + goto fail; } state->data = sqfs_data_reader_create(state->file, @@ -86,41 +98,21 @@ static int open_sfqs(sqfs_state_t *state, const char *path) state->cmp, 0); if (state->data == NULL) { sqfs_perror(path, "creating data reader", SQFS_ERROR_ALLOC); - goto fail_tree; + goto fail; } ret = sqfs_data_reader_load_fragment_table(state->data, &state->super); if (ret) { sqfs_perror(path, "loading fragment table", ret); - goto fail_data; + goto fail; } return 0; -fail_data: - sqfs_drop(state->data); -fail_tree: - sqfs_dir_tree_destroy(state->root); -fail_dr: - sqfs_drop(state->dr); -fail_id: - sqfs_drop(state->idtbl); -fail_cmp: - sqfs_drop(state->cmp); -fail_file: - sqfs_drop(state->file); +fail: + close_sfqs(state); return -1; } -static void close_sfqs(sqfs_state_t *state) -{ - sqfs_drop(state->data); - sqfs_dir_tree_destroy(state->root); - sqfs_drop(state->dr); - sqfs_drop(state->idtbl); - sqfs_drop(state->cmp); - sqfs_drop(state->file); -} - int main(int argc, char **argv) { int status, ret = 0; |