Linux-EROFS Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Jingbo Xu <jefflexu@linux.alibaba.com>
To: linux-erofs@lists.ozlabs.org, hsiangkao@linux.alibaba.com
Subject: [PATCH 4/6] erofs-utils: introduce init/cleanup routine for extra xattr name prefix
Date: Tue,  4 Apr 2023 16:02:21 +0800	[thread overview]
Message-ID: <20230404080224.77577-5-jefflexu@linux.alibaba.com> (raw)
In-Reply-To: <20230404080224.77577-1-jefflexu@linux.alibaba.com>

Introduce helpers for registering and cleaning up extra xattr name
prefix.

Signed-off-by: Jingbo Xu <jefflexu@linux.alibaba.com>
---
 include/erofs/xattr.h |  3 +++
 lib/xattr.c           | 58 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 61 insertions(+)

diff --git a/include/erofs/xattr.h b/include/erofs/xattr.h
index 9efadc5..1085908 100644
--- a/include/erofs/xattr.h
+++ b/include/erofs/xattr.h
@@ -70,6 +70,9 @@ int erofs_prepare_xattr_ibody(struct erofs_inode *inode);
 char *erofs_export_xattr_ibody(struct list_head *ixattrs, unsigned int size);
 int erofs_build_shared_xattrs_from_path(const char *path);
 
+int erofs_insert_ea_type(const char *prefix);
+void erofs_cleanup_ea_type(void);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/lib/xattr.c b/lib/xattr.c
index a292f2c..ec40aad 100644
--- a/lib/xattr.c
+++ b/lib/xattr.c
@@ -61,6 +61,14 @@ static struct xattr_prefix {
 	}
 };
 
+struct ea_type_node {
+	struct list_head list;
+	struct xattr_prefix type;
+	u8 index;
+};
+static LIST_HEAD(ea_types);
+static unsigned int ea_types_count;
+
 static unsigned int BKDRHash(char *str, unsigned int len)
 {
 	const unsigned int seed = 131313;
@@ -1222,3 +1230,53 @@ int erofs_listxattr(struct erofs_inode *vi, char *buffer, size_t buffer_size)
 		return ret;
 	return shared_listxattr(vi, &it);
 }
+
+int erofs_insert_ea_type(const char *prefix)
+{
+	struct ea_type_node *tnode;
+	struct xattr_prefix *p;
+	bool matched = false;
+	char *s;
+
+	if (ea_types_count == EROFS_XATTR_EA_FLAG || strlen(prefix) > UINT8_MAX)
+		return -EOVERFLOW;
+
+	for (p = xattr_types; p < xattr_types + ARRAY_SIZE(xattr_types); ++p) {
+		if (!strncmp(p->prefix, prefix, p->prefix_len)) {
+			matched = true;
+			break;
+		}
+	}
+	if (!matched)
+		return -ENODATA;
+
+	s = strdup(prefix);
+	if (!s)
+		return -ENOMEM;
+
+	tnode = malloc(sizeof(*tnode));
+	if (!tnode) {
+		free(s);
+		return -ENOMEM;
+	}
+
+	tnode->type.prefix = s;
+	tnode->type.prefix_len = strlen(prefix);
+
+	tnode->index = EROFS_XATTR_EA_FLAG | ea_types_count;
+	ea_types_count++;
+	init_list_head(&tnode->list);
+	list_add_tail(&tnode->list, &ea_types);
+	return 0;
+}
+
+void erofs_cleanup_ea_type(void)
+{
+	struct ea_type_node *tnode, *n;
+
+	list_for_each_entry_safe(tnode, n, &ea_types, list) {
+		list_del(&tnode->list);
+		free(tnode->type.prefix);
+		free(tnode);
+	}
+}
-- 
2.19.1.6.gb485710b


  parent reply	other threads:[~2023-04-04  8:02 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-04  8:02 [PATCH 0/6] erofs-utils: introduce extra xattr name prefix Jingbo Xu
2023-04-04  8:02 ` [PATCH 1/6] erofs-utils: declare prefix_len as u8 Jingbo Xu
2023-04-04  8:02 ` [PATCH 2/6] erofs-utils: extract packedfile API Jingbo Xu
2023-04-04  8:02 ` [PATCH 3/6] erofs-utils: introduce on-disk format for extra xattr name prefix Jingbo Xu
2023-04-04  8:19   ` Gao Xiang
2023-04-04  8:02 ` Jingbo Xu [this message]
2023-04-04  8:02 ` [PATCH 5/6] erofs-utils: build erofs_xattr_entry upon " Jingbo Xu
2023-04-04  8:02 ` [PATCH 6/6] erofs-utils: mkfs.erofs: introduce --xattr-prefix option Jingbo Xu
2023-04-04  8:02 ` [PATCH] tmp debug Jingbo Xu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230404080224.77577-5-jefflexu@linux.alibaba.com \
    --to=jefflexu@linux.alibaba.com \
    --cc=hsiangkao@linux.alibaba.com \
    --cc=linux-erofs@lists.ozlabs.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox