diff options
author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2019-06-11 13:34:15 +0200 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2019-06-11 13:34:15 +0200 |
commit | 4dc69cb9cd97e9a1f233a0f19ee8035929fa6065 (patch) | |
tree | 4d93cf0deb934e6e8914c89434ea51b1c02b72b7 /mkfs | |
parent | 99b153177dbac8689b2e58fc29530727fa7e00fc (diff) |
cleanup: merge rest of block.c into mkfs.c
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'mkfs')
-rw-r--r-- | mkfs/Makemodule.am | 2 | ||||
-rw-r--r-- | mkfs/block.c | 84 | ||||
-rw-r--r-- | mkfs/mkfs.c | 69 | ||||
-rw-r--r-- | mkfs/mkfs.h | 2 |
4 files changed, 69 insertions, 88 deletions
diff --git a/mkfs/Makemodule.am b/mkfs/Makemodule.am index fac5eec..07ea6b6 100644 --- a/mkfs/Makemodule.am +++ b/mkfs/Makemodule.am @@ -1,4 +1,4 @@ -gensquashfs_SOURCES = mkfs/mkfs.c mkfs/mkfs.h mkfs/block.c mkfs/options.c +gensquashfs_SOURCES = mkfs/mkfs.c mkfs/mkfs.h mkfs/options.c gensquashfs_LDADD = libsquashfs.a libfstree.a libcompress.a libutil.a gensquashfs_CPPFLAGS = $(AM_CPPFLAGS) diff --git a/mkfs/block.c b/mkfs/block.c deleted file mode 100644 index 73d43e8..0000000 --- a/mkfs/block.c +++ /dev/null @@ -1,84 +0,0 @@ -/* SPDX-License-Identifier: GPL-3.0-or-later */ -#include "mkfs.h" -#include "util.h" - -static int process_file(data_writer_t *data, file_info_t *fi) -{ - int ret, infd; - - infd = open(fi->input_file, O_RDONLY); - if (infd < 0) { - perror(fi->input_file); - return -1; - } - - ret = write_data_from_fd(data, fi, infd); - - close(infd); - return ret; -} - -static void print_name(tree_node_t *n) -{ - if (n->parent != NULL) { - print_name(n->parent); - fputc('/', stdout); - } - - fputs(n->name, stdout); -} - -static int find_and_process_files(data_writer_t *data, tree_node_t *n, - bool quiet) -{ - if (S_ISDIR(n->mode)) { - for (n = n->data.dir->children; n != NULL; n = n->next) { - if (find_and_process_files(data, n, quiet)) - return -1; - } - return 0; - } - - if (S_ISREG(n->mode)) { - if (!quiet) { - fputs("packing ", stdout); - print_name(n); - fputc('\n', stdout); - } - - return process_file(data, n->data.file); - } - - return 0; -} - -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 (opt->packdir != NULL) { - if (pushd(opt->packdir)) - return -1; - need_restore = true; - } else { - ptr = strrchr(opt->infile, '/'); - - if (ptr != NULL) { - if (pushdn(opt->infile, ptr - opt->infile)) - return -1; - - need_restore = true; - } - } - - ret = find_and_process_files(data, fs->root, opt->quiet); - - ret = ret == 0 ? data_writer_flush_fragments(data) : ret; - - if (need_restore) - ret = ret == 0 ? popd() : ret; - - return ret; -} diff --git a/mkfs/mkfs.c b/mkfs/mkfs.c index 86172e3..8028919 100644 --- a/mkfs/mkfs.c +++ b/mkfs/mkfs.c @@ -37,6 +37,73 @@ static int padd_file(int outfd, sqfs_super_t *super, options_t *opt) return 0; } +static int process_file(data_writer_t *data, tree_node_t *n, bool quiet) +{ + int ret, infd; + char *name; + + if (!quiet) { + name = fstree_get_path(n); + printf("packing %s\n", name); + free(name); + } + + infd = open(n->data.file->input_file, O_RDONLY); + if (infd < 0) { + perror(n->data.file->input_file); + return -1; + } + + ret = write_data_from_fd(data, n->data.file, infd); + + close(infd); + return ret; +} + +static int pack_files_dfs(data_writer_t *data, tree_node_t *n, bool quiet) +{ + if (S_ISREG(n->mode)) + return process_file(data, n, quiet); + + if (S_ISDIR(n->mode)) { + for (n = n->data.dir->children; n != NULL; n = n->next) { + if (pack_files_dfs(data, n, quiet)) + return -1; + } + } + + return 0; +} + +static int pack_files(data_writer_t *data, fstree_t *fs, options_t *opt) +{ + bool need_restore = false; + const char *ptr; + + if (opt->packdir != NULL) { + if (pushd(opt->packdir)) + return -1; + need_restore = true; + } else { + ptr = strrchr(opt->infile, '/'); + + if (ptr != NULL) { + if (pushdn(opt->infile, ptr - opt->infile)) + return -1; + + need_restore = true; + } + } + + if (pack_files_dfs(data, fs->root, opt->quiet)) + return -1; + + if (data_writer_flush_fragments(data)) + return -1; + + return need_restore ? popd() : 0; +} + int main(int argc, char **argv) { int status = EXIT_FAILURE, ret; @@ -114,7 +181,7 @@ int main(int argc, char **argv) if (data == NULL) goto out_cmp; - if (write_data_to_image(data, &fs, &opt)) + if (pack_files(data, &fs, &opt)) goto out_data; if (sqfs_serialize_fstree(outfd, &super, &fs, cmp, &idtbl)) diff --git a/mkfs/mkfs.h b/mkfs/mkfs.h index e354f7c..a743cf7 100644 --- a/mkfs/mkfs.h +++ b/mkfs/mkfs.h @@ -38,6 +38,4 @@ typedef struct { void process_command_line(options_t *opt, int argc, char **argv); -int write_data_to_image(data_writer_t *data, fstree_t *fs, options_t *opt); - #endif /* MKFS_H */ |