summaryrefslogtreecommitdiff
path: root/unpack
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-06-11 17:56:09 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-06-11 18:04:04 +0200
commitcfbbe12db970b266186775350267f163967d2ede (patch)
tree4a315590c0f83f475c8fb1270a8180fbed9a6ff1 /unpack
parent578fc9124db4c50ca8c5fac865296139be8c8dfd (diff)
cleanup: get rid of unsqfs_info_t
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'unpack')
-rw-r--r--unpack/rdsquashfs.c63
-rw-r--r--unpack/rdsquashfs.h10
-rw-r--r--unpack/restore_fstree.c19
3 files changed, 41 insertions, 51 deletions
diff --git a/unpack/rdsquashfs.c b/unpack/rdsquashfs.c
index 7fd2947..a24d6c3 100644
--- a/unpack/rdsquashfs.c
+++ b/unpack/rdsquashfs.c
@@ -125,13 +125,14 @@ int main(int argc, char **argv)
{
int i, status = EXIT_FAILURE, op = OP_NONE;
const char *unpack_root = NULL;
+ int rdtree_flags = 0, flags = 0;
+ data_reader_t *data = NULL;
char *cmdpath = NULL;
- unsqfs_info_t info;
sqfs_super_t super;
+ compressor_t *cmp;
tree_node_t *n;
fstree_t fs;
-
- memset(&info, 0, sizeof(info));
+ int sqfsfd;
for (;;) {
i = getopt_long(argc, argv, short_opts, long_opts, NULL);
@@ -140,25 +141,25 @@ int main(int argc, char **argv)
switch (i) {
case 'D':
- info.rdtree_flags |= RDTREE_NO_DEVICES;
+ rdtree_flags |= RDTREE_NO_DEVICES;
break;
case 'S':
- info.rdtree_flags |= RDTREE_NO_SOCKETS;
+ rdtree_flags |= RDTREE_NO_SOCKETS;
break;
case 'F':
- info.rdtree_flags |= RDTREE_NO_FIFO;
+ rdtree_flags |= RDTREE_NO_FIFO;
break;
case 'L':
- info.rdtree_flags |= RDTREE_NO_SLINKS;
+ rdtree_flags |= RDTREE_NO_SLINKS;
break;
case 'C':
- info.flags |= UNPACK_CHMOD;
+ flags |= UNPACK_CHMOD;
break;
case 'O':
- info.flags |= UNPACK_CHOWN;
+ flags |= UNPACK_CHOWN;
break;
case 'E':
- info.rdtree_flags |= RDTREE_NO_EMPTY;
+ rdtree_flags |= RDTREE_NO_EMPTY;
break;
case 'c':
op = OP_CAT;
@@ -179,7 +180,7 @@ int main(int argc, char **argv)
cmdpath = get_path(cmdpath, optarg);
break;
case 'q':
- info.flags |= UNPACK_QUIET;
+ flags |= UNPACK_QUIET;
break;
case 'h':
printf(help_string, __progname);
@@ -204,13 +205,13 @@ int main(int argc, char **argv)
goto fail_arg;
}
- info.sqfsfd = open(argv[optind], O_RDONLY);
- if (info.sqfsfd < 0) {
+ sqfsfd = open(argv[optind], O_RDONLY);
+ if (sqfsfd < 0) {
perror(argv[optind]);
goto out_cmd;
}
- if (sqfs_super_read(&super, info.sqfsfd))
+ if (sqfs_super_read(&super, sqfsfd))
goto out_fd;
if ((super.version_major != SQFS_VERSION_MAJOR) ||
@@ -229,20 +230,18 @@ int main(int argc, char **argv)
goto out_fd;
}
- info.cmp = compressor_create(super.compression_id, false,
- super.block_size, NULL);
- if (info.cmp == NULL)
+ 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 (info.cmp->read_options(info.cmp, info.sqfsfd))
+ if (cmp->read_options(cmp, sqfsfd))
goto out_cmp;
}
- if (deserialize_fstree(&fs, &super, info.cmp,
- info.sqfsfd, info.rdtree_flags)) {
+ if (deserialize_fstree(&fs, &super, cmp, sqfsfd, rdtree_flags))
goto out_cmp;
- }
switch (op) {
case OP_LS:
@@ -266,14 +265,12 @@ int main(int argc, char **argv)
goto out_fs;
}
- info.data = data_reader_create(info.sqfsfd, &super, info.cmp);
- if (info.data == NULL)
+ data = data_reader_create(sqfsfd, &super, cmp);
+ if (data == NULL)
goto out_fs;
- if (data_reader_dump_file(info.data, n->data.file,
- STDOUT_FILENO)) {
+ if (data_reader_dump_file(data, n->data.file, STDOUT_FILENO))
goto out_fs;
- }
break;
case OP_UNPACK:
n = find_node(fs.root, cmdpath);
@@ -282,11 +279,11 @@ int main(int argc, char **argv)
goto out_fs;
}
- info.data = data_reader_create(info.sqfsfd, &super, info.cmp);
- if (info.data == NULL)
+ data = data_reader_create(sqfsfd, &super, cmp);
+ if (data == NULL)
goto out_fs;
- if (restore_fstree(unpack_root, n, &info))
+ if (restore_fstree(unpack_root, n, data, flags))
goto out_fs;
break;
case OP_DESCRIBE:
@@ -296,13 +293,13 @@ int main(int argc, char **argv)
status = EXIT_SUCCESS;
out_fs:
- if (info.data != NULL)
- data_reader_destroy(info.data);
+ if (data != NULL)
+ data_reader_destroy(data);
fstree_cleanup(&fs);
out_cmp:
- info.cmp->destroy(info.cmp);
+ cmp->destroy(cmp);
out_fd:
- close(info.sqfsfd);
+ close(sqfsfd);
out_cmd:
free(cmdpath);
return status;
diff --git a/unpack/rdsquashfs.h b/unpack/rdsquashfs.h
index b927bab..959960a 100644
--- a/unpack/rdsquashfs.h
+++ b/unpack/rdsquashfs.h
@@ -26,18 +26,10 @@ enum UNPACK_FLAGS {
UNPACK_QUIET = 0x04,
};
-typedef struct {
- data_reader_t *data;
- compressor_t *cmp;
- int rdtree_flags;
- int sqfsfd;
- int flags;
-} unsqfs_info_t;
-
void list_files(tree_node_t *node);
int restore_fstree(const char *rootdir, tree_node_t *root,
- unsqfs_info_t *info);
+ data_reader_t *data, int flags);
void describe_tree(tree_node_t *root, const char *unpack_root);
diff --git a/unpack/restore_fstree.c b/unpack/restore_fstree.c
index a39ec97..976b15c 100644
--- a/unpack/restore_fstree.c
+++ b/unpack/restore_fstree.c
@@ -1,12 +1,12 @@
/* SPDX-License-Identifier: GPL-3.0-or-later */
#include "rdsquashfs.h"
-static int create_node(tree_node_t *n, unsqfs_info_t *info)
+static int create_node(tree_node_t *n, data_reader_t *data, int flags)
{
char *name;
int fd;
- if (!(info->flags & UNPACK_QUIET)) {
+ if (!(flags & UNPACK_QUIET)) {
name = fstree_get_path(n);
printf("unpacking %s\n", name);
free(name);
@@ -24,7 +24,7 @@ static int create_node(tree_node_t *n, unsqfs_info_t *info)
return -1;
for (n = n->data.dir->children; n != NULL; n = n->next) {
- if (create_node(n, info))
+ if (create_node(n, data, flags))
return -1;
}
@@ -63,7 +63,7 @@ static int create_node(tree_node_t *n, unsqfs_info_t *info)
return -1;
}
- if (data_reader_dump_file(info->data, n->data.file, fd)) {
+ if (data_reader_dump_file(data, n->data.file, fd)) {
close(fd);
return -1;
}
@@ -74,7 +74,7 @@ static int create_node(tree_node_t *n, unsqfs_info_t *info)
break;
}
- if (info->flags & UNPACK_CHOWN) {
+ if (flags & UNPACK_CHOWN) {
if (fchownat(AT_FDCWD, n->name, n->uid, n->gid,
AT_SYMLINK_NOFOLLOW)) {
fprintf(stderr, "chown %s: %s\n",
@@ -83,7 +83,7 @@ static int create_node(tree_node_t *n, unsqfs_info_t *info)
}
}
- if (info->flags & UNPACK_CHMOD) {
+ if (flags & UNPACK_CHMOD) {
if (fchmodat(AT_FDCWD, n->name, n->mode,
AT_SYMLINK_NOFOLLOW)) {
fprintf(stderr, "chmod %s: %s\n",
@@ -94,7 +94,8 @@ static int create_node(tree_node_t *n, unsqfs_info_t *info)
return 0;
}
-int restore_fstree(const char *rootdir, tree_node_t *root, unsqfs_info_t *info)
+int restore_fstree(const char *rootdir, tree_node_t *root,
+ data_reader_t *data, int flags)
{
tree_node_t *n;
@@ -108,11 +109,11 @@ int restore_fstree(const char *rootdir, tree_node_t *root, unsqfs_info_t *info)
if (S_ISDIR(root->mode)) {
for (n = root->data.dir->children; n != NULL; n = n->next) {
- if (create_node(n, info))
+ if (create_node(n, data, flags))
return -1;
}
} else {
- if (create_node(root, info))
+ if (create_node(root, data, flags))
return -1;
}