summaryrefslogtreecommitdiff
path: root/mkfs
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-06-11 12:56:22 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-06-11 13:00:25 +0200
commit99b153177dbac8689b2e58fc29530727fa7e00fc (patch)
treef6e7c0fd060c51c7e25fe76138ceb5abfbe002a2 /mkfs
parent223dcc487cb0115d3ccb0dd6464d20346253a43e (diff)
cleanup: remove rest of sqfs_info_t
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'mkfs')
-rw-r--r--mkfs/block.c14
-rw-r--r--mkfs/mkfs.c93
-rw-r--r--mkfs/mkfs.h13
-rw-r--r--mkfs/options.c4
4 files changed, 57 insertions, 67 deletions
diff --git a/mkfs/block.c b/mkfs/block.c
index 89bb689..73d43e8 100644
--- a/mkfs/block.c
+++ b/mkfs/block.c
@@ -52,33 +52,33 @@ static int find_and_process_files(data_writer_t *data, tree_node_t *n,
return 0;
}
-int write_data_to_image(data_writer_t *data, sqfs_info_t *info)
+int write_data_to_image(data_writer_t *data, fstree_t *fs, options_t *opt)
{
bool need_restore = false;
const char *ptr;
int ret;
- if (info->opt.packdir != NULL) {
- if (pushd(info->opt.packdir))
+ if (opt->packdir != NULL) {
+ if (pushd(opt->packdir))
return -1;
need_restore = true;
} else {
- ptr = strrchr(info->opt.infile, '/');
+ ptr = strrchr(opt->infile, '/');
if (ptr != NULL) {
- if (pushdn(info->opt.infile, ptr - info->opt.infile))
+ if (pushdn(opt->infile, ptr - opt->infile))
return -1;
need_restore = true;
}
}
- ret = find_and_process_files(data, info->fs.root, info->opt.quiet);
+ ret = find_and_process_files(data, fs->root, opt->quiet);
ret = ret == 0 ? data_writer_flush_fragments(data) : ret;
if (need_restore)
- ret = popd();
+ ret = ret == 0 ? popd() : ret;
return ret;
}
diff --git a/mkfs/mkfs.c b/mkfs/mkfs.c
index 50e2ce5..86172e3 100644
--- a/mkfs/mkfs.c
+++ b/mkfs/mkfs.c
@@ -2,16 +2,16 @@
#include "mkfs.h"
#include "util.h"
-static int padd_file(sqfs_info_t *info)
+static int padd_file(int outfd, sqfs_super_t *super, options_t *opt)
{
- size_t padd_sz = info->super.bytes_used % info->opt.devblksz;
+ size_t padd_sz = super->bytes_used % opt->devblksz;
uint8_t *buffer;
ssize_t ret;
if (padd_sz == 0)
return 0;
- padd_sz = info->opt.devblksz - padd_sz;
+ padd_sz = opt->devblksz - padd_sz;
buffer = calloc(1, padd_sz);
if (buffer == NULL) {
@@ -19,7 +19,7 @@ static int padd_file(sqfs_info_t *info)
return -1;
}
- ret = write_retry(info->outfd, buffer, padd_sz);
+ ret = write_retry(outfd, buffer, padd_sz);
if (ret < 0) {
perror("Error padding squashfs image to page size");
@@ -41,113 +41,110 @@ int main(int argc, char **argv)
{
int status = EXIT_FAILURE, ret;
data_writer_t *data;
- sqfs_info_t info;
+ sqfs_super_t super;
+ compressor_t *cmp;
+ id_table_t idtbl;
+ options_t opt;
+ fstree_t fs;
+ int outfd;
- memset(&info, 0, sizeof(info));
+ process_command_line(&opt, argc, argv);
- process_command_line(&info.opt, argc, argv);
-
- if (sqfs_super_init(&info.super, info.opt.blksz, info.opt.def_mtime,
- info.opt.compressor)) {
+ if (sqfs_super_init(&super, opt.blksz, opt.def_mtime, opt.compressor))
return EXIT_FAILURE;
- }
- if (id_table_init(&info.idtbl))
+ if (id_table_init(&idtbl))
return EXIT_FAILURE;
- info.outfd = open(info.opt.outfile, info.opt.outmode, 0644);
- if (info.outfd < 0) {
- perror(info.opt.outfile);
+ outfd = open(opt.outfile, opt.outmode, 0644);
+ if (outfd < 0) {
+ perror(opt.outfile);
goto out_idtbl;
}
- if (sqfs_super_write(&info.super, info.outfd))
+ if (sqfs_super_write(&super, outfd))
goto out_outfd;
- if (fstree_init(&info.fs, info.opt.blksz, info.opt.def_mtime,
- info.opt.def_mode, info.opt.def_uid,
- info.opt.def_gid)) {
+ if (fstree_init(&fs, opt.blksz, opt.def_mtime, opt.def_mode,
+ opt.def_uid, opt.def_gid)) {
goto out_outfd;
}
- if (info.opt.infile != NULL) {
- if (fstree_from_file(&info.fs, info.opt.infile, info.opt.packdir))
+ if (opt.infile != NULL) {
+ if (fstree_from_file(&fs, opt.infile, opt.packdir))
goto out_fstree;
} else {
- if (fstree_from_dir(&info.fs, info.opt.packdir))
+ if (fstree_from_dir(&fs, opt.packdir))
goto out_fstree;
}
#ifdef WITH_SELINUX
- if (info.opt.selinux != NULL) {
- if (fstree_relabel_selinux(&info.fs, info.opt.selinux))
+ if (opt.selinux != NULL) {
+ if (fstree_relabel_selinux(&fs, opt.selinux))
goto out_fstree;
}
#endif
- fstree_xattr_deduplicate(&info.fs);
+ fstree_xattr_deduplicate(&fs);
- fstree_sort(&info.fs);
+ fstree_sort(&fs);
- if (fstree_gen_inode_table(&info.fs))
+ if (fstree_gen_inode_table(&fs))
goto out_fstree;
- info.super.inode_count = info.fs.inode_tbl_size - 2;
+ super.inode_count = fs.inode_tbl_size - 2;
- info.cmp = compressor_create(info.super.compression_id, true,
- info.super.block_size,
- info.opt.comp_extra);
- if (info.cmp == NULL) {
+ cmp = compressor_create(super.compression_id, true, super.block_size,
+ opt.comp_extra);
+ if (cmp == NULL) {
fputs("Error creating compressor\n", stderr);
goto out_outfd;
}
- ret = info.cmp->write_options(info.cmp, info.outfd);
+ ret = cmp->write_options(cmp, outfd);
if (ret < 0)
goto out_cmp;
if (ret > 0) {
- info.super.flags |= SQFS_FLAG_COMPRESSOR_OPTIONS;
- info.super.bytes_used += ret;
+ super.flags |= SQFS_FLAG_COMPRESSOR_OPTIONS;
+ super.bytes_used += ret;
}
- data = data_writer_create(&info.super, info.cmp, info.outfd);
+ data = data_writer_create(&super, cmp, outfd);
if (data == NULL)
goto out_cmp;
- if (write_data_to_image(data, &info))
+ if (write_data_to_image(data, &fs, &opt))
goto out_data;
- if (sqfs_serialize_fstree(info.outfd, &info.super, &info.fs,
- info.cmp, &info.idtbl)) {
+ if (sqfs_serialize_fstree(outfd, &super, &fs, cmp, &idtbl))
goto out_data;
- }
if (data_writer_write_fragment_table(data))
goto out_data;
- if (id_table_write(&info.idtbl, info.outfd, &info.super, info.cmp))
+ if (id_table_write(&idtbl, outfd, &super, cmp))
goto out_data;
- if (write_xattr(info.outfd, &info.fs, &info.super, info.cmp))
+ if (write_xattr(outfd, &fs, &super, cmp))
goto out_data;
- if (sqfs_super_write(&info.super, info.outfd))
+ if (sqfs_super_write(&super, outfd))
goto out_data;
- if (padd_file(&info))
+ if (padd_file(outfd, &super, &opt))
goto out_data;
status = EXIT_SUCCESS;
out_data:
data_writer_destroy(data);
out_cmp:
- info.cmp->destroy(info.cmp);
+ cmp->destroy(cmp);
out_fstree:
- fstree_cleanup(&info.fs);
+ fstree_cleanup(&fs);
out_outfd:
- close(info.outfd);
+ close(outfd);
out_idtbl:
- id_table_cleanup(&info.idtbl);
+ id_table_cleanup(&idtbl);
return status;
}
diff --git a/mkfs/mkfs.h b/mkfs/mkfs.h
index e7a339f..e354f7c 100644
--- a/mkfs/mkfs.h
+++ b/mkfs/mkfs.h
@@ -36,19 +36,8 @@ typedef struct {
char *comp_extra;
} options_t;
-typedef struct {
- int outfd;
- options_t opt;
- sqfs_super_t super;
- fstree_t fs;
-
- id_table_t idtbl;
-
- compressor_t *cmp;
-} sqfs_info_t;
-
void process_command_line(options_t *opt, int argc, char **argv);
-int write_data_to_image(data_writer_t *data, sqfs_info_t *info);
+int write_data_to_image(data_writer_t *data, fstree_t *fs, options_t *opt);
#endif /* MKFS_H */
diff --git a/mkfs/options.c b/mkfs/options.c
index 272e860..8ed01ba 100644
--- a/mkfs/options.c
+++ b/mkfs/options.c
@@ -253,8 +253,12 @@ void process_command_line(options_t *opt, int argc, char **argv)
opt->compressor = SQFS_COMP_XZ;
opt->blksz = SQFS_DEFAULT_BLOCK_SIZE;
opt->devblksz = SQFS_DEVBLK_SIZE;
+ opt->quiet = false;
opt->infile = NULL;
+ opt->packdir = NULL;
opt->outfile = NULL;
+ opt->selinux = NULL;
+ opt->comp_extra = NULL;
for (;;) {
i = getopt_long(argc, argv, short_opts, long_opts, NULL);