diff options
author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2023-06-05 19:20:04 +0200 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2023-06-05 16:28:56 +0200 |
commit | 9221d4dce6ff3e3cdd0f630a884b3643e6a1cac4 (patch) | |
tree | c0f2deb25d2104bbaa735bb00ed7a226604fe5ec | |
parent | 2d3cb9c4323a803268206db3a9363abc67d908d0 (diff) |
gensquashfs: replace XattrMapEntry with sqfs_xattr_t
It has the same members, but with the added benefit that we already
have helper functions for it in libsquashfs and we can just hose
it directly into the xattr writer.
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
-rw-r--r-- | bin/gensquashfs/src/filemap_xattr.c | 32 | ||||
-rw-r--r-- | bin/gensquashfs/src/mkfs.h | 9 | ||||
-rw-r--r-- | bin/gensquashfs/test/filemap_xattr.c | 2 |
3 files changed, 17 insertions, 26 deletions
diff --git a/bin/gensquashfs/src/filemap_xattr.c b/bin/gensquashfs/src/filemap_xattr.c index 508e75a..4adc24f 100644 --- a/bin/gensquashfs/src/filemap_xattr.c +++ b/bin/gensquashfs/src/filemap_xattr.c @@ -128,25 +128,29 @@ static int parse_xattr(const char *filename, size_t line_num, char *key_start, { size_t len; struct XattrMapPattern *current_pattern = map->patterns; - struct XattrMapEntry *current_entry; + sqfs_xattr_t *current_entry; + sqfs_u8 *value; if (current_pattern == NULL) { print_error(filename, line_num, "no file specified yet"); return -1; } - current_entry = calloc(1, sizeof(struct XattrMapEntry)); + len = strlen(value_start); + value = decode(filename, line_num, value_start, &len); + if (value == NULL) + return -1; + + current_entry = sqfs_xattr_create(key_start, value, len); + free(value); if (current_entry == NULL) { + print_error(filename, line_num, "out-of-memory"); return -1; } + current_entry->next = current_pattern->entries; current_pattern->entries = current_entry; - current_entry->key = strdup(key_start); - len = strlen(value_start); - current_entry->value = decode(filename, line_num, value_start, &len); - current_entry->value_len = len; - return 0; } @@ -206,13 +210,8 @@ xattr_close_map_file(void *xattr_map) { while (map->patterns != NULL) { struct XattrMapPattern *file = map->patterns; map->patterns = file->next; - while (file->entries != NULL) { - struct XattrMapEntry *entry = file->entries; - file->entries = entry->next; - free(entry->key); - free(entry->value); - free(entry); - } + + sqfs_xattr_list_free(file->entries); free(file->path); free(file); } @@ -224,7 +223,7 @@ xattr_apply_map_file(char *path, void *map, sqfs_xattr_writer_t *xwr) { struct XattrMap *xattr_map = map; int ret = 0; const struct XattrMapPattern *pat; - const struct XattrMapEntry *entry; + const sqfs_xattr_t *entry; for (pat = xattr_map->patterns; pat != NULL; pat = pat->next) { char *patstr = pat->path; @@ -240,8 +239,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_kv( - xwr, entry->key, entry->value, entry->value_len); + ret = sqfs_xattr_writer_add(xwr, entry); if (ret < 0) { return ret; } diff --git a/bin/gensquashfs/src/mkfs.h b/bin/gensquashfs/src/mkfs.h index 9f2be13..0a9a3b3 100644 --- a/bin/gensquashfs/src/mkfs.h +++ b/bin/gensquashfs/src/mkfs.h @@ -62,16 +62,9 @@ typedef struct { bool scan_xattr; } options_t; -struct XattrMapEntry { - char *key; - sqfs_u8 *value; - size_t value_len; - struct XattrMapEntry *next; -}; - struct XattrMapPattern { char *path; - struct XattrMapEntry *entries; + sqfs_xattr_t *entries; struct XattrMapPattern *next; }; diff --git a/bin/gensquashfs/test/filemap_xattr.c b/bin/gensquashfs/test/filemap_xattr.c index d258d89..c9fd26b 100644 --- a/bin/gensquashfs/test/filemap_xattr.c +++ b/bin/gensquashfs/test/filemap_xattr.c @@ -25,8 +25,8 @@ static const sqfs_u8 rfkill_acl[] = { int main(int argc, char **argv) { struct XattrMapPattern *pat; - struct XattrMapEntry *ent; struct XattrMap *map; + sqfs_xattr_t *ent; int ret; (void)argc; (void)argv; |