diff options
author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2020-11-07 16:04:40 +0100 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2020-11-07 16:12:47 +0100 |
commit | 411f659fe0140bacbd56f8503cda269816d4a887 (patch) | |
tree | 1b1f97a2964d550292790d949471eff96776d11c /include | |
parent | 73e853f9660072abf0ae68cbb5d9753ac6e9034a (diff) |
Cleanup: libcommon: try to split up some of the larger files
The sqsf_writer is moved to a separate header, as well as the compressor
related stuff. The statistics function is moved into the writer code, as
this is the only place that actually uses it. The writer code itself is
split up into a hand full of file in their own subdirectory.
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'include')
-rw-r--r-- | include/common.h | 90 | ||||
-rw-r--r-- | include/compress_cli.h | 42 | ||||
-rw-r--r-- | include/simple_writer.h | 87 |
3 files changed, 131 insertions, 88 deletions
diff --git a/include/common.h b/include/common.h index ea27edc..b0c7abb 100644 --- a/include/common.h +++ b/include/common.h @@ -9,25 +9,17 @@ #include "config.h" -#include "sqfs/xattr_writer.h" #include "sqfs/xattr_reader.h" -#include "sqfs/compressor.h" -#include "sqfs/id_table.h" #include "sqfs/inode.h" #include "sqfs/table.h" -#include "sqfs/error.h" -#include "sqfs/meta_writer.h" #include "sqfs/data_reader.h" -#include "sqfs/block_processor.h" -#include "sqfs/block_writer.h" -#include "sqfs/frag_table.h" -#include "sqfs/dir_writer.h" #include "sqfs/dir_reader.h" #include "sqfs/block.h" #include "sqfs/xattr.h" #include "sqfs/dir.h" -#include "sqfs/io.h" +#include "simple_writer.h" +#include "compress_cli.h" #include "fstream.h" #include "compat.h" #include "fstree.h" @@ -35,39 +27,6 @@ #include <stddef.h> -typedef struct { - const char *filename; - sqfs_block_writer_t *blkwr; - sqfs_frag_table_t *fragtbl; - sqfs_block_processor_t *data; - sqfs_dir_writer_t *dirwr; - sqfs_meta_writer_t *dm; - sqfs_meta_writer_t *im; - sqfs_compressor_t *cmp; - sqfs_id_table_t *idtbl; - sqfs_file_t *outfile; - sqfs_super_t super; - fstree_t fs; - sqfs_xattr_writer_t *xwr; -} sqfs_writer_t; - -typedef struct { - const char *filename; - char *fs_defaults; - char *comp_extra; - size_t block_size; - size_t devblksize; - size_t max_backlog; - size_t num_jobs; - - int outmode; - SQFS_COMPRESSOR comp_id; - - bool exportable; - bool no_xattr; - bool quiet; -} sqfs_writer_cfg_t; - typedef struct sqfs_hard_link_t { struct sqfs_hard_link_t *next; sqfs_u32 inode_number; @@ -77,35 +36,6 @@ typedef struct sqfs_hard_link_t { #define container_of(ptr, type, member) \ ((type *)((char *)ptr - offsetof(type, member))) -/* - High level helper function to serialize an entire file system tree to - a squashfs inode table and directory table. - - The data is written to the given file descriptor and the super block is - update accordingly (inode and directory table start and total size). - - The function internally creates two meta data writers and uses - meta_writer_write_inode to serialize the inode table of the fstree. - - Returns 0 on success. Prints error messages to stderr on failure. - */ -int sqfs_serialize_fstree(const char *filename, sqfs_writer_t *wr); - -/* Print out fancy statistics for squashfs packing tools */ -void sqfs_print_statistics(const sqfs_super_t *super, - const sqfs_block_processor_t *blk, - const sqfs_block_writer_t *wr); - -void compressor_print_available(void); - -SQFS_COMPRESSOR compressor_get_default(void); - -int compressor_cfg_init_options(sqfs_compressor_config_t *cfg, - SQFS_COMPRESSOR id, - size_t block_size, char *options); - -void compressor_print_help(SQFS_COMPRESSOR id); - int inode_stat(const sqfs_tree_node_t *node, struct stat *sb); char *sqfs_tree_node_get_path(const sqfs_tree_node_t *node); @@ -118,14 +48,6 @@ int write_data_from_file(const char *filename, sqfs_block_processor_t *data, sqfs_inode_generic_t **inode, sqfs_file_t *file, int flags); -void sqfs_writer_cfg_init(sqfs_writer_cfg_t *cfg); - -int sqfs_writer_init(sqfs_writer_t *sqfs, const sqfs_writer_cfg_t *wrcfg); - -int sqfs_writer_finish(sqfs_writer_t *sqfs, const sqfs_writer_cfg_t *cfg); - -void sqfs_writer_cleanup(sqfs_writer_t *sqfs, int status); - void sqfs_perror(const char *file, const char *action, int error_code); int sqfs_tree_find_hard_links(const sqfs_tree_node_t *root, @@ -143,14 +65,6 @@ int mkdir_p(const char *path); void print_version(const char *progname); /* - Create an liblzo2 based LZO compressor. - - XXX: This must be in libcommon instead of libsquashfs for legal reasons. - */ -int lzo_compressor_create(const sqfs_compressor_config_t *cfg, - sqfs_compressor_t **out); - -/* Parse a number optionally followed by a KMG suffix (case insensitive). Prints an error message to stderr and returns -1 on failure, 0 on success. diff --git a/include/compress_cli.h b/include/compress_cli.h new file mode 100644 index 0000000..1ac7972 --- /dev/null +++ b/include/compress_cli.h @@ -0,0 +1,42 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * compress_cli.h + * + * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at> + */ +#ifndef COMPRESS_CLI_H +#define COMPRESS_CLI_H + +#include "sqfs/compressor.h" +#include "sqfs/super.h" +#include "sqfs/block.h" +#include "sqfs/error.h" +#include "sqfs/io.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void compressor_print_available(void); + +SQFS_COMPRESSOR compressor_get_default(void); + +int compressor_cfg_init_options(sqfs_compressor_config_t *cfg, + SQFS_COMPRESSOR id, + size_t block_size, char *options); + +void compressor_print_help(SQFS_COMPRESSOR id); + +/* + Create an liblzo2 based LZO compressor. + + XXX: This must be in libcommon instead of libsquashfs for legal reasons. + */ +int lzo_compressor_create(const sqfs_compressor_config_t *cfg, + sqfs_compressor_t **out); + +#ifdef __cplusplus +} +#endif + +#endif /* COMPRESS_CLI_H */ diff --git a/include/simple_writer.h b/include/simple_writer.h new file mode 100644 index 0000000..1a3302b --- /dev/null +++ b/include/simple_writer.h @@ -0,0 +1,87 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * simple_writer.h + * + * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at> + */ +#ifndef SIMPLE_WRITER_H +#define SIMPLE_WRITER_H + +#include "config.h" + +#include "sqfs/block_processor.h" +#include "sqfs/block_writer.h" +#include "sqfs/xattr_writer.h" +#include "sqfs/meta_writer.h" +#include "sqfs/frag_table.h" +#include "sqfs/dir_writer.h" +#include "sqfs/compressor.h" +#include "sqfs/id_table.h" +#include "sqfs/error.h" +#include "sqfs/io.h" + +#include "fstree.h" + +typedef struct { + const char *filename; + sqfs_block_writer_t *blkwr; + sqfs_frag_table_t *fragtbl; + sqfs_block_processor_t *data; + sqfs_dir_writer_t *dirwr; + sqfs_meta_writer_t *dm; + sqfs_meta_writer_t *im; + sqfs_compressor_t *cmp; + sqfs_id_table_t *idtbl; + sqfs_file_t *outfile; + sqfs_super_t super; + fstree_t fs; + sqfs_xattr_writer_t *xwr; +} sqfs_writer_t; + +typedef struct { + const char *filename; + char *fs_defaults; + char *comp_extra; + size_t block_size; + size_t devblksize; + size_t max_backlog; + size_t num_jobs; + + int outmode; + SQFS_COMPRESSOR comp_id; + + bool exportable; + bool no_xattr; + bool quiet; +} sqfs_writer_cfg_t; + +#ifdef __cplusplus +extern "C" { +#endif + +void sqfs_writer_cfg_init(sqfs_writer_cfg_t *cfg); + +int sqfs_writer_init(sqfs_writer_t *sqfs, const sqfs_writer_cfg_t *wrcfg); + +int sqfs_writer_finish(sqfs_writer_t *sqfs, const sqfs_writer_cfg_t *cfg); + +void sqfs_writer_cleanup(sqfs_writer_t *sqfs, int status); + +/* + High level helper function to serialize an entire file system tree to + a squashfs inode table and directory table. The super block is update + accordingly. + + The function internally creates two meta data writers and uses + meta_writer_write_inode to serialize the inode table of the fstree. + + Returns 0 on success. Prints error messages to stderr on failure. + The filename is used to prefix error messages. + */ +int sqfs_serialize_fstree(const char *filename, sqfs_writer_t *wr); + +#ifdef __cplusplus +} +#endif + +#endif /* SIMPLE_WRITER_H */ |