diff options
| author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2019-08-05 17:38:08 +0200 | 
|---|---|---|
| committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2019-08-05 17:45:59 +0200 | 
| commit | 88f75857702bcc6a2a423570912140c125ec518a (patch) | |
| tree | a1ec54e2520e076395208872d36606f917c8ca34 /unpack | |
| parent | 3a340b12eb9b7ed86a47391345cb836fa662b2d9 (diff) | |
cleanup: unify all the code that reads squashfs images
This commit creates a new data structure called 'sqfs_reader_t' that
takes care of all the repetetive tasks like opening the file, reading
the super block, creating the compressor, deserializing an fstree and
creating a data reader.
This in turn makes it possible to remove all the duplicate code from
rdsquashfs and sqfs2tar.
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'unpack')
| -rw-r--r-- | unpack/rdsquashfs.c | 66 | 
1 files changed, 11 insertions, 55 deletions
| diff --git a/unpack/rdsquashfs.c b/unpack/rdsquashfs.c index dc43fcd..4fb3a78 100644 --- a/unpack/rdsquashfs.c +++ b/unpack/rdsquashfs.c @@ -24,54 +24,23 @@ static void dump_xattrs(fstree_t *fs, tree_xattr_t *xattr)  int main(int argc, char **argv)  {  	int status = EXIT_FAILURE; -	data_reader_t *data = NULL; -	sqfs_super_t super; -	compressor_t *cmp; +	sqfs_reader_t sqfs;  	tree_node_t *n;  	options_t opt; -	fstree_t fs; -	int sqfsfd;  	process_command_line(&opt, argc, argv); -	sqfsfd = open(opt.image_name, O_RDONLY); -	if (sqfsfd < 0) { -		perror(opt.image_name); +	if (sqfs_reader_open(&sqfs, opt.image_name, opt.rdtree_flags))  		goto out_cmd; -	} - -	if (sqfs_super_read(&super, sqfsfd)) -		goto out_fd; - -	if (!compressor_exists(super.compression_id)) { -		fputs("Image uses a compressor that has not been built in\n", -		      stderr); -		goto out_fd; -	} - -	cmp = compressor_create(super.compression_id, false, -				super.block_size, NULL); -	if (cmp == NULL) -		goto out_fd; - -	if (super.flags & SQFS_FLAG_COMPRESSOR_OPTIONS) { -		if (cmp->read_options(cmp, sqfsfd)) -			goto out_cmp; -	} - -	if (deserialize_fstree(&fs, &super, cmp, sqfsfd, opt.rdtree_flags)) -		goto out_cmp; - -	fstree_gen_file_list(&fs);  	if (opt.cmdpath != NULL) { -		n = fstree_node_from_path(&fs, opt.cmdpath); +		n = fstree_node_from_path(&sqfs.fs, opt.cmdpath);  		if (n == NULL) {  			perror(opt.cmdpath);  			goto out_fs;  		}  	} else { -		n = fs.root; +		n = sqfs.fs.root;  	}  	switch (opt.op) { @@ -85,11 +54,7 @@ int main(int argc, char **argv)  			goto out_fs;  		} -		data = data_reader_create(sqfsfd, &super, cmp); -		if (data == NULL) -			goto out_fs; - -		if (data_reader_dump_file(data, n->data.file, +		if (data_reader_dump_file(sqfs.data, n->data.file,  					  STDOUT_FILENO, false))  			goto out_fs;  		break; @@ -105,38 +70,29 @@ int main(int argc, char **argv)  		if (restore_fstree(n, opt.flags))  			goto out_fs; -		data = data_reader_create(sqfsfd, &super, cmp); -		if (data == NULL) -			goto out_fs; - -		if (fill_unpacked_files(&fs, data, opt.flags, opt.num_jobs)) +		if (fill_unpacked_files(&sqfs.fs, sqfs.data, +					opt.flags, opt.num_jobs))  			goto out_fs; -		if (update_tree_attribs(&fs, n, opt.flags)) +		if (update_tree_attribs(&sqfs.fs, n, opt.flags))  			goto out_fs;  		if (opt.unpack_root != NULL && popd() != 0)  			goto out_fs;  		break;  	case OP_DESCRIBE: -		if (describe_tree(fs.root, opt.unpack_root)) +		if (describe_tree(sqfs.fs.root, opt.unpack_root))  			goto out_fs;  		break;  	case OP_RDATTR:  		if (n->xattr != NULL) -			dump_xattrs(&fs, n->xattr); +			dump_xattrs(&sqfs.fs, n->xattr);  		break;  	}  	status = EXIT_SUCCESS;  out_fs: -	if (data != NULL) -		data_reader_destroy(data); -	fstree_cleanup(&fs); -out_cmp: -	cmp->destroy(cmp); -out_fd: -	close(sqfsfd); +	sqfs_reader_close(&sqfs);  out_cmd:  	free(opt.cmdpath);  	return status; | 
