erofs-utils: lib: expose erofs_xattr_prefix_matches()
authorHongzhen Luo <hongzhen@linux.alibaba.com>
Fri, 13 Sep 2024 07:20:59 +0000 (15:20 +0800)
committerGao Xiang <hsiangkao@linux.alibaba.com>
Fri, 13 Sep 2024 07:32:32 +0000 (15:32 +0800)
Prepare for the feature of exporting extended attributes for
`fsck.erofs`.

Signed-off-by: Hongzhen Luo <hongzhen@linux.alibaba.com>
Link: https://lore.kernel.org/r/20240913072100.577753-1-hongzhen@linux.alibaba.com
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
include/erofs/xattr.h
lib/xattr.c

index 7643611d6c113518727c92a38c6abc0002775284..804f56590ba34992f8f0bfac51df2ae9ef102160 100644 (file)
@@ -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
index 9f31f2d0a7d7d20da12d10d883b9332155e9cd1c..63c7fce7fc257ea556e33e1346d53c1fe85ffc78 100644 (file)
@@ -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;
        }