summaryrefslogtreecommitdiff
path: root/unpack/rdsquashfs.c
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-09-17 13:21:05 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-09-20 03:18:47 +0200
commit544f8f6dfd2f61fd1d2ab7a9a955e63d4b416dcc (patch)
treee0d560ef70e719079735f10684dfe3a46d6ddf04 /unpack/rdsquashfs.c
parentd6d70a7315d5a39130928e031e3e72e7f790ac83 (diff)
Remove sqfs reader from rdsquashfs
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'unpack/rdsquashfs.c')
-rw-r--r--unpack/rdsquashfs.c88
1 files changed, 69 insertions, 19 deletions
diff --git a/unpack/rdsquashfs.c b/unpack/rdsquashfs.c
index 4fb3a78..e0cfaba 100644
--- a/unpack/rdsquashfs.c
+++ b/unpack/rdsquashfs.c
@@ -23,24 +23,69 @@ static void dump_xattrs(fstree_t *fs, tree_xattr_t *xattr)
int main(int argc, char **argv)
{
+ sqfs_compressor_config_t cfg;
int status = EXIT_FAILURE;
- sqfs_reader_t sqfs;
+ sqfs_compressor_t *cmp;
+ data_reader_t *data;
+ sqfs_super_t super;
+ sqfs_file_t *file;
tree_node_t *n;
options_t opt;
+ fstree_t fs;
process_command_line(&opt, argc, argv);
- if (sqfs_reader_open(&sqfs, opt.image_name, opt.rdtree_flags))
+ file = sqfs_open_file(opt.image_name, SQFS_FILE_OPEN_READ_ONLY);
+ if (file == NULL) {
+ perror(opt.image_name);
goto out_cmd;
+ }
+
+ if (sqfs_super_read(&super, file)) {
+ fprintf(stderr, "%s: error reading super block.\n",
+ opt.image_name);
+ goto out_file;
+ }
+
+ if (!sqfs_compressor_exists(super.compression_id)) {
+ fprintf(stderr, "%s: unknown compressor used.\n",
+ opt.image_name);
+ goto out_file;
+ }
+
+ sqfs_compressor_config_init(&cfg, super.compression_id,
+ super.block_size,
+ SQFS_COMP_FLAG_UNCOMPRESS);
+
+ cmp = sqfs_compressor_create(&cfg);
+ if (cmp == NULL)
+ goto out_file;
+
+ if (super.flags & SQFS_FLAG_COMPRESSOR_OPTIONS) {
+ if (cmp->read_options(cmp, file))
+ goto out_cmp;
+ }
+
+ if (super.flags & SQFS_FLAG_NO_XATTRS)
+ opt.rdtree_flags &= ~RDTREE_READ_XATTR;
+
+ if (deserialize_fstree(&fs, &super, cmp, file, opt.rdtree_flags))
+ goto out_cmp;
+
+ fstree_gen_file_list(&fs);
+
+ data = data_reader_create(file, &super, cmp);
+ if (data == NULL)
+ goto out_fs;
if (opt.cmdpath != NULL) {
- n = fstree_node_from_path(&sqfs.fs, opt.cmdpath);
+ n = fstree_node_from_path(&fs, opt.cmdpath);
if (n == NULL) {
perror(opt.cmdpath);
- goto out_fs;
+ goto out;
}
} else {
- n = sqfs.fs.root;
+ n = fs.root;
}
switch (opt.op) {
@@ -51,12 +96,12 @@ int main(int argc, char **argv)
if (!S_ISREG(n->mode)) {
fprintf(stderr, "/%s: not a regular file\n",
opt.cmdpath);
- goto out_fs;
+ goto out;
}
- if (data_reader_dump_file(sqfs.data, n->data.file,
+ if (data_reader_dump_file(data, n->data.file,
STDOUT_FILENO, false))
- goto out_fs;
+ goto out;
break;
case OP_UNPACK:
if (opt.unpack_root != NULL) {
@@ -68,31 +113,36 @@ int main(int argc, char **argv)
}
if (restore_fstree(n, opt.flags))
- goto out_fs;
+ goto out;
- if (fill_unpacked_files(&sqfs.fs, sqfs.data,
- opt.flags, opt.num_jobs))
- goto out_fs;
+ if (fill_unpacked_files(&fs, data, opt.flags, opt.num_jobs))
+ goto out;
- if (update_tree_attribs(&sqfs.fs, n, opt.flags))
- goto out_fs;
+ if (update_tree_attribs(&fs, n, opt.flags))
+ goto out;
if (opt.unpack_root != NULL && popd() != 0)
- goto out_fs;
+ goto out;
break;
case OP_DESCRIBE:
- if (describe_tree(sqfs.fs.root, opt.unpack_root))
- goto out_fs;
+ if (describe_tree(fs.root, opt.unpack_root))
+ goto out;
break;
case OP_RDATTR:
if (n->xattr != NULL)
- dump_xattrs(&sqfs.fs, n->xattr);
+ dump_xattrs(&fs, n->xattr);
break;
}
status = EXIT_SUCCESS;
+out:
+ data_reader_destroy(data);
out_fs:
- sqfs_reader_close(&sqfs);
+ fstree_cleanup(&fs);
+out_cmp:
+ cmp->destroy(cmp);
+out_file:
+ file->destroy(file);
out_cmd:
free(opt.cmdpath);
return status;