aboutsummaryrefslogtreecommitdiff
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
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>
-rw-r--r--bin/sqfs2tar/src/sqfs2tar.h2
-rw-r--r--bin/sqfs2tar/src/write_tree.c4
-rw-r--r--bin/sqfs2tar/src/xattr.c16
-rw-r--r--bin/tar2sqfs/src/process_tarball.c6
-rw-r--r--include/io/dir_entry.h15
-rw-r--r--include/io/dir_iterator.h2
-rw-r--r--include/sqfs/predef.h1
-rw-r--r--include/sqfs/xattr.h87
-rw-r--r--include/tar/tar.h4
-rw-r--r--lib/io/src/dir_entry.c68
-rw-r--r--lib/io/src/dir_tree_iterator.c2
-rw-r--r--lib/io/src/unix/dir_iterator.c2
-rw-r--r--lib/io/src/win32/dir_iterator.c2
-rw-r--r--lib/sqfs/Makemodule.am5
-rw-r--r--lib/sqfs/src/xattr/xattr.c96
-rw-r--r--lib/sqfs/test/xattr.c111
-rw-r--r--lib/tar/Makemodule.am78
-rw-r--r--lib/tar/src/cleanup.c3
-rw-r--r--lib/tar/src/iterator.c5
-rw-r--r--lib/tar/src/pax_header.c26
-rw-r--r--lib/tar/src/write_header.c10
-rw-r--r--lib/tar/test/tar_write_simple.c17
-rw-r--r--lib/tar/test/tar_xattr.c1
-rw-r--r--lib/tar/test/tar_xattr_bin.c1
24 files changed, 397 insertions, 167 deletions
diff --git a/bin/sqfs2tar/src/sqfs2tar.h b/bin/sqfs2tar/src/sqfs2tar.h
index 88185ee..3c7b3d1 100644
--- a/bin/sqfs2tar/src/sqfs2tar.h
+++ b/bin/sqfs2tar/src/sqfs2tar.h
@@ -48,7 +48,7 @@ char *assemble_tar_path(char *name, bool is_dir);
/* xattr.c */
int get_xattrs(const char *name, const sqfs_inode_generic_t *inode,
- dir_entry_xattr_t **out);
+ sqfs_xattr_t **out);
/* write_tree.c */
int write_tree(const sqfs_tree_node_t *n);
diff --git a/bin/sqfs2tar/src/write_tree.c b/bin/sqfs2tar/src/write_tree.c
index 150bac1..71eb249 100644
--- a/bin/sqfs2tar/src/write_tree.c
+++ b/bin/sqfs2tar/src/write_tree.c
@@ -68,7 +68,7 @@ static void inode_stat(const sqfs_tree_node_t *node, struct stat *sb)
static int write_tree_dfs(const sqfs_tree_node_t *n)
{
sqfs_hard_link_t *lnk = NULL;
- dir_entry_xattr_t *xattr = NULL;
+ sqfs_xattr_t *xattr = NULL;
char *name, *target;
struct stat sb;
size_t len;
@@ -134,7 +134,7 @@ static int write_tree_dfs(const sqfs_tree_node_t *n)
target = S_ISLNK(sb.st_mode) ? (char *)n->inode->extra : NULL;
ret = write_tar_header(out_file, &sb, name, target, xattr,
record_counter++);
- dir_entry_xattr_list_free(xattr);
+ sqfs_xattr_list_free(xattr);
if (ret > 0)
goto out_skip;
diff --git a/bin/sqfs2tar/src/xattr.c b/bin/sqfs2tar/src/xattr.c
index 8d21cd8..2af856d 100644
--- a/bin/sqfs2tar/src/xattr.c
+++ b/bin/sqfs2tar/src/xattr.c
@@ -6,13 +6,13 @@
*/
#include "sqfs2tar.h"
-static dir_entry_xattr_t *mkxattr(const sqfs_xattr_entry_t *key,
- const sqfs_xattr_value_t *value)
+static sqfs_xattr_t *mkxattr(const sqfs_xattr_entry_t *key,
+ const sqfs_xattr_value_t *value)
{
- dir_entry_xattr_t *ent;
+ sqfs_xattr_t *ent;
- ent = dir_entry_xattr_create((const char *)key->key,
- value->value, value->size);
+ ent = sqfs_xattr_create((const char *)key->key,
+ value->value, value->size);
if (ent == NULL) {
perror("creating xattr entry");
return NULL;
@@ -22,9 +22,9 @@ static dir_entry_xattr_t *mkxattr(const sqfs_xattr_entry_t *key,
}
int get_xattrs(const char *name, const sqfs_inode_generic_t *inode,
- dir_entry_xattr_t **out)
+ sqfs_xattr_t **out)
{
- dir_entry_xattr_t *list = NULL, *ent;
+ sqfs_xattr_t *list = NULL, *ent;
sqfs_xattr_value_t *value;
sqfs_xattr_entry_t *key;
sqfs_xattr_id_t desc;
@@ -79,6 +79,6 @@ int get_xattrs(const char *name, const sqfs_inode_generic_t *inode,
*out = list;
return 0;
fail:
- dir_entry_xattr_list_free(list);
+ sqfs_xattr_list_free(list);
return -1;
}
diff --git a/bin/tar2sqfs/src/process_tarball.c b/bin/tar2sqfs/src/process_tarball.c
index 76c7dc1..5b0cbdd 100644
--- a/bin/tar2sqfs/src/process_tarball.c
+++ b/bin/tar2sqfs/src/process_tarball.c
@@ -40,7 +40,7 @@ static int write_file(sqfs_writer_t *sqfs, dir_iterator_t *it,
static int copy_xattr(sqfs_writer_t *sqfs, const char *filename,
tree_node_t *node, dir_iterator_t *it)
{
- dir_entry_xattr_t *xattr, *list;
+ sqfs_xattr_t *xattr, *list;
int ret;
ret = it->read_xattr(it, &list);
@@ -82,10 +82,10 @@ static int copy_xattr(sqfs_writer_t *sqfs, const char *filename,
goto fail;
}
- dir_entry_xattr_list_free(list);
+ sqfs_xattr_list_free(list);
return 0;
fail:
- dir_entry_xattr_list_free(list);
+ sqfs_xattr_list_free(list);
return -1;
}
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,
diff --git a/lib/io/src/dir_entry.c b/lib/io/src/dir_entry.c
index b7f38f5..15f078f 100644
--- a/lib/io/src/dir_entry.c
+++ b/lib/io/src/dir_entry.c
@@ -28,71 +28,3 @@ dir_entry_t *dir_entry_create(const char *name)
memcpy(out->name, name, name_len);
return out;
}
-
-dir_entry_xattr_t *dir_entry_xattr_create(const char *key, const sqfs_u8 *value,
- size_t value_len)
-{
- dir_entry_xattr_t *out;
- size_t len, key_len;
-
- /* key_ley = strlen(key) + 1 */
- key_len = strlen(key);
- if (SZ_ADD_OV(key_len, 1, &key_len))
- return NULL;
-
- /* len = key_len + value_len + 1 + sizeof(*out) */
- if (SZ_ADD_OV(key_len, value_len, &len))
- return NULL;
- if (SZ_ADD_OV(len, 1, &len))
- return NULL;
- if (SZ_ADD_OV(len, sizeof(*out), &len))
- return NULL;
-
- out = calloc(1, len);
- if (out != NULL) {
- out->key = out->data;
- out->value = (sqfs_u8 *)out->data + key_len;
- out->value_len = value_len;
-
- memcpy(out->key, key, key_len);
- memcpy(out->value, value, value_len);
- }
-
- return out;
-}
-
-dir_entry_xattr_t *dir_entry_xattr_list_copy(const dir_entry_xattr_t *list)
-{
- dir_entry_xattr_t *new, *copy = NULL, *copy_last = NULL;
- const dir_entry_xattr_t *it;
-
- for (it = list; it != NULL; it = it->next) {
- new = dir_entry_xattr_create(it->key, it->value,
- it->value_len);
- if (new == NULL) {
- dir_entry_xattr_list_free(copy);
- return NULL;
- }
-
- if (copy_last == NULL) {
- copy = new;
- copy_last = new;
- } else {
- copy_last->next = new;
- copy_last = new;
- }
- }
-
- return copy;
-}
-
-void dir_entry_xattr_list_free(dir_entry_xattr_t *list)
-{
- dir_entry_xattr_t *old;
-
- while (list != NULL) {
- old = list;
- list = list->next;
- free(old);
- }
-}
diff --git a/lib/io/src/dir_tree_iterator.c b/lib/io/src/dir_tree_iterator.c
index 0174d73..25cb1d9 100644
--- a/lib/io/src/dir_tree_iterator.c
+++ b/lib/io/src/dir_tree_iterator.c
@@ -284,7 +284,7 @@ static int open_file_ro(dir_iterator_t *base, istream_t **out)
return it->top->dir->open_file_ro(it->top->dir, out);
}
-static int read_xattr(dir_iterator_t *base, dir_entry_xattr_t **out)
+static int read_xattr(dir_iterator_t *base, sqfs_xattr_t **out)
{
dir_tree_iterator_t *it = (dir_tree_iterator_t *)base;
diff --git a/lib/io/src/unix/dir_iterator.c b/lib/io/src/unix/dir_iterator.c
index afbf0c0..9ba200f 100644
--- a/lib/io/src/unix/dir_iterator.c
+++ b/lib/io/src/unix/dir_iterator.c
@@ -134,7 +134,7 @@ static int dir_open_file_ro(dir_iterator_t *it, istream_t **out)
return SQFS_ERROR_UNSUPPORTED;
}
-static int dir_read_xattr(dir_iterator_t *it, dir_entry_xattr_t **out)
+static int dir_read_xattr(dir_iterator_t *it, sqfs_xattr_t **out)
{
(void)it;
*out = NULL;
diff --git a/lib/io/src/win32/dir_iterator.c b/lib/io/src/win32/dir_iterator.c
index f504b65..b1045f1 100644
--- a/lib/io/src/win32/dir_iterator.c
+++ b/lib/io/src/win32/dir_iterator.c
@@ -122,7 +122,7 @@ static int dir_iterator_open_file_ro(dir_iterator_t *it, istream_t **out)
return SQFS_ERROR_UNSUPPORTED;
}
-static int dir_iterator_read_xattr(dir_iterator_t *it, dir_entry_xattr_t **out)
+static int dir_iterator_read_xattr(dir_iterator_t *it, sqfs_xattr_t **out)
{
(void)it;
*out = NULL;
diff --git a/lib/sqfs/Makemodule.am b/lib/sqfs/Makemodule.am
index 3500aad..d54134c 100644
--- a/lib/sqfs/Makemodule.am
+++ b/lib/sqfs/Makemodule.am
@@ -107,6 +107,9 @@ pkgconfig_DATA += lib/sqfs/libsquashfs1.pc
test_abi_SOURCES = lib/sqfs/test/abi.c
test_abi_LDADD = libsquashfs.la libcompat.a
+test_xattr_SOURCES = lib/sqfs/test/xattr.c
+test_xattr_LDADD = libsquashfs.la libcompat.a
+
test_table_SOURCES = lib/sqfs/test/table.c
test_table_LDADD = libsquashfs.la libcompat.a
@@ -120,7 +123,7 @@ test_get_node_path_SOURCES = lib/sqfs/test/get_node_path.c
test_get_node_path_LDADD = libcommon.a libsquashfs.la libcompat.a
LIBSQFS_TESTS = \
- test_abi test_table test_xattr_writer test_get_node_path
+ test_abi test_xattr test_table test_xattr_writer test_get_node_path
noinst_PROGRAMS += xattr_benchmark
diff --git a/lib/sqfs/src/xattr/xattr.c b/lib/sqfs/src/xattr/xattr.c
index 29ecebf..9dc284d 100644
--- a/lib/sqfs/src/xattr/xattr.c
+++ b/lib/sqfs/src/xattr/xattr.c
@@ -8,8 +8,10 @@
#include "config.h"
#include "sqfs/xattr.h"
#include "sqfs/error.h"
+#include "compat.h"
#include <string.h>
+#include <stdlib.h>
static const struct {
const char *prefix;
@@ -47,3 +49,97 @@ const char *sqfs_get_xattr_prefix(SQFS_XATTR_TYPE id)
return NULL;
}
+
+static sqfs_xattr_t *mkxattr(const char *prefix, const char *key,
+ const sqfs_u8 *value, size_t value_len)
+{
+ size_t pfx_len = (prefix == NULL) ? 0 : strlen(prefix);
+ size_t key_len = strlen(key);
+ sqfs_xattr_t *out;
+ size_t len;
+
+ /* len = pfx_len + (key_len + 1) + (value_len + 1) + sizeof(*out) */
+ if (SZ_ADD_OV(pfx_len, key_len, &len))
+ return NULL;
+ if (SZ_ADD_OV(len, value_len, &len))
+ return NULL;
+ if (SZ_ADD_OV(len, 2, &len))
+ return NULL;
+ if (SZ_ADD_OV(len, sizeof(*out), &len))
+ return NULL;
+
+ out = calloc(1, len);
+
+ if (out != NULL) {
+ size_t value_offset = pfx_len + key_len + 1;
+
+ out->key = (const char *)out->data;
+ out->value = out->data + value_offset;
+ out->value_len = value_len;
+
+ if (prefix != NULL)
+ memcpy(out->data, prefix, pfx_len);
+
+ memcpy(out->data + pfx_len, key, key_len);
+ memcpy(out->data + value_offset, value, value_len);
+ }
+
+ return out;
+}
+
+sqfs_xattr_t *sqfs_xattr_create(const char *key, const sqfs_u8 *value,
+ size_t value_len)
+{
+ return mkxattr(NULL, key, value, value_len);
+}
+
+int sqfs_xattr_create_prefixed(sqfs_xattr_t **out, sqfs_u16 id,
+ const char *key, const sqfs_u8 *value,
+ size_t value_len)
+{
+ const char *prefix = sqfs_get_xattr_prefix(id & (~SQFS_XATTR_FLAG_OOL));
+
+ if (prefix == NULL) {
+ *out = NULL;
+ return SQFS_ERROR_UNSUPPORTED;
+ }
+
+ *out = mkxattr(prefix, key, value, value_len);
+ if (*out == NULL)
+ return SQFS_ERROR_ALLOC;
+
+ return 0;
+}
+
+sqfs_xattr_t *sqfs_xattr_list_copy(const sqfs_xattr_t *list)
+{
+ sqfs_xattr_t *copy = NULL, *copy_last = NULL;
+
+ for (const sqfs_xattr_t *it = list; it != NULL; it = it->next) {
+ sqfs_xattr_t *new = mkxattr(NULL, it->key,
+ it->value, it->value_len);
+ if (new == NULL) {
+ sqfs_xattr_list_free(copy);
+ return NULL;
+ }
+
+ if (copy_last == NULL) {
+ copy = new;
+ } else {
+ copy_last->next = new;
+ }
+
+ copy_last = new;
+ }
+
+ return copy;
+}
+
+void sqfs_xattr_list_free(sqfs_xattr_t *list)
+{
+ while (list != NULL) {
+ sqfs_xattr_t *old = list;
+ list = list->next;
+ free(old);
+ }
+}
diff --git a/lib/sqfs/test/xattr.c b/lib/sqfs/test/xattr.c
new file mode 100644
index 0000000..a5222f4
--- /dev/null
+++ b/lib/sqfs/test/xattr.c
@@ -0,0 +1,111 @@
+/* SPDX-License-Identifier: GPL-3.0-or-later */
+/*
+ * xattr.c
+ *
+ * Copyright (C) 2023 David Oberhollenzer <goliath@infraroot.at>
+ */
+#include "config.h"
+#include "compat.h"
+#include "util/test.h"
+
+#include "sqfs/xattr.h"
+#include "sqfs/error.h"
+
+int main(int argc, char **argv)
+{
+ sqfs_xattr_t *ent, *ent2, *list;
+ const char *str;
+ int id, ret;
+ (void)argc; (void)argv;
+
+ /* prefix API */
+ id = sqfs_get_xattr_prefix_id("user.mime_type");
+ TEST_EQUAL_I(id, SQFS_XATTR_USER);
+
+ str = sqfs_get_xattr_prefix(id);
+ TEST_STR_EQUAL(str, "user.");
+
+ id = sqfs_get_xattr_prefix_id("security.selinux");
+ TEST_EQUAL_I(id, SQFS_XATTR_SECURITY);
+
+ str = sqfs_get_xattr_prefix(id);
+ TEST_STR_EQUAL(str, "security.");
+
+ id = sqfs_get_xattr_prefix_id("trusted.bla");
+ TEST_EQUAL_I(id, SQFS_XATTR_TRUSTED);
+
+ str = sqfs_get_xattr_prefix(id);
+ TEST_STR_EQUAL(str, "trusted.");
+
+ id = sqfs_get_xattr_prefix_id("system.acl");
+ TEST_EQUAL_I(id, SQFS_ERROR_UNSUPPORTED);
+
+ str = sqfs_get_xattr_prefix(id);
+ TEST_NULL(str);
+
+ /* combined entry API */
+ ent = sqfs_xattr_create("foo.bar", (const sqfs_u8 *)"Hello, World!", 5);
+ TEST_NOT_NULL(ent);
+ TEST_EQUAL_UI(ent->value_len, 5);
+ TEST_STR_EQUAL(ent->key, "foo.bar");
+ TEST_STR_EQUAL((const char *)ent->value, "Hello");
+ sqfs_xattr_list_free(ent);
+
+ /* with prefix */
+ ret = sqfs_xattr_create_prefixed(&ent, SQFS_XATTR_SECURITY, "selinux",
+ (const sqfs_u8 *)"Hello, World!", 5);
+ TEST_EQUAL_I(ret, 0);
+ TEST_NOT_NULL(ent);
+ TEST_EQUAL_UI(ent->value_len, 5);
+ TEST_STR_EQUAL(ent->key, "security.selinux");
+ TEST_STR_EQUAL((const char *)ent->value, "Hello");
+ sqfs_xattr_list_free(ent);
+
+ ret = sqfs_xattr_create_prefixed(&ent, 42, "selinux",
+ (const sqfs_u8 *)"Hello, World!", 5);
+ TEST_EQUAL_I(ret, SQFS_ERROR_UNSUPPORTED);
+ TEST_NULL(ent);
+
+ /* list copy */
+ ent = sqfs_xattr_create("foo.bar", (const sqfs_u8 *)"Hello, World!", 5);
+ TEST_NOT_NULL(ent);
+
+ ent2 = sqfs_xattr_create("bla.blu", (const sqfs_u8 *)"test", 4);
+ TEST_NOT_NULL(ent2);
+
+ list = sqfs_xattr_list_copy(NULL);
+ TEST_NULL(list);
+
+ list = sqfs_xattr_list_copy(ent);
+ TEST_NOT_NULL(list);
+ TEST_ASSERT(list != ent);
+ TEST_STR_EQUAL(list->key, ent->key);
+ TEST_STR_EQUAL((const char *)list->value, (const char *)ent->value);
+ TEST_EQUAL_UI(list->value_len, ent->value_len);
+ sqfs_xattr_list_free(list);
+
+ ent->next = ent2;
+ ent2->next = NULL;
+
+ list = sqfs_xattr_list_copy(ent);
+ TEST_NOT_NULL(list);
+ TEST_ASSERT(list != ent && list != ent2);
+ TEST_STR_EQUAL(list->key, ent->key);
+ TEST_STR_EQUAL((const char *)list->value, (const char *)ent->value);
+ TEST_EQUAL_UI(list->value_len, ent->value_len);
+
+ TEST_NOT_NULL(list->next);
+ TEST_ASSERT(list->next != ent && list->next != ent2);
+ TEST_STR_EQUAL(list->next->key, ent2->key);
+ TEST_STR_EQUAL((const char *)list->next->value,
+ (const char *)ent2->value);
+ TEST_EQUAL_UI(list->next->value_len, ent2->value_len);
+ sqfs_xattr_list_free(list);
+
+ ent->next = NULL;
+ ent2->next = NULL;
+ sqfs_xattr_list_free(ent);
+ sqfs_xattr_list_free(ent2);
+
+ return EXIT_SUCCESS;
+}
diff --git a/lib/tar/Makemodule.am b/lib/tar/Makemodule.am
index 7e58cc6..9061571 100644
--- a/lib/tar/Makemodule.am
+++ b/lib/tar/Makemodule.am
@@ -11,177 +11,187 @@ noinst_LIBRARIES += libtar.a
TARDATADIR=$(top_srcdir)/lib/tar/test/data
test_tar_gnu0_SOURCES = lib/tar/test/tar_simple.c
-test_tar_gnu0_LDADD = libtar.a libio.a libutil.a libcompat.a
+test_tar_gnu0_LDADD = libtar.a libsquashfs.la libio.a libutil.a libcompat.a
test_tar_gnu0_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR)
test_tar_gnu0_CPPFLAGS += -DTESTFILE=format-acceptance/gnu.tar
test_tar_gnu1_SOURCES = lib/tar/test/tar_simple.c
-test_tar_gnu1_LDADD = libtar.a libio.a libutil.a libcompat.a
+test_tar_gnu1_LDADD = libtar.a libsquashfs.la libio.a libutil.a libcompat.a
test_tar_gnu1_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR)
test_tar_gnu1_CPPFLAGS += -DTESTFILE=format-acceptance/gnu-g.tar
test_tar_gnu2_SOURCES = lib/tar/test/tar_simple.c
-test_tar_gnu2_LDADD = libtar.a libio.a libutil.a libcompat.a
+test_tar_gnu2_LDADD = libtar.a libsquashfs.la libio.a libutil.a libcompat.a
test_tar_gnu2_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR)
test_tar_gnu2_CPPFLAGS += -DTESTFILE=user-group-largenum/gnu.tar
test_tar_gnu2_CPPFLAGS += -DTESTUID=0x80000000 -DTESTGID=0x80000000
test_tar_gnu2_CPPFLAGS += -DTESTTS=1542995392
test_tar_gnu3_SOURCES = lib/tar/test/tar_simple.c
-test_tar_gnu3_LDADD = libtar.a libio.a libutil.a libcompat.a
+test_tar_gnu3_LDADD = libtar.a libsquashfs.la libio.a libutil.a libcompat.a
test_tar_gnu3_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR)
test_tar_gnu3_CPPFLAGS += -DTESTFILE=negative-mtime/gnu.tar -DTESTTS=-315622800
test_tar_gnu4_SOURCES = lib/tar/test/tar_simple.c
-test_tar_gnu4_LDADD = libtar.a libio.a libutil.a libcompat.a
+test_tar_gnu4_LDADD = libtar.a libsquashfs.la libio.a libutil.a libcompat.a
test_tar_gnu4_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR)
test_tar_gnu4_CPPFLAGS += -DTESTFILE=long-paths/gnu.tar -DLONG_NAME_TEST
test_tar_gnu4_CPPFLAGS += -DTESTTS=1542909670
test_tar_gnu5_SOURCES = lib/tar/test/tar_simple.c
-test_tar_gnu5_LDADD = libtar.a libio.a libutil.a libcompat.a
+test_tar_gnu5_LDADD = libtar.a libsquashfs.la libio.a libutil.a libcompat.a
test_tar_gnu5_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR)
test_tar_gnu5_CPPFLAGS += -DTESTFILE=large-mtime/gnu.tar -DTESTTS=8589934592L
test_tar_gnu6_SOURCES = lib/tar/test/tar_big_file.c
-test_tar_gnu6_LDADD = libtar.a libio.a libutil.a libcompat.a
+test_tar_gnu6_LDADD = libtar.a libsquashfs.la libio.a libutil.a libcompat.a
test_tar_gnu6_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR)
test_tar_gnu6_CPPFLAGS += -DTESTFILE=file-size/gnu.tar
test_tar_pax0_SOURCES = lib/tar/test/tar_simple.c
-test_tar_pax0_LDADD = libtar.a libio.a libutil.a libcompat.a
+test_tar_pax0_LDADD = libtar.a libsquashfs.la libio.a libutil.a libcompat.a
test_tar_pax0_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR)
test_tar_pax0_CPPFLAGS += -DTESTFILE=format-acceptance/pax.tar
test_tar_pax1_SOURCES = lib/tar/test/tar_simple.c
-test_tar_pax1_LDADD = libtar.a libio.a libutil.a libcompat.a
+test_tar_pax1_LDADD = libtar.a libsquashfs.la libio.a libutil.a libcompat.a
test_tar_pax1_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR)
test_tar_pax1_CPPFLAGS += -DTESTFILE=user-group-largenum/pax.tar
test_tar_pax1_CPPFLAGS += -DTESTUID=2147483648UL -DTESTGID=2147483648UL
test_tar_pax1_CPPFLAGS += -DTESTTS=1542995392
test_tar_pax2_SOURCES = lib/tar/test/tar_simple.c
-test_tar_pax2_LDADD = libtar.a libio.a libutil.a libcompat.a
+test_tar_pax2_LDADD = libtar.a libsquashfs.la libio.a libutil.a libcompat.a
test_tar_pax2_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR)
test_tar_pax2_CPPFLAGS += -DTESTFILE=large-mtime/pax.tar -DTESTTS=8589934592L
test_tar_pax3_SOURCES = lib/tar/test/tar_simple.c
-test_tar_pax3_LDADD = libtar.a libio.a libutil.a libcompat.a
+test_tar_pax3_LDADD = libtar.a libsquashfs.la libio.a libutil.a libcompat.a
test_tar_pax3_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR)
test_tar_pax3_CPPFLAGS += -DTESTFILE=negative-mtime/pax.tar -DTESTTS=-315622800
test_tar_pax4_SOURCES = lib/tar/test/tar_simple.c
-test_tar_pax4_LDADD = libtar.a libio.a libutil.a libcompat.a
+test_tar_pax4_LDADD = libtar.a libsquashfs.la libio.a libutil.a libcompat.a
test_tar_pax4_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR)
test_tar_pax4_CPPFLAGS += -DTESTFILE=long-paths/pax.tar
test_tar_pax4_CPPFLAGS += -DLONG_NAME_TEST -DTESTTS=1542909670
test_tar_pax5_SOURCES = lib/tar/test/tar_big_file.c
-test_tar_pax5_LDADD = libtar.a libio.a libutil.a libcompat.a
+test_tar_pax5_LDADD = libtar.a libsquashfs.la libio.a libutil.a libcompat.a
test_tar_pax5_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR)
test_tar_pax5_CPPFLAGS += -DTESTFILE=file-size/pax.tar
test_tar_ustar0_SOURCES = lib/tar/test/tar_simple.c
-test_tar_ustar0_LDADD = libtar.a libio.a libutil.a libcompat.a
+test_tar_ustar0_LDADD = libtar.a libsquashfs.la libio.a libutil.a libcompat.a
test_tar_ustar0_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR)
test_tar_ustar0_CPPFLAGS += -DTESTFILE=format-acceptance/ustar.tar
test_tar_ustar1_SOURCES = lib/tar/test/tar_simple.c
-test_tar_ustar1_LDADD = libtar.a libio.a libutil.a libcompat.a
+test_tar_ustar1_LDADD = libtar.a libsquashfs.la libio.a libutil.a libcompat.a
test_tar_ustar1_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR)
test_tar_ustar1_CPPFLAGS += -DTESTFILE=format-acceptance/ustar-pre-posix.tar
test_tar_ustar2_SOURCES = lib/tar/test/tar_simple.c
-test_tar_ustar2_LDADD = libtar.a libio.a libutil.a libcompat.a
+test_tar_ustar2_LDADD = libtar.a libsquashfs.la libio.a libutil.a libcompat.a
test_tar_ustar2_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR)
test_tar_ustar2_CPPFLAGS += -DTESTFILE=format-acceptance/v7.tar
test_tar_ustar3_SOURCES = lib/tar/test/tar_simple.c
-test_tar_ustar3_LDADD = libtar.a libio.a libutil.a libcompat.a
+test_tar_ustar3_LDADD = libtar.a libsquashfs.la libio.a libutil.a libcompat.a
test_tar_ustar3_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR)
test_tar_ustar3_CPPFLAGS += -DTESTFILE=user-group-largenum/8-digit.tar
test_tar_ustar3_CPPFLAGS += -DTESTUID=8388608 -DTESTGID=8388608
test_tar_ustar3_CPPFLAGS += -DTESTTS=1542995392
test_tar_ustar4_SOURCES = lib/tar/test/tar_simple.c
-test_tar_ustar4_LDADD = libtar.a libio.a libutil.a libcompat.a
+test_tar_ustar4_LDADD = libtar.a libsquashfs.la libio.a libutil.a libcompat.a
test_tar_ustar4_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR)
test_tar_ustar4_CPPFLAGS += -DTESTFILE=large-mtime/12-digit.tar
test_tar_ustar4_CPPFLAGS += -DTESTTS=8589934592L
test_tar_ustar5_SOURCES = lib/tar/test/tar_simple.c
-test_tar_ustar5_LDADD = libtar.a libio.a libutil.a libcompat.a
+test_tar_ustar5_LDADD = libtar.a libsquashfs.la libio.a libutil.a libcompat.a
test_tar_ustar5_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR)
test_tar_ustar5_CPPFLAGS += -DTESTFILE=long-paths/ustar.tar
test_tar_ustar5_CPPFLAGS += -DLONG_NAME_TEST -DTESTTS=1542909670
test_tar_ustar6_SOURCES = lib/tar/test/tar_big_file.c
-test_tar_ustar6_LDADD = libtar.a libio.a libutil.a libcompat.a
+test_tar_ustar6_LDADD = libtar.a libsquashfs.la libio.a libutil.a libcompat.a
test_tar_ustar6_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR)
test_tar_ustar6_CPPFLAGS += -DTESTFILE=file-size/12-digit.tar
test_tar_target_filled_SOURCES = lib/tar/test/tar_target_filled.c
-test_tar_target_filled_LDADD = libtar.a libio.a libutil.a libcompat.a
+test_tar_target_filled_LDADD = libtar.a libsquashfs.la libio.a libutil.a \
+ libcompat.a
test_tar_target_filled_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR)
test_tar_sparse_gnu_SOURCES = lib/tar/test/tar_sparse_gnu.c
-test_tar_sparse_gnu_LDADD = libtar.a libio.a libutil.a libcompat.a
+test_tar_sparse_gnu_LDADD = libtar.a libsquashfs.la libio.a libutil.a \
+ libcompat.a
test_tar_sparse_gnu_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR)
test_tar_sparse_gnu0_SOURCES = lib/tar/test/tar_sparse.c
-test_tar_sparse_gnu0_LDADD = libtar.a libio.a libutil.a libcompat.a
+test_tar_sparse_gnu0_LDADD = libtar.a libsquashfs.la libio.a libutil.a \
+ libcompat.a
test_tar_sparse_gnu0_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR)
test_tar_sparse_gnu0_CPPFLAGS += -DTESTFILE=sparse-files/pax-gnu0-0.tar
test_tar_sparse_gnu1_SOURCES = lib/tar/test/tar_sparse.c
-test_tar_sparse_gnu1_LDADD = libtar.a libio.a libutil.a libcompat.a
+test_tar_sparse_gnu1_LDADD = libtar.a libsquashfs.la libio.a libutil.a \
+ libcompat.a
test_tar_sparse_gnu1_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR)
test_tar_sparse_gnu1_CPPFLAGS += -DTESTFILE=sparse-files/pax-gnu0-1.tar
test_tar_sparse_gnu2_SOURCES = lib/tar/test/tar_sparse.c
-test_tar_sparse_gnu2_LDADD = libtar.a libio.a libutil.a libcompat.a
+test_tar_sparse_gnu2_LDADD = libtar.a libsquashfs.la libio.a libutil.a \
+ libcompat.a
test_tar_sparse_gnu2_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR)
test_tar_sparse_gnu2_CPPFLAGS += -DTESTFILE=sparse-files/pax-gnu1-0.tar
test_tar_sparse_gnu3_SOURCES = lib/tar/test/tar_sparse.c
-test_tar_sparse_gnu3_LDADD = libtar.a libio.a libutil.a libcompat.a
+test_tar_sparse_gnu3_LDADD = libtar.a libsquashfs.la libio.a libutil.a \
+ libcompat.a
test_tar_sparse_gnu3_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR)
test_tar_sparse_gnu3_CPPFLAGS += -DTESTFILE=sparse-files/gnu.tar
test_tar_xattr_bsd_SOURCES = lib/tar/test/tar_xattr.c
-test_tar_xattr_bsd_LDADD = libtar.a libio.a libutil.a libcompat.a
+test_tar_xattr_bsd_LDADD = libtar.a libsquashfs.la libio.a libutil.a \
+ libcompat.a
test_tar_xattr_bsd_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR)
test_tar_xattr_bsd_CPPFLAGS += -DTESTFILE=xattr/xattr-libarchive.tar
test_tar_xattr_schily_SOURCES = lib/tar/test/tar_xattr.c
-test_tar_xattr_schily_LDADD = libtar.a libio.a libutil.a libcompat.a
+test_tar_xattr_schily_LDADD = libtar.a libsquashfs.la libio.a libutil.a \
+ libcompat.a
test_tar_xattr_schily_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR)
test_tar_xattr_schily_CPPFLAGS += -DTESTFILE=xattr/xattr-schily.tar
test_tar_xattr_schily_bin_SOURCES = lib/tar/test/tar_xattr_bin.c
-test_tar_xattr_schily_bin_LDADD = libtar.a libio.a libutil.a libcompat.a
+test_tar_xattr_schily_bin_LDADD = libtar.a libsquashfs.la libio.a libutil.a \
+ libcompat.a
test_tar_xattr_schily_bin_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR)
test_tar_xattr_schily_bin_CPPFLAGS += -DTESTFILE=xattr/xattr-schily-binary.tar
test_tar_iterator_SOURCES = lib/tar/test/tar_iterator.c
-test_tar_iterator_LDADD = libtar.a libio.a libutil.a libcompat.a
+test_tar_iterator_LDADD = libtar.a libsquashfs.la libio.a libutil.a libcompat.a
test_tar_iterator_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR)
test_tar_iterator_CPPFLAGS += -DTESTFILE=format-acceptance/gnu.tar
test_tar_iterator2_SOURCES = lib/tar/test/tar_iterator2.c
-test_tar_iterator2_LDADD = libtar.a libio.a libutil.a libcompat.a
+test_tar_iterator2_LDADD = libtar.a libsquashfs.la libio.a libutil.a libcompat.a
test_tar_iterator2_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR)
test_tar_iterator2_CPPFLAGS += -DTESTFILE=iterator/sparse.tar
test_tar_iterator3_SOURCES = lib/tar/test/tar_iterator3.c
-test_tar_iterator3_LDADD = libtar.a libio.a libutil.a libcompat.a
+test_tar_iterator3_LDADD = libtar.a libsquashfs.la libio.a libutil.a libcompat.a
test_tar_iterator3_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR)
tar_fuzz_SOURCES = lib/tar/test/tar_fuzz.c
-tar_fuzz_LDADD = libtar.a libio.a libutil.a libcompat.a
+tar_fuzz_LDADD = libtar.a libsquashfs.la libio.a libutil.a libcompat.a
test_tar_write_simple_SOURCES = lib/tar/test/tar_write_simple.c
-test_tar_write_simple_LDADD = libtar.a libio.a libutil.a libcompat.a
+test_tar_write_simple_LDADD = libtar.a libsquashfs.la libio.a libutil.a \
+ libcompat.a
test_tar_write_simple_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR)
test_tar_write_simple_CPPFLAGS += -DTESTFILE=write/simple.tar
diff --git a/lib/tar/src/cleanup.c b/lib/tar/src/cleanup.c
index 3ba8019..145f34d 100644
--- a/lib/tar/src/cleanup.c
+++ b/lib/tar/src/cleanup.c
@@ -7,6 +7,7 @@
#include "config.h"
#include "internal.h"
+#include "sqfs/xattr.h"
#include <stdlib.h>
#include <string.h>
@@ -23,7 +24,7 @@ void free_sparse_list(sparse_map_t *sparse)
void clear_header(tar_header_decoded_t *hdr)
{
- dir_entry_xattr_list_free(hdr->xattr);
+ sqfs_xattr_list_free(hdr->xattr);
free_sparse_list(hdr->sparse);
free(hdr->name);
free(hdr->link_target);
diff --git a/lib/tar/src/iterator.c b/lib/tar/src/iterator.c
index b1be42d..216c528 100644
--- a/lib/tar/src/iterator.c
+++ b/lib/tar/src/iterator.c
@@ -6,6 +6,7 @@
*/
#include "tar/tar.h"
#include "sqfs/error.h"
+#include "sqfs/xattr.h"
#include "util/util.h"
#include <stdlib.h>
@@ -281,7 +282,7 @@ static int it_open_file_ro(dir_iterator_t *it, istream_t **out)
return 0;
}
-static int it_read_xattr(dir_iterator_t *it, dir_entry_xattr_t **out)
+static int it_read_xattr(dir_iterator_t *it, sqfs_xattr_t **out)
{
tar_iterator_t *tar = (tar_iterator_t *)it;
@@ -293,7 +294,7 @@ static int it_read_xattr(dir_iterator_t *it, dir_entry_xattr_t **out)
return tar->state < 0 ? tar->state : SQFS_ERROR_NO_ENTRY;
if (tar->current.xattr != NULL) {
- *out = dir_entry_xattr_list_copy(tar->current.xattr);
+ *out = sqfs_xattr_list_copy(tar->current.xattr);
if (*out == NULL)
return SQFS_ERROR_ALLOC;
}
diff --git a/lib/tar/src/pax_header.c b/lib/tar/src/pax_header.c
index 81f6ad4..74a1b24 100644
--- a/lib/tar/src/pax_header.c
+++ b/lib/tar/src/pax_header.c
@@ -7,6 +7,7 @@
#include "config.h"
#include "internal.h"
+#include "sqfs/xattr.h"
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
@@ -140,27 +141,27 @@ fail:
return -1;
}
-static int pax_xattr_schily(tar_header_decoded_t *out,
- dir_entry_xattr_t *xattr)
+static int pax_xattr_schily(tar_header_decoded_t *out, sqfs_xattr_t *xattr)
{
xattr->next = out->xattr;
out->xattr = xattr;
return 0;
}
-static int pax_xattr_libarchive(tar_header_decoded_t *out,
- dir_entry_xattr_t *xattr)
+static int pax_xattr_libarchive(tar_header_decoded_t *out, sqfs_xattr_t *xattr)
{
+ char *key = (char *)xattr->data;
+ sqfs_u8 *value = xattr->data + (size_t)(xattr->value - xattr->data);
int ret;
ret = base64_decode((const char *)xattr->value, xattr->value_len,
- xattr->value, &xattr->value_len);
+ value, &xattr->value_len);
if (ret)
return -1;
- urldecode(xattr->key);
+ urldecode(key);
+ value[xattr->value_len] = '\0';
- xattr->value[xattr->value_len] = '\0';
xattr->next = out->xattr;
out->xattr = xattr;
return 0;
@@ -184,8 +185,7 @@ static const struct pax_handler_t {
int (*uint)(tar_header_decoded_t *out, sqfs_u64 uval);
int (*str)(tar_header_decoded_t *out, char *str);
int (*cstr)(tar_header_decoded_t *out, const char *str);
- int (*xattr)(tar_header_decoded_t *out,
- dir_entry_xattr_t *xattr);
+ int (*xattr)(tar_header_decoded_t *out, sqfs_xattr_t *xattr);
} cb;
} pax_fields[] = {
{ "uid", PAX_UID, PAX_TYPE_UINT, { .uint = pax_uid } },
@@ -239,7 +239,7 @@ static int apply_handler(tar_header_decoded_t *out,
const struct pax_handler_t *field, const char *key,
const char *value, size_t valuelen)
{
- dir_entry_xattr_t *xattr;
+ sqfs_xattr_t *xattr;
sqfs_s64 s64val;
sqfs_u64 uval;
char *copy;
@@ -274,9 +274,9 @@ static int apply_handler(tar_header_decoded_t *out,
}
break;
case PAX_TYPE_PREFIXED_XATTR:
- xattr = dir_entry_xattr_create(key + strlen(field->name) + 1,
- (const sqfs_u8 *)value,
- valuelen);
+ xattr = sqfs_xattr_create(key + strlen(field->name) + 1,
+ (const sqfs_u8 *)value,
+ valuelen);
if (xattr == NULL) {
perror("reading pax xattr field");
return -1;
diff --git a/lib/tar/src/write_header.c b/lib/tar/src/write_header.c
index f5473ca..039d1fe 100644
--- a/lib/tar/src/write_header.c
+++ b/lib/tar/src/write_header.c
@@ -7,6 +7,7 @@
#include "config.h"
#include "internal.h"
+#include "sqfs/xattr.h"
#include <string.h>
#include <stdlib.h>
@@ -144,15 +145,14 @@ static size_t prefix_digit_len(size_t len)
}
static int write_schily_xattr(ostream_t *fp, const struct stat *orig,
- const char *name, const dir_entry_xattr_t *xattr)
+ const char *name, const sqfs_xattr_t *xattr)
{
static const char *prefix = "SCHILY.xattr.";
size_t len, total_size = 0;
- const dir_entry_xattr_t *it;
char *buffer, *ptr;
int ret;
- for (it = xattr; it != NULL; it = it->next) {
+ for (const sqfs_xattr_t *it = xattr; it != NULL; it = it->next) {
len = strlen(prefix) + strlen(it->key) + it->value_len + 3;
total_size += len + prefix_digit_len(len);
@@ -167,7 +167,7 @@ static int write_schily_xattr(ostream_t *fp, const struct stat *orig,
ptr = buffer;
- for (it = xattr; it != NULL; it = it->next) {
+ for (const sqfs_xattr_t *it = xattr; it != NULL; it = it->next) {
len = strlen(prefix) + strlen(it->key) + it->value_len + 3;
len += prefix_digit_len(len);
@@ -184,7 +184,7 @@ static int write_schily_xattr(ostream_t *fp, const struct stat *orig,
}
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)
{
const char *reason;
diff --git a/lib/tar/test/tar_write_simple.c b/lib/tar/test/tar_write_simple.c
index 738b469..8a41c8f 100644
--- a/lib/tar/test/tar_write_simple.c
+++ b/lib/tar/test/tar_write_simple.c
@@ -9,6 +9,7 @@
#include "io/ostream.h"
#include "io/file.h"
#include "util/test.h"
+#include "sqfs/xattr.h"
#include "compat.h"
/*****************************************************************************/
@@ -52,7 +53,7 @@ static const char *buffer_get_filename(ostream_t *strm)
#define TIME_STAMP (1057296600)
-static dir_entry_xattr_t *mkxattr_chain(void)
+static sqfs_xattr_t *mkxattr_chain(void)
{
static const uint8_t value[] = {
0x00, 0x00, 0x00, 0x02,
@@ -61,20 +62,20 @@ static dir_entry_xattr_t *mkxattr_chain(void)
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
};
- dir_entry_xattr_t *list;
+ sqfs_xattr_t *list;
- list = dir_entry_xattr_create("user.mime_type",
- (const sqfs_u8 *)"blob/magic", 10);
+ list = sqfs_xattr_create("user.mime_type",
+ (const sqfs_u8 *)"blob/magic", 10);
TEST_NOT_NULL(list);
- list->next = dir_entry_xattr_create("security.capability",
- value, sizeof(value));
+ list->next = sqfs_xattr_create("security.capability",
+ value, sizeof(value));
TEST_NOT_NULL(list->next);
return list;
}
int main(int argc, char **argv)
{
- dir_entry_xattr_t *xattr;
+ sqfs_xattr_t *xattr;
struct stat sb;
istream_t *fp;
int ret;
@@ -154,7 +155,7 @@ int main(int argc, char **argv)
ret = write_tar_header(&mem_stream, &sb, "home/goliath/test.exe",
NULL, xattr, 11);
TEST_EQUAL_I(ret, 0);
- dir_entry_xattr_list_free(xattr);
+ sqfs_xattr_list_free(xattr);
ret = ostream_append(&mem_stream, ":-)\n", 4);
TEST_EQUAL_I(ret, 0);
diff --git a/lib/tar/test/tar_xattr.c b/lib/tar/test/tar_xattr.c
index 122d1db..1577fc7 100644
--- a/lib/tar/test/tar_xattr.c
+++ b/lib/tar/test/tar_xattr.c
@@ -8,6 +8,7 @@
#include "io/file.h"
#include "tar/tar.h"
#include "util/test.h"
+#include "sqfs/xattr.h"
int main(int argc, char **argv)
{
diff --git a/lib/tar/test/tar_xattr_bin.c b/lib/tar/test/tar_xattr_bin.c
index 90443a1..129d227 100644
--- a/lib/tar/test/tar_xattr_bin.c
+++ b/lib/tar/test/tar_xattr_bin.c
@@ -8,6 +8,7 @@
#include "io/file.h"
#include "tar/tar.h"
#include "util/test.h"
+#include "sqfs/xattr.h"
static const uint8_t value[] = {
0x00, 0x00, 0x00, 0x02,