aboutsummaryrefslogtreecommitdiff
path: root/bin/rdsquashfs
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2023-06-07 23:10:41 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2023-06-07 23:10:41 +0200
commit9c9ef7cae619e95232f44be21d4648edb5f0777a (patch)
treeaa40581ab35a7032dd49aaca312a77b0c882bbe7 /bin/rdsquashfs
parent9221d4dce6ff3e3cdd0f630a884b3643e6a1cac4 (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/rdsquashfs')
-rw-r--r--bin/rdsquashfs/src/dump_xattrs.c47
-rw-r--r--bin/rdsquashfs/src/rdsquashfs.h1
2 files changed, 14 insertions, 34 deletions
diff --git a/bin/rdsquashfs/src/dump_xattrs.c b/bin/rdsquashfs/src/dump_xattrs.c
index 9dbe437..93f3635 100644
--- a/bin/rdsquashfs/src/dump_xattrs.c
+++ b/bin/rdsquashfs/src/dump_xattrs.c
@@ -63,58 +63,37 @@ static bool is_printable(const sqfs_u8 *value, size_t len)
int dump_xattrs(sqfs_xattr_reader_t *xattr, const sqfs_inode_generic_t *inode)
{
- sqfs_xattr_value_t *value;
- sqfs_xattr_entry_t *key;
- sqfs_xattr_id_t desc;
+ sqfs_xattr_t *list;
sqfs_u32 index;
- size_t i;
if (xattr == NULL)
return 0;
sqfs_inode_get_xattr_index(inode, &index);
- if (index == 0xFFFFFFFF)
- return 0;
-
- if (sqfs_xattr_reader_get_desc(xattr, index, &desc)) {
- fputs("Error resolving xattr index\n", stderr);
+ if (sqfs_xattr_reader_read_all(xattr, index, &list)) {
+ fprintf(stderr, "Error loading xattr entries list #%08X\n",
+ index);
return -1;
}
- if (sqfs_xattr_reader_seek_kv(xattr, &desc)) {
- fputs("Error locating xattr key-value pairs\n", stderr);
- return -1;
- }
+ for (const sqfs_xattr_t *ent = list; ent != NULL; ent = ent->next) {
+ size_t key_len = strlen(ent->key);
- for (i = 0; i < desc.count; ++i) {
- if (sqfs_xattr_reader_read_key(xattr, &key)) {
- fputs("Error reading xattr key\n", stderr);
- return -1;
- }
-
- if (sqfs_xattr_reader_read_value(xattr, key, &value)) {
- fputs("Error reading xattr value\n", stderr);
- sqfs_free(key);
- return -1;
- }
-
- if (is_printable(key->key, key->size)) {
- printf("%s=", key->key);
+ if (is_printable((const sqfs_u8 *)ent->key, key_len)) {
+ printf("%s=", ent->key);
} else {
- print_hex(key->key, key->size);
+ print_hex((const sqfs_u8 *)ent->key, key_len);
}
- if (is_printable(value->value, value->size)) {
- printf("%s\n", value->value);
+ if (is_printable(ent->value, ent->value_len)) {
+ printf("%s\n", ent->value);
} else {
- print_hex(value->value, value->size);
+ print_hex(ent->value, ent->value_len);
printf("\n");
}
-
- sqfs_free(key);
- sqfs_free(value);
}
+ sqfs_xattr_list_free(list);
return 0;
}
diff --git a/bin/rdsquashfs/src/rdsquashfs.h b/bin/rdsquashfs/src/rdsquashfs.h
index f9f75e9..364af14 100644
--- a/bin/rdsquashfs/src/rdsquashfs.h
+++ b/bin/rdsquashfs/src/rdsquashfs.h
@@ -10,6 +10,7 @@
#include "config.h"
#include "common.h"
#include "util/util.h"
+#include "sqfs/xattr.h"
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN