aboutsummaryrefslogtreecommitdiff
path: root/lib/sqfs
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2023-06-05 19:15:13 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2023-06-05 16:22:00 +0200
commit2d3cb9c4323a803268206db3a9363abc67d908d0 (patch)
treeebf126a48931b46f5d76c42818754dbf054c68b5 /lib/sqfs
parentc9a8adc15f9de110771156fdc85fb98533648a53 (diff)
libsqfs: Add an xattr writer function to add a combined key-value struct
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/sqfs')
-rw-r--r--lib/sqfs/src/xattr/xattr_writer_record.c10
-rw-r--r--lib/sqfs/test/xattr_benchmark.c4
-rw-r--r--lib/sqfs/test/xattr_writer.c20
3 files changed, 20 insertions, 14 deletions
diff --git a/lib/sqfs/src/xattr/xattr_writer_record.c b/lib/sqfs/src/xattr/xattr_writer_record.c
index 81bbf6b..082331c 100644
--- a/lib/sqfs/src/xattr/xattr_writer_record.c
+++ b/lib/sqfs/src/xattr/xattr_writer_record.c
@@ -46,8 +46,8 @@ int sqfs_xattr_writer_begin(sqfs_xattr_writer_t *xwr, sqfs_u32 flags)
return 0;
}
-int sqfs_xattr_writer_add(sqfs_xattr_writer_t *xwr, const char *key,
- const void *value, size_t size)
+int sqfs_xattr_writer_add_kv(sqfs_xattr_writer_t *xwr, const char *key,
+ const void *value, size_t size)
{
size_t i, key_index, old_value_index, value_index;
sqfs_u64 kv_pair;
@@ -98,6 +98,12 @@ int sqfs_xattr_writer_add(sqfs_xattr_writer_t *xwr, const char *key,
return array_append(&xwr->kv_pairs, &kv_pair);
}
+int sqfs_xattr_writer_add(sqfs_xattr_writer_t *xwr, const sqfs_xattr_t *ent)
+{
+ return sqfs_xattr_writer_add_kv(xwr, ent->key,
+ ent->value, ent->value_len);
+}
+
int sqfs_xattr_writer_end(sqfs_xattr_writer_t *xwr, sqfs_u32 *out)
{
kv_block_desc_t blk;
diff --git a/lib/sqfs/test/xattr_benchmark.c b/lib/sqfs/test/xattr_benchmark.c
index 072dd06..eab759a 100644
--- a/lib/sqfs/test/xattr_benchmark.c
+++ b/lib/sqfs/test/xattr_benchmark.c
@@ -96,8 +96,8 @@ int main(int argc, char **argv)
snprintf(value, sizeof(value), "group%ld/value%ld",
blkidx, grpidx);
- ret = sqfs_xattr_writer_add(xwr, key, value,
- strlen(value));
+ ret = sqfs_xattr_writer_add_kv(xwr, key, value,
+ strlen(value));
if (ret < 0) {
sqfs_perror(NULL, "add to xattr block", ret);
diff --git a/lib/sqfs/test/xattr_writer.c b/lib/sqfs/test/xattr_writer.c
index f7d0734..55d2030 100644
--- a/lib/sqfs/test/xattr_writer.c
+++ b/lib/sqfs/test/xattr_writer.c
@@ -95,10 +95,10 @@ int main(int argc, char **argv)
ret = sqfs_xattr_writer_begin(xwr, 0);
TEST_EQUAL_I(ret, 0);
- ret = sqfs_xattr_writer_add(xwr, "user.foobar", "test", 4);
+ ret = sqfs_xattr_writer_add_kv(xwr, "user.foobar", "test", 4);
TEST_EQUAL_I(ret, 0);
- ret = sqfs_xattr_writer_add(xwr, "security.selinux", "Xwhatever", 9);
+ ret = sqfs_xattr_writer_add_kv(xwr, "security.selinux", "Xwhatever", 9);
TEST_EQUAL_I(ret, 0);
ret = sqfs_xattr_writer_end(xwr, &id);
@@ -109,10 +109,10 @@ int main(int argc, char **argv)
ret = sqfs_xattr_writer_begin(xwr, 0);
TEST_EQUAL_I(ret, 0);
- ret = sqfs_xattr_writer_add(xwr, "user.foobar", "bla", 3);
+ ret = sqfs_xattr_writer_add_kv(xwr, "user.foobar", "bla", 3);
TEST_EQUAL_I(ret, 0);
- ret = sqfs_xattr_writer_add(xwr, "security.selinux", "blub", 4);
+ ret = sqfs_xattr_writer_add_kv(xwr, "security.selinux", "blub", 4);
TEST_EQUAL_I(ret, 0);
ret = sqfs_xattr_writer_end(xwr, &id);
@@ -123,10 +123,10 @@ int main(int argc, char **argv)
ret = sqfs_xattr_writer_begin(xwr, 0);
TEST_EQUAL_I(ret, 0);
- ret = sqfs_xattr_writer_add(xwr, "security.selinux", "Xwhatever", 9);
+ ret = sqfs_xattr_writer_add_kv(xwr, "security.selinux", "Xwhatever", 9);
TEST_EQUAL_I(ret, 0);
- ret = sqfs_xattr_writer_add(xwr, "user.foobar", "test", 4);
+ ret = sqfs_xattr_writer_add_kv(xwr, "user.foobar", "test", 4);
TEST_EQUAL_I(ret, 0);
ret = sqfs_xattr_writer_end(xwr, &id);
@@ -138,13 +138,13 @@ int main(int argc, char **argv)
ret = sqfs_xattr_writer_begin(xwr, 0);
TEST_EQUAL_I(ret, 0);
- ret = sqfs_xattr_writer_add(xwr, "user.foobar", "mimimi", 6);
+ ret = sqfs_xattr_writer_add_kv(xwr, "user.foobar", "mimimi", 6);
TEST_EQUAL_I(ret, 0);
- ret = sqfs_xattr_writer_add(xwr, "security.selinux", "blub", 4);
+ ret = sqfs_xattr_writer_add_kv(xwr, "security.selinux", "blub", 4);
TEST_EQUAL_I(ret, 0);
- ret = sqfs_xattr_writer_add(xwr, "user.foobar", "bla", 3);
+ ret = sqfs_xattr_writer_add_kv(xwr, "user.foobar", "bla", 3);
TEST_EQUAL_I(ret, 0);
ret = sqfs_xattr_writer_end(xwr, &id);
@@ -155,7 +155,7 @@ int main(int argc, char **argv)
ret = sqfs_xattr_writer_begin(xwr, 0);
TEST_EQUAL_I(ret, 0);
- ret = sqfs_xattr_writer_add(xwr, "security.selinux", "Xwhatever", 9);
+ ret = sqfs_xattr_writer_add_kv(xwr, "security.selinux", "Xwhatever", 9);
TEST_EQUAL_I(ret, 0);
ret = sqfs_xattr_writer_end(xwr, &id);