[PATCH v2 2/4] erofs-utils: lib: add match_base_prefix() helper
Jingbo Xu
jefflexu at linux.alibaba.com
Wed Aug 16 13:49:39 AEST 2023
Since the introduction of long xattr name prefix, match_prefix() will
search among the long xattr name prefixes first and return the matched
prefix, while erofs_getxattr() expects a base prefix even when the
queried xattr name matches a long prefix.
Thus introduce match_base_prefix() helper to do this.
Signed-off-by: Jingbo Xu <jefflexu at linux.alibaba.com>
---
lib/xattr.c | 25 ++++++++++++++++---------
1 file changed, 16 insertions(+), 9 deletions(-)
diff --git a/lib/xattr.c b/lib/xattr.c
index 2548750..4091fe6 100644
--- a/lib/xattr.c
+++ b/lib/xattr.c
@@ -137,27 +137,34 @@ static struct xattr_item *get_xattritem(u8 prefix, char *kvbuf,
return item;
}
-static bool match_prefix(const char *key, u8 *index, u16 *len)
+static bool match_base_prefix(const char *key, u8 *index, u16 *len)
{
struct xattr_prefix *p;
- struct ea_type_node *tnode;
- list_for_each_entry(tnode, &ea_name_prefixes, list) {
- p = &tnode->type;
+ for (p = xattr_types; p < xattr_types + ARRAY_SIZE(xattr_types); ++p) {
if (p->prefix && !strncmp(p->prefix, key, p->prefix_len)) {
*len = p->prefix_len;
- *index = tnode->index;
+ *index = p - xattr_types;
return true;
}
}
- for (p = xattr_types; p < xattr_types + ARRAY_SIZE(xattr_types); ++p) {
+ return false;
+}
+
+static bool match_prefix(const char *key, u8 *index, u16 *len)
+{
+ struct xattr_prefix *p;
+ struct ea_type_node *tnode;
+
+ list_for_each_entry(tnode, &ea_name_prefixes, list) {
+ p = &tnode->type;
if (p->prefix && !strncmp(p->prefix, key, p->prefix_len)) {
*len = p->prefix_len;
- *index = p - xattr_types;
+ *index = tnode->index;
return true;
}
}
- return false;
+ return match_base_prefix(key, index, len);
}
static struct xattr_item *parse_one_xattr(const char *path, const char *key,
@@ -1198,7 +1205,7 @@ int erofs_getxattr(struct erofs_inode *vi, const char *name, char *buffer,
if (ret)
return ret;
- if (!match_prefix(name, &prefix, &prefixlen))
+ if (!match_base_prefix(name, &prefix, &prefixlen))
return -ENODATA;
it.it.sbi = vi->sbi;
--
2.19.1.6.gb485710b
More information about the Linux-erofs
mailing list