aboutsummaryrefslogtreecommitdiff
path: root/include/sqfs
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2023-06-05 19:06:42 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2023-06-05 16:01:34 +0200
commitc9a8adc15f9de110771156fdc85fb98533648a53 (patch)
treecdd6300b1c69a002628a76c4bac45ac6664111d9 /include/sqfs
parent57ca46cdd74fd1004a3b0476c136e1f26fcf002d (diff)
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 <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'include/sqfs')
-rw-r--r--include/sqfs/predef.h1
-rw-r--r--include/sqfs/xattr.h87
2 files changed, 88 insertions, 0 deletions
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