Prepare for the feature of exporting extended attributes for
`fsck.erofs`.

Signed-off-by: Hongzhen Luo <hongz...@linux.alibaba.com>
---
v5: No changes.
v4: 
https://lore.kernel.org/all/20240913064913.537850-1-hongz...@linux.alibaba.com/
v3: 
https://lore.kernel.org/all/20240912131108.3742683-1-hongz...@linux.alibaba.com/
v2: 
https://lore.kernel.org/all/20240906095853.3167228-1-hongz...@linux.alibaba.com/
v1: 
https://lore.kernel.org/all/20240906083849.3090392-1-hongz...@linux.alibaba.com/
---
 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.43.5

Reply via email to