diff options
-rw-r--r-- | include/io/dir_iterator.h | 11 | ||||
-rw-r--r-- | include/io/xattr.h | 18 | ||||
-rw-r--r-- | lib/io/Makemodule.am | 2 | ||||
-rw-r--r-- | lib/io/src/dir_tree_iterator.c | 13 | ||||
-rw-r--r-- | lib/io/src/unix/dir_iterator.c | 9 | ||||
-rw-r--r-- | lib/io/src/win32/dir_iterator.c | 9 |
6 files changed, 61 insertions, 1 deletions
diff --git a/include/io/dir_iterator.h b/include/io/dir_iterator.h index 0de135a..377f07e 100644 --- a/include/io/dir_iterator.h +++ b/include/io/dir_iterator.h @@ -9,6 +9,7 @@ #include "sqfs/predef.h" #include "io/istream.h" +#include "io/xattr.h" typedef enum { DIR_ENTRY_FLAG_MOUNT_POINT = 0x0001, @@ -148,6 +149,16 @@ typedef struct dir_iterator_t { * @return Zero on success, negative @ref SQFS_ERROR value on failure. */ int (*open_file_ro)(struct dir_iterator_t *it, istream_t **out); + + /** + * @brief Read extended attributes associated with the current entry + * + * @param it A pointer to the iterator itself. + * @param out Returns a linked list of xattr entries. + * + * @return Zero on success, negative @ref SQFS_ERROR value on failure. + */ + int (*read_xattr)(struct dir_iterator_t *it, dir_entry_xattr_t **out); } dir_iterator_t; enum { diff --git a/include/io/xattr.h b/include/io/xattr.h new file mode 100644 index 0000000..d912fad --- /dev/null +++ b/include/io/xattr.h @@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: LGPL-3.0-or-later */ +/* + * xattr.h + * + * Copyright (C) 2023 David Oberhollenzer <goliath@infraroot.at> + */ +#ifndef IO_XATTR_H +#define IO_XATTR_H + +typedef struct dir_entry_xattr_t { + struct dir_entry_xattr_t *next; + char *key; + sqfs_u8 *value; + size_t value_len; + char data[]; +} dir_entry_xattr_t; + +#endif /* IO_XATTR_H */ diff --git a/lib/io/Makemodule.am b/lib/io/Makemodule.am index 2fcd1a7..841febf 100644 --- a/lib/io/Makemodule.am +++ b/lib/io/Makemodule.am @@ -1,6 +1,6 @@ libio_a_SOURCES = include/io/istream.h include/io/ostream.h include/io/xfrm.h \ include/io/file.h include/io/std.h \ - include/io/dir_iterator.h \ + include/io/dir_iterator.h include/io/xattr.h \ lib/io/src/internal.h lib/io/src/ostream.c \ lib/io/src/istream.c lib/io/src/get_line.c lib/io/src/xfrm/ostream.c \ lib/io/src/xfrm/istream.c lib/io/src/dir_tree_iterator.c diff --git a/lib/io/src/dir_tree_iterator.c b/lib/io/src/dir_tree_iterator.c index 51d289a..0174d73 100644 --- a/lib/io/src/dir_tree_iterator.c +++ b/lib/io/src/dir_tree_iterator.c @@ -284,6 +284,18 @@ static int open_file_ro(dir_iterator_t *base, istream_t **out) return it->top->dir->open_file_ro(it->top->dir, out); } +static int read_xattr(dir_iterator_t *base, dir_entry_xattr_t **out) +{ + dir_tree_iterator_t *it = (dir_tree_iterator_t *)base; + + if (it->top == NULL) { + *out = NULL; + return SQFS_ERROR_NO_ENTRY; + } + + return it->top->dir->read_xattr(it->top->dir, out); +} + dir_iterator_t *dir_tree_iterator_create(const char *path, const dir_tree_cfg_t *cfg) { @@ -315,6 +327,7 @@ dir_iterator_t *dir_tree_iterator_create(const char *path, ((dir_iterator_t *)it)->open_subdir = open_subdir; ((dir_iterator_t *)it)->ignore_subdir = ignore_subdir; ((dir_iterator_t *)it)->open_file_ro = open_file_ro; + ((dir_iterator_t *)it)->read_xattr = read_xattr; return (dir_iterator_t *)it; fail: diff --git a/lib/io/src/unix/dir_iterator.c b/lib/io/src/unix/dir_iterator.c index d6a7454..fb7edae 100644 --- a/lib/io/src/unix/dir_iterator.c +++ b/lib/io/src/unix/dir_iterator.c @@ -137,6 +137,13 @@ static int dir_open_file_ro(dir_iterator_t *it, istream_t **out) return SQFS_ERROR_UNSUPPORTED; } +static int dir_read_xattr(dir_iterator_t *it, dir_entry_xattr_t **out) +{ + (void)it; + *out = NULL; + return 0; +} + static int dir_open_subdir(dir_iterator_t *base, dir_iterator_t **out) { const unix_dir_iterator_t *it = (const unix_dir_iterator_t *)base; @@ -178,6 +185,7 @@ static int dir_open_subdir(dir_iterator_t *base, dir_iterator_t **out) ((dir_iterator_t *)sub)->open_subdir = dir_open_subdir; ((dir_iterator_t *)sub)->ignore_subdir = dir_ignore_subdir; ((dir_iterator_t *)sub)->open_file_ro = dir_open_file_ro; + ((dir_iterator_t *)sub)->read_xattr = dir_read_xattr; *out = (dir_iterator_t *)sub; return 0; @@ -219,6 +227,7 @@ dir_iterator_t *dir_iterator_create(const char *path) ((dir_iterator_t *)it)->open_subdir = dir_open_subdir; ((dir_iterator_t *)it)->ignore_subdir = dir_ignore_subdir; ((dir_iterator_t *)it)->open_file_ro = dir_open_file_ro; + ((dir_iterator_t *)it)->read_xattr = dir_read_xattr; return (dir_iterator_t *)it; } diff --git a/lib/io/src/win32/dir_iterator.c b/lib/io/src/win32/dir_iterator.c index d8ac8f3..c9defc7 100644 --- a/lib/io/src/win32/dir_iterator.c +++ b/lib/io/src/win32/dir_iterator.c @@ -119,6 +119,13 @@ static int dir_iterator_open_file_ro(dir_iterator_t *it, istream_t **out) return SQFS_ERROR_UNSUPPORTED; } +static int dir_iterator_read_xattr(dir_iterator_t *it, dir_entry_xattr_t **out) +{ + (void)it; + *out = NULL; + return 0; +} + static int dir_iterator_open_subdir(dir_iterator_t *it, dir_iterator_t **out) { const dir_iterator_win32_t *dir = (const dir_iterator_win32_t *)it; @@ -153,6 +160,7 @@ static int dir_iterator_open_subdir(dir_iterator_t *it, dir_iterator_t **out) ((dir_iterator_t *)sub)->open_subdir = dir_iterator_open_subdir; ((dir_iterator_t *)sub)->ignore_subdir = dir_iterator_ignore_subdir; ((dir_iterator_t *)sub)->open_file_ro = dir_iterator_open_file_ro; + ((dir_iterator_t *)sub)->read_xattr = dir_iterator_read_xattr; sub->is_first = true; sub->state = 0; @@ -214,6 +222,7 @@ dir_iterator_t *dir_iterator_create(const char *path) ((dir_iterator_t *)it)->open_subdir = dir_iterator_open_subdir; ((dir_iterator_t *)it)->ignore_subdir = dir_iterator_ignore_subdir; ((dir_iterator_t *)it)->open_file_ro = dir_iterator_open_file_ro; + ((dir_iterator_t *)it)->read_xattr = dir_iterator_read_xattr; it->is_first = true; it->state = 0; |