diff options
author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2023-06-05 19:15:13 +0200 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2023-06-05 16:22:00 +0200 |
commit | 2d3cb9c4323a803268206db3a9363abc67d908d0 (patch) | |
tree | ebf126a48931b46f5d76c42818754dbf054c68b5 | |
parent | c9a8adc15f9de110771156fdc85fb98533648a53 (diff) |
libsqfs: Add an xattr writer function to add a combined key-value struct
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
-rw-r--r-- | bin/gensquashfs/src/dirscan_xattr.c | 2 | ||||
-rw-r--r-- | bin/gensquashfs/src/filemap_xattr.c | 2 | ||||
-rw-r--r-- | bin/gensquashfs/src/selinux.c | 4 | ||||
-rw-r--r-- | bin/tar2sqfs/src/process_tarball.c | 6 | ||||
-rw-r--r-- | include/sqfs/xattr_writer.h | 20 | ||||
-rw-r--r-- | lib/sqfs/src/xattr/xattr_writer_record.c | 10 | ||||
-rw-r--r-- | lib/sqfs/test/xattr_benchmark.c | 4 | ||||
-rw-r--r-- | lib/sqfs/test/xattr_writer.c | 20 |
8 files changed, 45 insertions, 23 deletions
diff --git a/bin/gensquashfs/src/dirscan_xattr.c b/bin/gensquashfs/src/dirscan_xattr.c index e39a868..1bc829f 100644 --- a/bin/gensquashfs/src/dirscan_xattr.c +++ b/bin/gensquashfs/src/dirscan_xattr.c @@ -95,7 +95,7 @@ static int xattr_from_path(sqfs_xattr_writer_t *xwr, const char *path) goto fail; } - ret = sqfs_xattr_writer_add(xwr, key, value, vallen); + ret = sqfs_xattr_writer_add_kv(xwr, key, value, vallen); if (ret) { sqfs_perror(path, "storing xattr key-value pairs", diff --git a/bin/gensquashfs/src/filemap_xattr.c b/bin/gensquashfs/src/filemap_xattr.c index 0870d3b..508e75a 100644 --- a/bin/gensquashfs/src/filemap_xattr.c +++ b/bin/gensquashfs/src/filemap_xattr.c @@ -240,7 +240,7 @@ xattr_apply_map_file(char *path, void *map, sqfs_xattr_writer_t *xwr) { printf(" %s = \n", entry->key); fwrite(entry->value, entry->value_len, 1, stdout); puts("\n"); - ret = sqfs_xattr_writer_add( + ret = sqfs_xattr_writer_add_kv( xwr, entry->key, entry->value, entry->value_len); if (ret < 0) { return ret; diff --git a/bin/gensquashfs/src/selinux.c b/bin/gensquashfs/src/selinux.c index 678723b..24fba54 100644 --- a/bin/gensquashfs/src/selinux.c +++ b/bin/gensquashfs/src/selinux.c @@ -22,8 +22,8 @@ int selinux_relable_node(void *sehnd, sqfs_xattr_writer_t *xwr, goto fail; } - ret = sqfs_xattr_writer_add(xwr, XATTR_NAME_SELINUX, - context, strlen(context)); + ret = sqfs_xattr_writer_add_kv(xwr, XATTR_NAME_SELINUX, + context, strlen(context)); free(context); if (ret) diff --git a/bin/tar2sqfs/src/process_tarball.c b/bin/tar2sqfs/src/process_tarball.c index 5b0cbdd..9ad7d9a 100644 --- a/bin/tar2sqfs/src/process_tarball.c +++ b/bin/tar2sqfs/src/process_tarball.c @@ -56,7 +56,9 @@ static int copy_xattr(sqfs_writer_t *sqfs, const char *filename, } for (xattr = list; xattr != NULL; xattr = xattr->next) { - if (sqfs_get_xattr_prefix_id(xattr->key) < 0) { + ret = sqfs_xattr_writer_add(sqfs->xwr, xattr); + + if (ret == SQFS_ERROR_UNSUPPORTED) { fprintf(stderr, "%s: squashfs does not " "support xattr prefix of %s\n", dont_skip ? "ERROR" : "WARNING", @@ -67,8 +69,6 @@ static int copy_xattr(sqfs_writer_t *sqfs, const char *filename, continue; } - ret = sqfs_xattr_writer_add(sqfs->xwr, xattr->key, xattr->value, - xattr->value_len); if (ret) { sqfs_perror(filename, "storing xattr key-value pair", ret); diff --git a/include/sqfs/xattr_writer.h b/include/sqfs/xattr_writer.h index 8820e51..d8f8343 100644 --- a/include/sqfs/xattr_writer.h +++ b/include/sqfs/xattr_writer.h @@ -94,8 +94,24 @@ SQFS_API int sqfs_xattr_writer_begin(sqfs_xattr_writer_t *xwr, sqfs_u32 flags); * * @return Zero on success, a negative @ref SQFS_ERROR value on failure. */ -SQFS_API int sqfs_xattr_writer_add(sqfs_xattr_writer_t *xwr, const char *key, - const void *value, size_t size); +SQFS_API int sqfs_xattr_writer_add_kv(sqfs_xattr_writer_t *xwr, + const char *key, + const void *value, size_t size); + +/** + * @brief Add a key-value struct to the current block. + * + * @memberof sqfs_xattr_writer_t + * + * To add a key string and value blob, use @ref sqfs_xattr_writer_add_kv + * + * @param xwr A pointer to an xattr writer instance. + * @param ent A pointer to a combined key-value pair. + * + * @return Zero on success, a negative @ref SQFS_ERROR value on failure. + */ +SQFS_API int sqfs_xattr_writer_add(sqfs_xattr_writer_t *xwr, + const sqfs_xattr_t *ent); /** * @brief Finish a generating a key-value block. 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); |