aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-04-30 13:06:16 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-05-02 12:40:06 +0200
commite711928cb0931c1d14ac14cfad709c2a453d6c31 (patch)
treefca3ce13a04c37f9266f749cd1a094a9ae7979b2
parent5ffeac25e3ae614e9c6b7d274962c8e0084907fd (diff)
Store globally interesting data in sqfs_info_t structure
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
-rw-r--r--mkfs/mksquashfs.c39
-rw-r--r--mkfs/mksquashfs.h23
-rw-r--r--mkfs/super.c98
3 files changed, 89 insertions, 71 deletions
diff --git a/mkfs/mksquashfs.c b/mkfs/mksquashfs.c
index 17de4ed..65cd552 100644
--- a/mkfs/mksquashfs.c
+++ b/mkfs/mksquashfs.c
@@ -36,47 +36,48 @@ static void print_tree(int level, tree_node_t *node)
int main(int argc, char **argv)
{
- int outfd, status = EXIT_FAILURE;
- sqfs_super_t super;
- options_t opt;
- fstree_t fs;
+ int status = EXIT_FAILURE;
+ sqfs_info_t info;
- process_command_line(&opt, argc, argv);
+ memset(&info, 0, sizeof(info));
- if (sqfs_super_init(&super, &opt) != 0)
+ process_command_line(&info.opt, argc, argv);
+
+ if (sqfs_super_init(&info) != 0)
return EXIT_FAILURE;
- outfd = open(opt.outfile, opt.outmode, 0644);
- if (outfd < 0) {
- perror(opt.outfile);
+ info.outfd = open(info.opt.outfile, info.opt.outmode, 0644);
+ if (info.outfd < 0) {
+ perror(info.opt.outfile);
return EXIT_FAILURE;
}
- if (sqfs_super_write(&super, outfd))
+ if (sqfs_super_write(&info))
goto out_outfd;
- if (fstree_init(&fs, opt.blksz, opt.def_mtime, opt.def_mode,
- opt.def_uid, opt.def_gid)) {
+ if (fstree_init(&info.fs, info.opt.blksz, info.opt.def_mtime,
+ info.opt.def_mode, info.opt.def_uid,
+ info.opt.def_gid)) {
goto out_outfd;
}
- if (fstree_from_file(&fs, opt.infile))
+ if (fstree_from_file(&info.fs, info.opt.infile))
goto out_fstree;
- fstree_sort(&fs);
+ fstree_sort(&info.fs);
- print_tree(0, fs.root);
+ print_tree(0, info.fs.root);
- if (sqfs_super_write(&super, outfd))
+ if (sqfs_super_write(&info))
goto out_outfd;
- if (sqfs_padd_file(&super, &opt, outfd))
+ if (sqfs_padd_file(&info))
goto out_fstree;
status = EXIT_SUCCESS;
out_fstree:
- fstree_cleanup(&fs);
+ fstree_cleanup(&info.fs);
out_outfd:
- close(outfd);
+ close(info.outfd);
return status;
}
diff --git a/mkfs/mksquashfs.h b/mkfs/mksquashfs.h
index 677dad4..e216329 100644
--- a/mkfs/mksquashfs.h
+++ b/mkfs/mksquashfs.h
@@ -35,13 +35,30 @@ typedef struct {
compressor_t *cmp;
} meta_writer_t;
+typedef struct {
+ int outfd;
+ options_t opt;
+ sqfs_super_t super;
+ fstree_t fs;
+ void *block;
+ void *fragment;
+
+ sqfs_fragment_t *fragments;
+ size_t num_fragments;
+ size_t max_fragments;
+
+ int file_block_count;
+ file_info_t *frag_list;
+ size_t frag_offset;
+} sqfs_info_t;
+
void process_command_line(options_t *opt, int argc, char **argv);
-int sqfs_super_init(sqfs_super_t *s, const options_t *opt);
+int sqfs_super_init(sqfs_info_t *info);
-int sqfs_padd_file(sqfs_super_t *s, const options_t *opt, int outfd);
+int sqfs_padd_file(sqfs_info_t *info);
-int sqfs_super_write(const sqfs_super_t *super, int outfd);
+int sqfs_super_write(sqfs_info_t *info);
meta_writer_t *meta_writer_create(int fd, compressor_t *cmp);
diff --git a/mkfs/super.c b/mkfs/super.c
index b3755d1..c924b6c 100644
--- a/mkfs/super.c
+++ b/mkfs/super.c
@@ -4,52 +4,52 @@
#include <endian.h>
-int sqfs_super_init(sqfs_super_t *s, const options_t *opt)
+int sqfs_super_init(sqfs_info_t *info)
{
unsigned int i;
- if (opt->blksz & (opt->blksz - 1)) {
+ if (info->opt.blksz & (info->opt.blksz - 1)) {
fputs("Block size must be a power of 2!\n", stderr);
return -1;
}
- if (opt->blksz < 8192 || opt->blksz >= (1 << 24)) {
+ if (info->opt.blksz < 8192 || info->opt.blksz >= (1 << 24)) {
fputs("Block size must be between 8k and 1M\n", stderr);
return -1;
}
- memset(s, 0, sizeof(*s));
- s->magic = SQFS_MAGIC;
- s->modification_time = opt->def_mtime;
- s->block_size = opt->blksz;
- s->compression_id = opt->compressor;
- s->flags = SQFS_FLAG_NO_FRAGMENTS | SQFS_FLAG_NO_XATTRS;
- s->version_major = SQFS_VERSION_MAJOR;
- s->version_minor = SQFS_VERSION_MINOR;
- s->bytes_used = sizeof(*s);
- s->id_table_start = 0xFFFFFFFFFFFFFFFFUL;
- s->xattr_id_table_start = 0xFFFFFFFFFFFFFFFFUL;
- s->inode_table_start = 0xFFFFFFFFFFFFFFFFUL;
- s->directory_table_start = 0xFFFFFFFFFFFFFFFFUL;
- s->fragment_table_start = 0xFFFFFFFFFFFFFFFFUL;
- s->export_table_start = 0xFFFFFFFFFFFFFFFFUL;
-
- for (i = opt->blksz; i != 0x01; i >>= 1)
- s->block_log += 1;
+ memset(&info->super, 0, sizeof(info->super));
+ info->super.magic = SQFS_MAGIC;
+ info->super.modification_time = info->opt.def_mtime;
+ info->super.block_size = info->opt.blksz;
+ info->super.compression_id = info->opt.compressor;
+ info->super.flags = SQFS_FLAG_NO_FRAGMENTS | SQFS_FLAG_NO_XATTRS;
+ info->super.version_major = SQFS_VERSION_MAJOR;
+ info->super.version_minor = SQFS_VERSION_MINOR;
+ info->super.bytes_used = sizeof(info->super);
+ info->super.id_table_start = 0xFFFFFFFFFFFFFFFFUL;
+ info->super.xattr_id_table_start = 0xFFFFFFFFFFFFFFFFUL;
+ info->super.inode_table_start = 0xFFFFFFFFFFFFFFFFUL;
+ info->super.directory_table_start = 0xFFFFFFFFFFFFFFFFUL;
+ info->super.fragment_table_start = 0xFFFFFFFFFFFFFFFFUL;
+ info->super.export_table_start = 0xFFFFFFFFFFFFFFFFUL;
+
+ for (i = info->opt.blksz; i != 0x01; i >>= 1)
+ info->super.block_log += 1;
return 0;
}
-int sqfs_padd_file(sqfs_super_t *s, const options_t *opt, int outfd)
+int sqfs_padd_file(sqfs_info_t *info)
{
- size_t padd_sz = s->bytes_used % opt->devblksz;
+ size_t padd_sz = info->super.bytes_used % info->opt.devblksz;
uint8_t *buffer;
ssize_t ret;
if (padd_sz == 0)
return 0;
- padd_sz = opt->devblksz - padd_sz;
+ padd_sz = info->opt.devblksz - padd_sz;
buffer = calloc(1, padd_sz);
if (buffer == NULL) {
@@ -57,7 +57,7 @@ int sqfs_padd_file(sqfs_super_t *s, const options_t *opt, int outfd)
return -1;
}
- ret = write_retry(outfd, buffer, padd_sz);
+ ret = write_retry(info->outfd, buffer, padd_sz);
if (ret < 0) {
perror("Error padding squashfs image to page size");
@@ -75,35 +75,35 @@ int sqfs_padd_file(sqfs_super_t *s, const options_t *opt, int outfd)
return 0;
}
-int sqfs_super_write(const sqfs_super_t *super, int outfd)
+int sqfs_super_write(sqfs_info_t *info)
{
sqfs_super_t copy;
ssize_t ret;
- copy.magic = htole32(super->magic);
- copy.inode_count = htole32(super->inode_count);
- copy.modification_time = htole32(super->modification_time);
- copy.block_size = htole32(super->block_size);
- copy.fragment_entry_count = htole32(super->fragment_entry_count);
- copy.compression_id = htole16(super->compression_id);
- copy.block_log = htole16(super->block_log);
- copy.flags = htole16(super->flags);
- copy.id_count = htole16(super->id_count);
- copy.version_major = htole16(super->version_major);
- copy.version_minor = htole16(super->version_minor);
- copy.root_inode_ref = htole64(super->root_inode_ref);
- copy.bytes_used = htole64(super->bytes_used);
- copy.id_table_start = htole64(super->id_table_start);
- copy.xattr_id_table_start = htole64(super->xattr_id_table_start);
- copy.inode_table_start = htole64(super->inode_table_start);
- copy.directory_table_start = htole64(super->directory_table_start);
- copy.fragment_table_start = htole64(super->fragment_table_start);
- copy.export_table_start = htole64(super->export_table_start);
-
- if (lseek(outfd, 0, SEEK_SET) == (off_t)-1)
+ copy.magic = htole32(info->super.magic);
+ copy.inode_count = htole32(info->super.inode_count);
+ copy.modification_time = htole32(info->super.modification_time);
+ copy.block_size = htole32(info->super.block_size);
+ copy.fragment_entry_count = htole32(info->super.fragment_entry_count);
+ copy.compression_id = htole16(info->super.compression_id);
+ copy.block_log = htole16(info->super.block_log);
+ copy.flags = htole16(info->super.flags);
+ copy.id_count = htole16(info->super.id_count);
+ copy.version_major = htole16(info->super.version_major);
+ copy.version_minor = htole16(info->super.version_minor);
+ copy.root_inode_ref = htole64(info->super.root_inode_ref);
+ copy.bytes_used = htole64(info->super.bytes_used);
+ copy.id_table_start = htole64(info->super.id_table_start);
+ copy.xattr_id_table_start = htole64(info->super.xattr_id_table_start);
+ copy.inode_table_start = htole64(info->super.inode_table_start);
+ copy.directory_table_start = htole64(info->super.directory_table_start);
+ copy.fragment_table_start = htole64(info->super.fragment_table_start);
+ copy.export_table_start = htole64(info->super.export_table_start);
+
+ if (lseek(info->outfd, 0, SEEK_SET) == (off_t)-1)
goto fail_seek;
- ret = write_retry(outfd, &copy, sizeof(copy));
+ ret = write_retry(info->outfd, &copy, sizeof(copy));
if (ret < 0) {
perror("squashfs writing super block");
@@ -116,7 +116,7 @@ int sqfs_super_write(const sqfs_super_t *super, int outfd)
return -1;
}
- if (lseek(outfd, 0, SEEK_END) == (off_t)-1)
+ if (lseek(info->outfd, 0, SEEK_END) == (off_t)-1)
goto fail_seek;
return 0;