diff options
author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2023-06-07 23:10:41 +0200 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2023-06-07 23:10:41 +0200 |
commit | 9c9ef7cae619e95232f44be21d4648edb5f0777a (patch) | |
tree | aa40581ab35a7032dd49aaca312a77b0c882bbe7 /bin/sqfs2tar/src | |
parent | 9221d4dce6ff3e3cdd0f630a884b3643e6a1cac4 (diff) |
libsquashfs: Add utility functions to read xattrs into list
The common pattern is used in rdsquashfs and sqfs2tar, move the code
to libsquashfs.
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'bin/sqfs2tar/src')
-rw-r--r-- | bin/sqfs2tar/src/sqfs2tar.h | 4 | ||||
-rw-r--r-- | bin/sqfs2tar/src/write_tree.c | 11 | ||||
-rw-r--r-- | bin/sqfs2tar/src/xattr.c | 84 |
3 files changed, 9 insertions, 90 deletions
diff --git a/bin/sqfs2tar/src/sqfs2tar.h b/bin/sqfs2tar/src/sqfs2tar.h index 3c7b3d1..e176008 100644 --- a/bin/sqfs2tar/src/sqfs2tar.h +++ b/bin/sqfs2tar/src/sqfs2tar.h @@ -46,10 +46,6 @@ extern ostream_t *out_file; char *assemble_tar_path(char *name, bool is_dir); -/* xattr.c */ -int get_xattrs(const char *name, const sqfs_inode_generic_t *inode, - 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 71eb249..e578a9f 100644 --- a/bin/sqfs2tar/src/write_tree.c +++ b/bin/sqfs2tar/src/write_tree.c @@ -124,8 +124,15 @@ static int write_tree_dfs(const sqfs_tree_node_t *n) } } - if (!no_xattr) { - if (get_xattrs(name, n->inode, &xattr)) { + if (!no_xattr && xr != NULL) { + sqfs_u32 index; + int ret; + + sqfs_inode_get_xattr_index(n->inode, &index); + + ret = sqfs_xattr_reader_read_all(xr, index, &xattr); + if (ret) { + sqfs_perror(name, "resolving xattr index", ret); sqfs_free(name); return -1; } diff --git a/bin/sqfs2tar/src/xattr.c b/bin/sqfs2tar/src/xattr.c deleted file mode 100644 index 2af856d..0000000 --- a/bin/sqfs2tar/src/xattr.c +++ /dev/null @@ -1,84 +0,0 @@ -/* SPDX-License-Identifier: GPL-3.0-or-later */ -/* - * xattr.c - * - * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at> - */ -#include "sqfs2tar.h" - -static sqfs_xattr_t *mkxattr(const sqfs_xattr_entry_t *key, - const sqfs_xattr_value_t *value) -{ - sqfs_xattr_t *ent; - - ent = sqfs_xattr_create((const char *)key->key, - value->value, value->size); - if (ent == NULL) { - perror("creating xattr entry"); - return NULL; - } - - return ent; -} - -int get_xattrs(const char *name, const sqfs_inode_generic_t *inode, - sqfs_xattr_t **out) -{ - sqfs_xattr_t *list = NULL, *ent; - sqfs_xattr_value_t *value; - sqfs_xattr_entry_t *key; - sqfs_xattr_id_t desc; - sqfs_u32 index; - size_t i; - int ret; - - if (xr == NULL) - return 0; - - sqfs_inode_get_xattr_index(inode, &index); - if (index == 0xFFFFFFFF) - return 0; - - ret = sqfs_xattr_reader_get_desc(xr, index, &desc); - if (ret) { - sqfs_perror(name, "resolving xattr index", ret); - return -1; - } - - ret = sqfs_xattr_reader_seek_kv(xr, &desc); - if (ret) { - sqfs_perror(name, "locating xattr key-value pairs", ret); - return -1; - } - - for (i = 0; i < desc.count; ++i) { - ret = sqfs_xattr_reader_read_key(xr, &key); - if (ret) { - sqfs_perror(name, "reading xattr key", ret); - goto fail; - } - - ret = sqfs_xattr_reader_read_value(xr, key, &value); - if (ret) { - sqfs_perror(name, "reading xattr value", ret); - sqfs_free(key); - goto fail; - } - - ent = mkxattr(key, value); - sqfs_free(key); - sqfs_free(value); - - if (ent == NULL) - goto fail; - - ent->next = list; - list = ent; - } - - *out = list; - return 0; -fail: - sqfs_xattr_list_free(list); - return -1; -} |