From 4ee671b63b18701a29cf9f119e2dc26a055c69c5 Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Sun, 1 Sep 2019 16:28:16 +0200 Subject: API cleanup: Shuffle declarations around Move declarations for stuff that is defined in libsquashfs.so into the public headers and declarations for stuff that isn't, out of there. Also move the meta reader/writer helper functions to their respective headers. Signed-off-by: David Oberhollenzer --- include/highlevel.h | 60 ++++++++++++++++++++++++++----------- include/sqfs/dir.h | 9 ++++++ include/sqfs/inode.h | 10 +++++++ include/sqfs/meta_reader.h | 16 ---------- include/sqfs/meta_writer.h | 41 ------------------------- include/sqfs/table.h | 34 +++++++++++++++++++++ lib/Makemodule.am | 2 ++ lib/sqfs/read_inode.c | 2 +- lib/sqfs/readdir.c | 2 +- lib/sqfshelper/deserialize_fstree.c | 2 ++ lib/sqfshelper/write_dir.c | 3 +- lib/sqfshelper/write_inode.c | 2 +- 12 files changed, 104 insertions(+), 79 deletions(-) create mode 100644 include/sqfs/table.h diff --git a/include/highlevel.h b/include/highlevel.h index bea674e..b9d9339 100644 --- a/include/highlevel.h +++ b/include/highlevel.h @@ -13,12 +13,26 @@ #include "sqfs/id_table.h" #include "sqfs/inode.h" #include "sqfs/data.h" +#include "sqfs/table.h" +#include "sqfs/meta_writer.h" #include "data_reader.h" #include "fstree.h" #include #include +typedef struct { + tree_node_t *node; + uint32_t block; + uint32_t index; +} idx_ref_t; + +typedef struct { + size_t num_nodes; + size_t max_nodes; + idx_ref_t idx_nodes[]; +} dir_index_t; + typedef struct { compressor_t *cmp; data_reader_t *data; @@ -36,24 +50,6 @@ enum RDTREE_FLAGS { RDTREE_READ_XATTR = 0x20, }; -/* - Convenience function for writing meta data to a SquashFS image - - This function internally creates a meta data writer and writes the given - 'data' blob with 'table_size' bytes to disk, neatly partitioned into meta - data blocks. For each meta data block, it remembers the 64 bit start address, - writes out all addresses to an uncompressed list and returns the location - where the address list starts in 'start'. - - Returns 0 on success. Internally prints error messages to stderr. - */ -int sqfs_write_table(int outfd, sqfs_super_t *super, compressor_t *cmp, - const void *data, size_t table_size, uint64_t *start); - -void *sqfs_read_table(int fd, compressor_t *cmp, size_t table_size, - uint64_t location, uint64_t lower_limit, - uint64_t upper_limit); - /* High level helper function to serialize an entire file system tree to a squashfs inode table and directory table. @@ -117,4 +113,32 @@ int sqfs_reader_open(sqfs_reader_t *rd, const char *filename, /* Cleanup after a successfull sqfs_reader_open */ void sqfs_reader_close(sqfs_reader_t *rd); +/* + High level helper function that writes squashfs directory entries to + a meta data writer. + + The dir_info_t structure is used to generate the listing and updated + accordingly (such as writing back the header position and total size). + A directory index is created on the fly and returned in *index. + A single free() call is sufficient. + + Returns 0 on success. Prints error messages to stderr on failure. + */ +int meta_writer_write_dir(meta_writer_t *dm, dir_info_t *dir, + dir_index_t **index); + +/* + High level helper function to serialize a tree_node_t to a squashfs inode + and write it to a meta data writer. + + The inode is written to `im`. If it is a directory node, the directory + contents are written to `dm` using meta_writer_write_dir. The given + id_table_t is used to store the uid and gid on the fly and write the + coresponding indices to the inode structure. + + Returns 0 on success. Prints error messages to stderr on failure. + */ +int meta_writer_write_inode(fstree_t *fs, id_table_t *idtbl, meta_writer_t *im, + meta_writer_t *dm, tree_node_t *node); + #endif /* HIGHLEVEL_H */ diff --git a/include/sqfs/dir.h b/include/sqfs/dir.h index a1ca69c..6e47fef 100644 --- a/include/sqfs/dir.h +++ b/include/sqfs/dir.h @@ -9,6 +9,8 @@ #include "config.h" +#include "sqfs/meta_reader.h" + #include #define SQFS_MAX_DIR_ENT 256 @@ -34,4 +36,11 @@ typedef struct { uint8_t name[]; } sqfs_dir_index_t; +/* Returns 0 on success. Internally prints to stderr on failure */ +int meta_reader_read_dir_header(meta_reader_t *m, sqfs_dir_header_t *hdr); + +/* Entry can be freed with a single free() call. + The function internally prints to stderr on failure */ +sqfs_dir_entry_t *meta_reader_read_dir_ent(meta_reader_t *m); + #endif /* SQFS_DIR_H */ diff --git a/include/sqfs/inode.h b/include/sqfs/inode.h index ac809d3..24889b8 100644 --- a/include/sqfs/inode.h +++ b/include/sqfs/inode.h @@ -9,6 +9,8 @@ #include "config.h" +#include "sqfs/meta_reader.h" + #include typedef enum { @@ -128,4 +130,12 @@ typedef struct { uint8_t extra[]; } sqfs_inode_generic_t; + +/* Inode can be freed with a single free() call. + The function internally prints error message to stderr on failure. */ +sqfs_inode_generic_t *meta_reader_read_inode(meta_reader_t *ir, + sqfs_super_t *super, + uint64_t block_start, + size_t offset); + #endif /* SQFS_INODE_H */ diff --git a/include/sqfs/meta_reader.h b/include/sqfs/meta_reader.h index 0de7401..75071e7 100644 --- a/include/sqfs/meta_reader.h +++ b/include/sqfs/meta_reader.h @@ -10,9 +10,7 @@ #include "config.h" #include "sqfs/compress.h" -#include "sqfs/inode.h" #include "sqfs/data.h" -#include "sqfs/dir.h" typedef struct meta_reader_t meta_reader_t; @@ -37,18 +35,4 @@ void meta_reader_get_position(meta_reader_t *m, uint64_t *block_start, /* Returns 0 on success. Internally prints to stderr on failure */ int meta_reader_read(meta_reader_t *m, void *data, size_t size); -/* Inode can be freed with a single free() call. - The function internally prints error message to stderr on failure. */ -sqfs_inode_generic_t *meta_reader_read_inode(meta_reader_t *ir, - sqfs_super_t *super, - uint64_t block_start, - size_t offset); - -/* Returns 0 on success. Internally prints to stderr on failure */ -int meta_reader_read_dir_header(meta_reader_t *m, sqfs_dir_header_t *hdr); - -/* Entry can be freed with a single free() call. - The function internally prints to stderr on failure */ -sqfs_dir_entry_t *meta_reader_read_dir_ent(meta_reader_t *m); - #endif /* META_READER_H */ diff --git a/include/sqfs/meta_writer.h b/include/sqfs/meta_writer.h index 6c56c93..aeee924 100644 --- a/include/sqfs/meta_writer.h +++ b/include/sqfs/meta_writer.h @@ -12,19 +12,6 @@ #include "sqfs/compress.h" #include "sqfs/id_table.h" #include "sqfs/data.h" -#include "fstree.h" - -typedef struct { - tree_node_t *node; - uint32_t block; - uint32_t index; -} idx_ref_t; - -typedef struct { - size_t num_nodes; - size_t max_nodes; - idx_ref_t idx_nodes[]; -} dir_index_t; typedef struct meta_writer_t meta_writer_t; @@ -56,32 +43,4 @@ void meta_writer_reset(meta_writer_t *m); returns non-zero on failure. */ int meta_write_write_to_file(meta_writer_t *m); -/* - High level helper function that writes squashfs directory entries to - a meta data writer. - - The dir_info_t structure is used to generate the listing and updated - accordingly (such as writing back the header position and total size). - A directory index is created on the fly and returned in *index. - A single free() call is sufficient. - - Returns 0 on success. Prints error messages to stderr on failure. - */ -int meta_writer_write_dir(meta_writer_t *dm, dir_info_t *dir, - dir_index_t **index); - -/* - High level helper function to serialize a tree_node_t to a squashfs inode - and write it to a meta data writer. - - The inode is written to `im`. If it is a directory node, the directory - contents are written to `dm` using meta_writer_write_dir. The given - id_table_t is used to store the uid and gid on the fly and write the - coresponding indices to the inode structure. - - Returns 0 on success. Prints error messages to stderr on failure. - */ -int meta_writer_write_inode(fstree_t *fs, id_table_t *idtbl, meta_writer_t *im, - meta_writer_t *dm, tree_node_t *node); - #endif /* META_WRITER_H */ diff --git a/include/sqfs/table.h b/include/sqfs/table.h new file mode 100644 index 0000000..b1b0c2d --- /dev/null +++ b/include/sqfs/table.h @@ -0,0 +1,34 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * table.h + * + * Copyright (C) 2019 David Oberhollenzer + */ +#ifndef SQFS_TABLE_H +#define SQFS_TABLE_H + +#include "sqfs/compress.h" +#include "sqfs/super.h" + +#include +#include + +/* + Convenience function for writing meta data to a SquashFS image + + This function internally creates a meta data writer and writes the given + 'data' blob with 'table_size' bytes to disk, neatly partitioned into meta + data blocks. For each meta data block, it remembers the 64 bit start address, + writes out all addresses to an uncompressed list and returns the location + where the address list starts in 'start'. + + Returns 0 on success. Internally prints error messages to stderr. + */ +int sqfs_write_table(int outfd, sqfs_super_t *super, compressor_t *cmp, + const void *data, size_t table_size, uint64_t *start); + +void *sqfs_read_table(int fd, compressor_t *cmp, size_t table_size, + uint64_t location, uint64_t lower_limit, + uint64_t upper_limit); + +#endif /* SQFS_TABLE_H */ diff --git a/lib/Makemodule.am b/lib/Makemodule.am index d29c169..bf2e965 100644 --- a/lib/Makemodule.am +++ b/lib/Makemodule.am @@ -47,6 +47,7 @@ libsquashfs_la_SOURCES += include/sqfs/meta_reader.h include/sqfs/id_table.h libsquashfs_la_SOURCES += include/sqfs/compress.h include/sqfs/block_processor.h libsquashfs_la_SOURCES += include/sqfs/super.h include/sqfs/inode.h libsquashfs_la_SOURCES += include/sqfs/dir.h include/sqfs/xattr.h +libsquashfs_la_SOURCES += include/sqfs/table.h libsquashfs_la_SOURCES += lib/sqfs/meta_writer.c lib/sqfs/super.c libsquashfs_la_SOURCES += lib/sqfs/id_table.c libsquashfs_la_SOURCES += lib/sqfs/write_table.c include/highlevel.h @@ -111,6 +112,7 @@ sqfsinclude_HEADERS += include/sqfs/meta_reader.h include/sqfs/id_table.h sqfsinclude_HEADERS += include/sqfs/compress.h include/sqfs/block_processor.h sqfsinclude_HEADERS += include/sqfs/super.h include/sqfs/inode.h sqfsinclude_HEADERS += include/sqfs/dir.h include/sqfs/xattr.h +sqfsinclude_HEADERS += include/sqfs/table.h noinst_LIBRARIES += libfstree.a libtar.a libsqfshelper.a noinst_LTLIBRARIES += libutil.la diff --git a/lib/sqfs/read_inode.c b/lib/sqfs/read_inode.c index 292f38e..10337a7 100644 --- a/lib/sqfs/read_inode.c +++ b/lib/sqfs/read_inode.c @@ -6,7 +6,7 @@ */ #include "config.h" -#include "sqfs/meta_reader.h" +#include "sqfs/inode.h" #include "util.h" #include diff --git a/lib/sqfs/readdir.c b/lib/sqfs/readdir.c index 30c6cf0..31e4c63 100644 --- a/lib/sqfs/readdir.c +++ b/lib/sqfs/readdir.c @@ -6,7 +6,7 @@ */ #include "config.h" -#include "sqfs/meta_reader.h" +#include "sqfs/dir.h" #include #include diff --git a/lib/sqfshelper/deserialize_fstree.c b/lib/sqfshelper/deserialize_fstree.c index 26804db..232c382 100644 --- a/lib/sqfshelper/deserialize_fstree.c +++ b/lib/sqfshelper/deserialize_fstree.c @@ -7,6 +7,8 @@ #include "config.h" #include "sqfs/meta_reader.h" +#include "sqfs/dir.h" + #include "xattr_reader.h" #include "highlevel.h" diff --git a/lib/sqfshelper/write_dir.c b/lib/sqfshelper/write_dir.c index 2b94667..b977bc4 100644 --- a/lib/sqfshelper/write_dir.c +++ b/lib/sqfshelper/write_dir.c @@ -6,11 +6,12 @@ */ #include "config.h" -#include "sqfs/meta_writer.h" #include "sqfs/inode.h" #include "sqfs/dir.h" +#include "highlevel.h" #include "util.h" +#include #include #include #include diff --git a/lib/sqfshelper/write_inode.c b/lib/sqfshelper/write_inode.c index 020eb64..1cd8e72 100644 --- a/lib/sqfshelper/write_inode.c +++ b/lib/sqfshelper/write_inode.c @@ -6,7 +6,7 @@ */ #include "config.h" -#include "sqfs/meta_writer.h" +#include "highlevel.h" #include "sqfs/inode.h" #include "sqfs/dir.h" #include "util.h" -- cgit v1.2.3