aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJingbo Xu <jefflexu@linux.alibaba.com>2023-08-17 15:14:53 +0800
committerGao Xiang <hsiangkao@linux.alibaba.com>2023-08-17 19:21:08 +0800
commitac20be2c0d08d7e61d64e854ebbe23250e9ad0d2 (patch)
tree81dba0c571fb615ae56fb6a2c30a7e8d7195ea4c
parent1e429b74bff825f61c5f99cbf3d41369df77a831 (diff)
downloaderofs-utils-ac20be2c0d08d7e61d64e854ebbe23250e9ad0d2.tar.gz
erofs-utils: lib: add match_base_prefix() helper
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@linux.alibaba.com> Link: https://lore.kernel.org/r/20230817071455.12040-2-jefflexu@linux.alibaba.com Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
-rw-r--r--lib/xattr.c25
1 files 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;