diff options
author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2019-09-19 17:36:53 +0200 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2019-09-20 18:34:16 +0200 |
commit | 37a1176c3191cd722de613e26eda91518ca73751 (patch) | |
tree | 037aedf6f9de72203130102c05fe1bdf956275e0 /unpack/dump_xattrs.c | |
parent | 5dcd267e9f0c5d93793e6d5e68279bd5dde5dff6 (diff) |
Remove fstree code from rdsquashfs
Use the directory reader from libsquashfs instead.
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'unpack/dump_xattrs.c')
-rw-r--r-- | unpack/dump_xattrs.c | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/unpack/dump_xattrs.c b/unpack/dump_xattrs.c new file mode 100644 index 0000000..c619767 --- /dev/null +++ b/unpack/dump_xattrs.c @@ -0,0 +1,73 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * dump_xattrs.c + * + * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at> + */ +#include "rdsquashfs.h" + +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; + uint32_t index; + size_t i; + + if (xattr == NULL) + return 0; + + switch (inode->base.type) { + case SQFS_INODE_EXT_DIR: + index = inode->data.dir_ext.xattr_idx; + break; + case SQFS_INODE_EXT_FILE: + index = inode->data.file_ext.xattr_idx; + break; + case SQFS_INODE_EXT_SLINK: + index = inode->data.slink_ext.xattr_idx; + break; + case SQFS_INODE_EXT_BDEV: + case SQFS_INODE_EXT_CDEV: + index = inode->data.dev_ext.xattr_idx; + break; + case SQFS_INODE_EXT_FIFO: + case SQFS_INODE_EXT_SOCKET: + index = inode->data.ipc_ext.xattr_idx; + break; + default: + return 0; + } + + if (index == 0xFFFFFFFF) + return 0; + + if (sqfs_xattr_reader_get_desc(xattr, index, &desc)) { + fputs("Error resolving xattr index\n", stderr); + return -1; + } + + if (sqfs_xattr_reader_seek_kv(xattr, &desc)) { + fputs("Error locating xattr key-value pairs\n", stderr); + return -1; + } + + 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); + free(key); + return -1; + } + + printf("%s=%s\n", key->key, value->value); + free(key); + free(value); + } + + return 0; +} |