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

Signed-off-by: Hongzhen Luo <[email protected]>
---
v2: Expose erofs_match_prefix() directly instead of introducing another helper 
function.
v1: 
https://lore.kernel.org/all/[email protected]/
---
 include/erofs/xattr.h |  3 +++
 lib/xattr.c           | 11 ++++++-----
 2 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/include/erofs/xattr.h b/include/erofs/xattr.h
index 7643611..e89172e 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_match_prefix(const char *key, unsigned int *index,
+                       unsigned int *len);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/lib/xattr.c b/lib/xattr.c
index 9f31f2d..375a658 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_match_prefix(const char *key, unsigned int *index,
+                       unsigned int *len)
 {
        struct xattr_prefix *p;
 
@@ -196,7 +196,7 @@ 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_match_prefix(kvbuf, &item->base_index, &item->prefix_len)) {
                free(item);
                return ERR_PTR(-ENODATA);
        }
@@ -1425,7 +1425,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_match_prefix(name, &prefix, &prefixlen))
                return -ENODATA;
 
        it.it.sbi = vi->sbi;
@@ -1600,7 +1600,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_match_prefix(prefix, &tnode->base_index,
+                               &tnode->base_len)) {
                free(tnode);
                return -ENODATA;
        }
-- 
2.43.5

Reply via email to