From 1a54ae7248a2bd31e1ae1451042c94af07a33e42 Mon Sep 17 00:00:00 2001 From: Hongzhen Luo Date: Fri, 13 Sep 2024 15:20:59 +0800 Subject: [PATCH] erofs-utils: lib: expose erofs_xattr_prefix_matches() Prepare for the feature of exporting extended attributes for `fsck.erofs`. Signed-off-by: Hongzhen Luo Link: https://lore.kernel.org/r/20240913072100.577753-1-hongzhen@linux.alibaba.com Signed-off-by: Gao Xiang --- include/erofs/xattr.h | 3 +++ lib/xattr.c | 12 +++++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/include/erofs/xattr.h b/include/erofs/xattr.h index 7643611..804f565 100644 --- a/include/erofs/xattr.h +++ b/include/erofs/xattr.h @@ -61,6 +61,9 @@ void erofs_clear_opaque_xattr(struct erofs_inode *inode); int erofs_set_origin_xattr(struct erofs_inode *inode); int erofs_read_xattrs_from_disk(struct erofs_inode *inode); +bool erofs_xattr_prefix_matches(const char *key, unsigned int *index, + unsigned int *len); + #ifdef __cplusplus } #endif diff --git a/lib/xattr.c b/lib/xattr.c index 9f31f2d..63c7fce 100644 --- a/lib/xattr.c +++ b/lib/xattr.c @@ -138,8 +138,8 @@ struct ea_type_node { static LIST_HEAD(ea_name_prefixes); static unsigned int ea_prefix_count; -static bool match_prefix(const char *key, unsigned int *index, - unsigned int *len) +bool erofs_xattr_prefix_matches(const char *key, unsigned int *index, + unsigned int *len) { struct xattr_prefix *p; @@ -196,7 +196,8 @@ static struct xattr_item *get_xattritem(char *kvbuf, unsigned int len[2]) if (!item) return ERR_PTR(-ENOMEM); - if (!match_prefix(kvbuf, &item->base_index, &item->prefix_len)) { + if (!erofs_xattr_prefix_matches(kvbuf, &item->base_index, + &item->prefix_len)) { free(item); return ERR_PTR(-ENODATA); } @@ -1425,7 +1426,7 @@ int erofs_getxattr(struct erofs_inode *vi, const char *name, char *buffer, if (ret) return ret; - if (!match_prefix(name, &prefix, &prefixlen)) + if (!erofs_xattr_prefix_matches(name, &prefix, &prefixlen)) return -ENODATA; it.it.sbi = vi->sbi; @@ -1600,7 +1601,8 @@ int erofs_xattr_insert_name_prefix(const char *prefix) if (!tnode) return -ENOMEM; - if (!match_prefix(prefix, &tnode->base_index, &tnode->base_len)) { + if (!erofs_xattr_prefix_matches(prefix, &tnode->base_index, + &tnode->base_len)) { free(tnode); return -ENODATA; } -- 2.34.1