From c9a8adc15f9de110771156fdc85fb98533648a53 Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Mon, 5 Jun 2023 19:06:42 +0200 Subject: Move dir_entry_xattr_t from libio to libsquashfs The structure and functions are renamed to sqfs_xattr_* instead, an additional helper is added to accept an encoded xattr. Documentation and unit test are added as well. Signed-off-by: David Oberhollenzer --- include/io/dir_entry.h | 15 -------- include/io/dir_iterator.h | 2 +- include/sqfs/predef.h | 1 + include/sqfs/xattr.h | 87 +++++++++++++++++++++++++++++++++++++++++++++++ include/tar/tar.h | 4 +-- 5 files changed, 91 insertions(+), 18 deletions(-) (limited to 'include') diff --git a/include/io/dir_entry.h b/include/io/dir_entry.h index 7546daf..be5c400 100644 --- a/include/io/dir_entry.h +++ b/include/io/dir_entry.h @@ -84,27 +84,12 @@ typedef struct { char name[]; } dir_entry_t; -typedef struct dir_entry_xattr_t { - struct dir_entry_xattr_t *next; - char *key; - sqfs_u8 *value; - size_t value_len; - char data[]; -} dir_entry_xattr_t; - #ifdef __cplusplus extern "C" { #endif dir_entry_t *dir_entry_create(const char *name); -dir_entry_xattr_t *dir_entry_xattr_create(const char *key, const sqfs_u8 *value, - size_t value_len); - -dir_entry_xattr_t *dir_entry_xattr_list_copy(const dir_entry_xattr_t *list); - -void dir_entry_xattr_list_free(dir_entry_xattr_t *list); - #ifdef __cplusplus } #endif diff --git a/include/io/dir_iterator.h b/include/io/dir_iterator.h index 6ae1cd1..cc64680 100644 --- a/include/io/dir_iterator.h +++ b/include/io/dir_iterator.h @@ -87,7 +87,7 @@ typedef struct dir_iterator_t { * * @return Zero on success, negative @ref SQFS_ERROR value on failure. */ - int (*read_xattr)(struct dir_iterator_t *it, dir_entry_xattr_t **out); + int (*read_xattr)(struct dir_iterator_t *it, sqfs_xattr_t **out); } dir_iterator_t; enum { diff --git a/include/sqfs/predef.h b/include/sqfs/predef.h index 7a7eef8..b0baf92 100644 --- a/include/sqfs/predef.h +++ b/include/sqfs/predef.h @@ -95,6 +95,7 @@ typedef struct sqfs_block_writer_stats_t sqfs_block_writer_stats_t; typedef struct sqfs_block_processor_stats_t sqfs_block_processor_stats_t; typedef struct sqfs_block_processor_desc_t sqfs_block_processor_desc_t; typedef struct sqfs_readdir_state_t sqfs_readdir_state_t; +typedef struct sqfs_xattr_t sqfs_xattr_t; typedef struct sqfs_fragment_t sqfs_fragment_t; typedef struct sqfs_dir_header_t sqfs_dir_header_t; diff --git a/include/sqfs/xattr.h b/include/sqfs/xattr.h index 2bbfb54..2c04ddb 100644 --- a/include/sqfs/xattr.h +++ b/include/sqfs/xattr.h @@ -148,6 +148,36 @@ struct sqfs_xattr_id_table_t { sqfs_u64 locations[]; }; +/** + * @brief sqsf_xattr_t + * + * @brief Represents a decoded xattr key-value pair + * + * On disk, xattr key and value are stored separately with respective headers, + * partially ID-encoded key and special encoding for back references. This + * struct and associated helper functions combine the fully decoded key-value + * pair for convenience. + */ +struct sqfs_xattr_t { + /** + * @brief A pointer for arranging multiple entries in a lined list + */ + sqfs_xattr_t *next; + + const char *key; + const sqfs_u8 *value; + + /** + * @brief The size of the value blob in bytes + */ + size_t value_len; + + /** + * @brief Flexible array member that holds the key & value data + */ + sqfs_u8 data[]; +}; + #ifdef __cplusplus extern "C" { #endif @@ -178,6 +208,63 @@ SQFS_API const char *sqfs_get_xattr_prefix(SQFS_XATTR_TYPE id); */ SQFS_API int sqfs_get_xattr_prefix_id(const char *key); +/** + * @brief Create a combined xattr pair struct from a key string and a value blob + * + * @memberof sqfs_xattr_t + * + * The returned struct can be released with @ref sqfs_xattr_list_free + * + * @param key A pointer to the key string + * @param value A pointer to the value blob + * @param value_len The size of the value blob in bytes + * + * @return A pointer to an sqfs_xattr_t on success, NULL on allocation failure + */ +SQFS_API sqfs_xattr_t *sqfs_xattr_create(const char *key, const sqfs_u8 *value, + size_t value_len); + +/** + * @brief Create an xattr pair struct from a key ID, key string, a value blob + * + * @memberof sqfs_xattr_t + * + * Basically does the same as @ref sqfs_xattr_create, but automatically adds + * a prefix to the key, based on an xattr ID type. The returned struct can be + * released with @ref sqfs_xattr_list_free + * + * @param out Returns a pointer ot an sqfs_xattr_t on success + * @param id An @ref SQFS_XATTR_TYPE enumerator + * @param key A pointer to the key string + * @param value A pointer to the value blob + * @param value_len The size of the value blob in bytes + * + * @return A pointer to , NULL on allocation failure + */ +SQFS_API int sqfs_xattr_create_prefixed(sqfs_xattr_t **out, sqfs_u16 id, + const char *key, const sqfs_u8 *value, + size_t value_len); + +/** + * @brief Create a copy of a linked list of xattr pairs + * + * @memberof sqfs_xattr_t + * + * @param list A pointer to a list of xattr entries + * + * @return A duplicate list on success, NULL on allocation failure + */ +SQFS_API sqfs_xattr_t *sqfs_xattr_list_copy(const sqfs_xattr_t *list); + +/** + * @brief Free a linked list of xattr pairs + * + * @memberof sqfs_xattr_t + * + * @param list A pointer to a list of xattr entries + */ +SQFS_API void sqfs_xattr_list_free(sqfs_xattr_t *list); + #ifdef __cplusplus } #endif diff --git a/include/tar/tar.h b/include/tar/tar.h index f77b27c..24ec408 100644 --- a/include/tar/tar.h +++ b/include/tar/tar.h @@ -31,7 +31,7 @@ typedef struct { sqfs_u64 record_size; bool unknown_record; bool is_hard_link; - dir_entry_xattr_t *xattr; + sqfs_xattr_t *xattr; sqfs_u16 mode; sqfs_u64 uid; @@ -52,7 +52,7 @@ extern "C" { headers need to be generated. */ int write_tar_header(ostream_t *fp, const struct stat *sb, const char *name, - const char *slink_target, const dir_entry_xattr_t *xattr, + const char *slink_target, const sqfs_xattr_t *xattr, unsigned int counter); int write_hard_link(ostream_t *fp, const struct stat *sb, const char *name, -- cgit v1.2.3