From 04aa1d971efb44eefa2290ed981c61842b7f62b7 Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Sat, 4 May 2019 21:02:09 +0200 Subject: Rename tools to not collide with squashfs-tools This commit changes the names of the tools to gensquashfs and rdsquashfs so they don't collide with the names used by the squashfs-tools package and the two can be installed side by side. Signed-off-by: David Oberhollenzer --- mkfs/Makemodule.am | 12 +++--- mkfs/block.c | 2 +- mkfs/meta.c | 2 +- mkfs/mkfs.c | 118 +++++++++++++++++++++++++++++++++++++++++++++++++++++ mkfs/mkfs.h | 61 +++++++++++++++++++++++++++ mkfs/mksquashfs.c | 118 ----------------------------------------------------- mkfs/mksquashfs.h | 61 --------------------------- mkfs/options.c | 2 +- 8 files changed, 188 insertions(+), 188 deletions(-) create mode 100644 mkfs/mkfs.c create mode 100644 mkfs/mkfs.h delete mode 100644 mkfs/mksquashfs.c delete mode 100644 mkfs/mksquashfs.h (limited to 'mkfs') diff --git a/mkfs/Makemodule.am b/mkfs/Makemodule.am index 3914e71..5af5ad5 100644 --- a/mkfs/Makemodule.am +++ b/mkfs/Makemodule.am @@ -1,13 +1,13 @@ -mksquashfs_SOURCES = mkfs/mksquashfs.c mkfs/mksquashfs.h mkfs/block.c -mksquashfs_SOURCES += mkfs/options.c mkfs/meta.c -mksquashfs_LDADD = libsquashfs.a libfstree.a libcompress.a libutil.a +gensquashfs_SOURCES = mkfs/mkfs.c mkfs/mkfs.h mkfs/block.c +gensquashfs_SOURCES += mkfs/options.c mkfs/meta.c +gensquashfs_LDADD = libsquashfs.a libfstree.a libcompress.a libutil.a if WITH_XZ -mksquashfs_LDADD += $(XZ_LIBS) +gensquashfs_LDADD += $(XZ_LIBS) endif if WITH_GZIP -mksquashfs_LDADD += $(ZLIB_LIBS) +gensquashfs_LDADD += $(ZLIB_LIBS) endif -bin_PROGRAMS += mksquashfs +bin_PROGRAMS += gensquashfs diff --git a/mkfs/block.c b/mkfs/block.c index 3472346..76b261d 100644 --- a/mkfs/block.c +++ b/mkfs/block.c @@ -1,5 +1,5 @@ /* SPDX-License-Identifier: GPL-3.0-or-later */ -#include "mksquashfs.h" +#include "mkfs.h" #include "util.h" static int write_block(file_info_t *fi, sqfs_info_t *info) diff --git a/mkfs/meta.c b/mkfs/meta.c index c48aec3..f7de5c6 100644 --- a/mkfs/meta.c +++ b/mkfs/meta.c @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: GPL-3.0-or-later */ #include "meta_writer.h" -#include "mksquashfs.h" +#include "mkfs.h" #include "util.h" #include diff --git a/mkfs/mkfs.c b/mkfs/mkfs.c new file mode 100644 index 0000000..d708d37 --- /dev/null +++ b/mkfs/mkfs.c @@ -0,0 +1,118 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +#include "mkfs.h" +#include "util.h" + +static int padd_file(sqfs_info_t *info) +{ + 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 = info->opt.devblksz - padd_sz; + + buffer = calloc(1, padd_sz); + if (buffer == NULL) { + perror("padding output file to block size"); + return -1; + } + + ret = write_retry(info->outfd, buffer, padd_sz); + + if (ret < 0) { + perror("Error padding squashfs image to page size"); + free(buffer); + return -1; + } + + if ((size_t)ret < padd_sz) { + fputs("Truncated write trying to padd squashfs image\n", + stderr); + return -1; + } + + free(buffer); + return 0; +} + +int main(int argc, char **argv) +{ + int status = EXIT_FAILURE; + sqfs_info_t info; + + memset(&info, 0, sizeof(info)); + + process_command_line(&info.opt, argc, argv); + + if (sqfs_super_init(&info.super, info.opt.blksz, info.opt.def_mtime, + info.opt.compressor)) { + return EXIT_FAILURE; + } + + if (id_table_init(&info.idtbl)) + return EXIT_FAILURE; + + info.outfd = open(info.opt.outfile, info.opt.outmode, 0644); + if (info.outfd < 0) { + perror(info.opt.outfile); + goto out_idtbl; + } + + if (sqfs_super_write(&info.super, info.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)) { + goto out_outfd; + } + + if (fstree_from_file(&info.fs, info.opt.infile)) + goto out_fstree; + + fstree_sort(&info.fs); + + info.cmp = compressor_create(info.super.compression_id, true, + info.super.block_size); + if (info.cmp == NULL) { + fputs("Error creating compressor\n", stderr); + goto out_outfd; + } + + if (write_data_to_image(&info)) + goto out_cmp; + + if (sqfs_write_inodes(&info)) + goto out_cmp; + + info.super.fragment_entry_count = info.num_fragments; + + if (sqfs_write_table(info.outfd, &info.super, info.fragments, + sizeof(info.fragments[0]), info.num_fragments, + &info.super.fragment_table_start, info.cmp)) { + goto out_cmp; + } + + if (id_table_write(&info.idtbl, info.outfd, &info.super, info.cmp)) + goto out_cmp; + + if (sqfs_super_write(&info.super, info.outfd)) + goto out_cmp; + + if (padd_file(&info)) + goto out_cmp; + + status = EXIT_SUCCESS; +out_cmp: + free(info.fragments); + info.cmp->destroy(info.cmp); +out_fstree: + fstree_cleanup(&info.fs); +out_outfd: + close(info.outfd); +out_idtbl: + id_table_cleanup(&info.idtbl); + return status; +} diff --git a/mkfs/mkfs.h b/mkfs/mkfs.h new file mode 100644 index 0000000..8a867f2 --- /dev/null +++ b/mkfs/mkfs.h @@ -0,0 +1,61 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +#ifndef MKFS_H +#define MKFS_H + +#include "squashfs.h" +#include "compress.h" +#include "id_table.h" +#include "fstree.h" +#include "config.h" +#include "table.h" + +#include +#include +#include +#include +#include +#include + +typedef struct { + unsigned int def_uid; + unsigned int def_gid; + unsigned int def_mode; + unsigned int def_mtime; + int outmode; + int compressor; + int blksz; + int devblksz; + const char *infile; + const char *outfile; +} options_t; + +typedef struct { + int outfd; + options_t opt; + sqfs_super_t super; + fstree_t fs; + void *block; + void *fragment; + void *scratch; + + 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; + + id_table_t idtbl; + size_t inode_counter; + + compressor_t *cmp; +} sqfs_info_t; + +void process_command_line(options_t *opt, int argc, char **argv); + +int write_data_to_image(sqfs_info_t *info); + +int sqfs_write_inodes(sqfs_info_t *info); + +#endif /* MKFS_H */ diff --git a/mkfs/mksquashfs.c b/mkfs/mksquashfs.c deleted file mode 100644 index 2f2e508..0000000 --- a/mkfs/mksquashfs.c +++ /dev/null @@ -1,118 +0,0 @@ -/* SPDX-License-Identifier: GPL-3.0-or-later */ -#include "mksquashfs.h" -#include "util.h" - -static int padd_file(sqfs_info_t *info) -{ - 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 = info->opt.devblksz - padd_sz; - - buffer = calloc(1, padd_sz); - if (buffer == NULL) { - perror("padding output file to block size"); - return -1; - } - - ret = write_retry(info->outfd, buffer, padd_sz); - - if (ret < 0) { - perror("Error padding squashfs image to page size"); - free(buffer); - return -1; - } - - if ((size_t)ret < padd_sz) { - fputs("Truncated write trying to padd squashfs image\n", - stderr); - return -1; - } - - free(buffer); - return 0; -} - -int main(int argc, char **argv) -{ - int status = EXIT_FAILURE; - sqfs_info_t info; - - memset(&info, 0, sizeof(info)); - - process_command_line(&info.opt, argc, argv); - - if (sqfs_super_init(&info.super, info.opt.blksz, info.opt.def_mtime, - info.opt.compressor)) { - return EXIT_FAILURE; - } - - if (id_table_init(&info.idtbl)) - return EXIT_FAILURE; - - info.outfd = open(info.opt.outfile, info.opt.outmode, 0644); - if (info.outfd < 0) { - perror(info.opt.outfile); - goto out_idtbl; - } - - if (sqfs_super_write(&info.super, info.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)) { - goto out_outfd; - } - - if (fstree_from_file(&info.fs, info.opt.infile)) - goto out_fstree; - - fstree_sort(&info.fs); - - info.cmp = compressor_create(info.super.compression_id, true, - info.super.block_size); - if (info.cmp == NULL) { - fputs("Error creating compressor\n", stderr); - goto out_outfd; - } - - if (write_data_to_image(&info)) - goto out_cmp; - - if (sqfs_write_inodes(&info)) - goto out_cmp; - - info.super.fragment_entry_count = info.num_fragments; - - if (sqfs_write_table(info.outfd, &info.super, info.fragments, - sizeof(info.fragments[0]), info.num_fragments, - &info.super.fragment_table_start, info.cmp)) { - goto out_cmp; - } - - if (id_table_write(&info.idtbl, info.outfd, &info.super, info.cmp)) - goto out_cmp; - - if (sqfs_super_write(&info.super, info.outfd)) - goto out_cmp; - - if (padd_file(&info)) - goto out_cmp; - - status = EXIT_SUCCESS; -out_cmp: - free(info.fragments); - info.cmp->destroy(info.cmp); -out_fstree: - fstree_cleanup(&info.fs); -out_outfd: - close(info.outfd); -out_idtbl: - id_table_cleanup(&info.idtbl); - return status; -} diff --git a/mkfs/mksquashfs.h b/mkfs/mksquashfs.h deleted file mode 100644 index 106822c..0000000 --- a/mkfs/mksquashfs.h +++ /dev/null @@ -1,61 +0,0 @@ -/* SPDX-License-Identifier: GPL-3.0-or-later */ -#ifndef MKSQUASHFS_H -#define MKSQUASHFS_H - -#include "squashfs.h" -#include "compress.h" -#include "id_table.h" -#include "fstree.h" -#include "config.h" -#include "table.h" - -#include -#include -#include -#include -#include -#include - -typedef struct { - unsigned int def_uid; - unsigned int def_gid; - unsigned int def_mode; - unsigned int def_mtime; - int outmode; - int compressor; - int blksz; - int devblksz; - const char *infile; - const char *outfile; -} options_t; - -typedef struct { - int outfd; - options_t opt; - sqfs_super_t super; - fstree_t fs; - void *block; - void *fragment; - void *scratch; - - 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; - - id_table_t idtbl; - size_t inode_counter; - - compressor_t *cmp; -} sqfs_info_t; - -void process_command_line(options_t *opt, int argc, char **argv); - -int write_data_to_image(sqfs_info_t *info); - -int sqfs_write_inodes(sqfs_info_t *info); - -#endif /* MKSQUASHFS_H */ diff --git a/mkfs/options.c b/mkfs/options.c index f1fe192..4d49a9b 100644 --- a/mkfs/options.c +++ b/mkfs/options.c @@ -1,5 +1,5 @@ /* SPDX-License-Identifier: GPL-3.0-or-later */ -#include "mksquashfs.h" +#include "mkfs.h" #include "util.h" #include -- cgit v1.2.3