aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
Diffstat (limited to 'bin')
-rw-r--r--bin/rdsquashfs/src/dump_xattrs.c47
-rw-r--r--bin/rdsquashfs/src/rdsquashfs.h1
-rw-r--r--bin/sqfs2tar/Makemodule.am3
-rw-r--r--bin/sqfs2tar/src/sqfs2tar.h4
-rw-r--r--bin/sqfs2tar/src/write_tree.c11
-rw-r--r--bin/sqfs2tar/src/xattr.c84
6 files changed, 24 insertions, 126 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
diff --git a/bin/sqfs2tar/Makemodule.am b/bin/sqfs2tar/Makemodule.am
index 2e6c411..9f7abf9 100644
--- a/bin/sqfs2tar/Makemodule.am
+++ b/bin/sqfs2tar/Makemodule.am
@@ -1,6 +1,5 @@
sqfs2tar_SOURCES = bin/sqfs2tar/src/sqfs2tar.c bin/sqfs2tar/src/sqfs2tar.h \
- bin/sqfs2tar/src/options.c bin/sqfs2tar/src/write_tree.c \
- bin/sqfs2tar/src/xattr.c
+ bin/sqfs2tar/src/options.c bin/sqfs2tar/src/write_tree.c
sqfs2tar_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS)
sqfs2tar_LDADD = libcommon.a libutil.a libsquashfs.la libtar.a
sqfs2tar_LDADD += libio.a libxfrm.a libcompat.a libfstree.a
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;
-}