summaryrefslogtreecommitdiff
path: root/mkfs/mkfs.c
diff options
context:
space:
mode:
Diffstat (limited to 'mkfs/mkfs.c')
-rw-r--r--mkfs/mkfs.c138
1 files changed, 17 insertions, 121 deletions
diff --git a/mkfs/mkfs.c b/mkfs/mkfs.c
index e36f2f4..16f9bc0 100644
--- a/mkfs/mkfs.c
+++ b/mkfs/mkfs.c
@@ -42,7 +42,7 @@ static int pack_files(sqfs_data_writer_t *data, fstree_t *fs,
return -1;
for (fi = fs->files; fi != NULL; fi = fi->next) {
- if (!opt->quiet)
+ if (!opt->cfg.quiet)
printf("packing %s\n", fi->input_file);
file = sqfs_open_file(fi->input_file,
@@ -54,8 +54,8 @@ static int pack_files(sqfs_data_writer_t *data, fstree_t *fs,
filesize = file->get_size(file);
- max_blk_count = filesize / opt->blksz;
- if (filesize % opt->blksz)
+ max_blk_count = filesize / opt->cfg.block_size;
+ if (filesize % opt->cfg.block_size)
++max_blk_count;
inode = alloc_flex(sizeof(*inode), sizeof(sqfs_u32),
@@ -83,9 +83,6 @@ static int pack_files(sqfs_data_writer_t *data, fstree_t *fs,
stats->bytes_read += filesize;
}
- if (sqfs_data_writer_finish(data))
- return -1;
-
return restore_working_dir(opt);
}
@@ -154,63 +151,26 @@ static int read_fstree(fstree_t *fs, options_t *opt, sqfs_xattr_writer_t *xwr,
int main(int argc, char **argv)
{
- int status = EXIT_FAILURE, ret;
- sqfs_compressor_config_t cfg;
- data_writer_stats_t stats;
- sqfs_data_writer_t *data;
- sqfs_xattr_writer_t *xwr;
- sqfs_compressor_t *cmp;
- sqfs_id_table_t *idtbl;
- sqfs_file_t *outfile;
+ int status = EXIT_FAILURE;
void *sehnd = NULL;
- sqfs_super_t super;
+ sqfs_writer_t sqfs;
options_t opt;
- fstree_t fs;
process_command_line(&opt, argc, argv);
- if (compressor_cfg_init_options(&cfg, opt.compressor,
- opt.blksz, opt.comp_extra)) {
- return EXIT_FAILURE;
- }
-
- if (fstree_init(&fs, opt.fs_defaults))
+ if (sqfs_writer_init(&sqfs, &opt.cfg))
return EXIT_FAILURE;
- if (sqfs_super_init(&super, opt.blksz, fs.defaults.st_mtime,
- opt.compressor)) {
- goto out_fstree;
- }
-
- idtbl = sqfs_id_table_create();
- if (idtbl == NULL)
- goto out_fstree;
-
- outfile = sqfs_open_file(opt.outfile, opt.outmode);
- if (outfile == NULL) {
- perror(opt.outfile);
- goto out_idtbl;
- }
-
- if (sqfs_super_write(&super, outfile))
- goto out_outfile;
-
if (opt.selinux != NULL) {
sehnd = selinux_open_context_file(opt.selinux);
if (sehnd == NULL)
- goto out_outfile;
- }
-
- xwr = sqfs_xattr_writer_create();
- if (xwr == NULL) {
- perror("creating Xattr writer");
- goto out_outfile;
+ goto out;
}
- if (read_fstree(&fs, &opt, xwr, sehnd)) {
+ if (read_fstree(&sqfs.fs, &opt, sqfs.xwr, sehnd)) {
if (sehnd != NULL)
selinux_close_context_file(sehnd);
- goto out_xwr;
+ goto out;
}
if (sehnd != NULL) {
@@ -218,81 +178,17 @@ int main(int argc, char **argv)
sehnd = NULL;
}
- tree_node_sort_recursive(fs.root);
-
- if (fstree_gen_inode_table(&fs))
- goto out_xwr;
-
- fstree_gen_file_list(&fs);
-
- super.inode_count = fs.inode_tbl_size;
-
- cmp = sqfs_compressor_create(&cfg);
- if (cmp == NULL) {
- fputs("Error creating compressor\n", stderr);
- goto out_xwr;
- }
-
- ret = cmp->write_options(cmp, outfile);
- if (ret < 0)
- goto out_cmp;
-
- if (ret > 0)
- super.flags |= SQFS_FLAG_COMPRESSOR_OPTIONS;
-
- data = sqfs_data_writer_create(super.block_size, cmp, opt.num_jobs,
- opt.max_backlog, opt.devblksz, outfile);
- if (data == NULL)
- goto out_cmp;
-
- memset(&stats, 0, sizeof(stats));
- register_stat_hooks(data, &stats);
-
- if (pack_files(data, &fs, &stats, &opt))
- goto out_data;
-
- if (sqfs_serialize_fstree(outfile, &super, &fs, cmp, idtbl))
- goto out_data;
-
- if (sqfs_data_writer_write_fragment_table(data, &super))
- goto out_data;
-
- if (opt.exportable) {
- if (write_export_table(outfile, &fs, &super, cmp))
- goto out_data;
- }
-
- if (sqfs_id_table_write(idtbl, outfile, &super, cmp))
- goto out_data;
-
- if (sqfs_xattr_writer_flush(xwr, outfile, &super, cmp)) {
- fputs("Error writing xattr table\n", stderr);
- goto out_data;
- }
-
- super.bytes_used = outfile->get_size(outfile);
-
- if (sqfs_super_write(&super, outfile))
- goto out_data;
+ tree_node_sort_recursive(sqfs.fs.root);
+ fstree_gen_file_list(&sqfs.fs);
- if (padd_sqfs(outfile, super.bytes_used, opt.devblksz))
- goto out_data;
+ if (pack_files(sqfs.data, &sqfs.fs, &sqfs.stats, &opt))
+ goto out;
- if (!opt.quiet)
- sqfs_print_statistics(&super, &stats);
+ if (sqfs_writer_finish(&sqfs, &opt.cfg))
+ goto out;
status = EXIT_SUCCESS;
-out_data:
- sqfs_data_writer_destroy(data);
-out_cmp:
- cmp->destroy(cmp);
-out_xwr:
- sqfs_xattr_writer_destroy(xwr);
-out_outfile:
- outfile->destroy(outfile);
-out_idtbl:
- sqfs_id_table_destroy(idtbl);
-out_fstree:
- fstree_cleanup(&fs);
+out:
+ sqfs_writer_cleanup(&sqfs);
return status;
}