From f780c9542d2c96cb0ae00a8de8d67b9a8fd278cd Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Tue, 3 Sep 2019 12:54:15 +0200 Subject: Add fstree independend directory writer to libsquashfs.so This commit adds a directory writer to libsquashfs that wrapps a meta data writer and provides a higher-level interface for writing directory entries. Under the hood it enforces the rules that squashfs insists upon. Signed-off-by: David Oberhollenzer --- include/highlevel.h | 29 ++--------------------------- include/sqfs/dir.h | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 27 deletions(-) (limited to 'include') diff --git a/include/highlevel.h b/include/highlevel.h index ef10c1e..576f686 100644 --- a/include/highlevel.h +++ b/include/highlevel.h @@ -16,24 +16,13 @@ #include "sqfs/table.h" #include "sqfs/meta_writer.h" #include "sqfs/xattr.h" +#include "sqfs/dir.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; @@ -114,20 +103,6 @@ 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. @@ -140,7 +115,7 @@ int meta_writer_write_dir(meta_writer_t *dm, dir_info_t *dir, 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); + sqfs_dir_writer_t *dirw, tree_node_t *node); void compressor_print_available(void); diff --git a/include/sqfs/dir.h b/include/sqfs/dir.h index 5c822f1..818ca87 100644 --- a/include/sqfs/dir.h +++ b/include/sqfs/dir.h @@ -10,6 +10,7 @@ #include "config.h" #include "sqfs/meta_reader.h" +#include "sqfs/meta_writer.h" #include @@ -36,6 +37,8 @@ typedef struct { uint8_t name[]; } sqfs_dir_index_t; +typedef struct sqfs_dir_writer_t sqfs_dir_writer_t; + #ifdef __cplusplus extern "C" { #endif @@ -47,6 +50,27 @@ int meta_reader_read_dir_header(meta_reader_t *m, sqfs_dir_header_t *hdr); The function internally prints to stderr on failure */ sqfs_dir_entry_t *meta_reader_read_dir_ent(meta_reader_t *m); +sqfs_dir_writer_t *sqfs_dir_writer_create(meta_writer_t *dm); + +void sqfs_dir_writer_destroy(sqfs_dir_writer_t *writer); + +int sqfs_dir_writer_begin(sqfs_dir_writer_t *writer); + +int sqfs_dir_writer_add_entry(sqfs_dir_writer_t *writer, const char *name, + uint32_t inode_num, uint64_t inode_ref, + mode_t mode); + +int sqfs_dir_writer_end(sqfs_dir_writer_t *writer); + +size_t sqfs_dir_writer_get_size(sqfs_dir_writer_t *writer); + +uint64_t sqfs_dir_writer_get_dir_reference(sqfs_dir_writer_t *writer); + +size_t sqfs_dir_writer_get_index_size(sqfs_dir_writer_t *writer); + +int sqfs_dir_writer_write_index(sqfs_dir_writer_t *writer, + meta_writer_t *im); + #ifdef __cplusplus } #endif -- cgit v1.2.3