From: Jingbo Xu <jefflexu@linux.alibaba.com>
To: linux-erofs@lists.ozlabs.org, hsiangkao@linux.alibaba.com
Subject: [PATCH 5/6] erofs-utils: build erofs_xattr_entry upon extra xattr name prefix
Date: Tue, 4 Apr 2023 16:02:22 +0800 [thread overview]
Message-ID: <20230404080224.77577-6-jefflexu@linux.alibaba.com> (raw)
In-Reply-To: <20230404080224.77577-1-jefflexu@linux.alibaba.com>
Build the xattr entry also considering the extra xattr name prefix. The
user specified extra xattr name prefix takes precedence over the
predefined xattr name prefix.
Signed-off-by: Jingbo Xu <jefflexu@linux.alibaba.com>
---
include/erofs/internal.h | 3 +++
lib/xattr.c | 44 ++++++++++++++++++++++++++++++++++++++++
mkfs/main.c | 2 ++
3 files changed, 49 insertions(+)
diff --git a/include/erofs/internal.h b/include/erofs/internal.h
index 641a795..f441429 100644
--- a/include/erofs/internal.h
+++ b/include/erofs/internal.h
@@ -102,6 +102,9 @@ struct erofs_sb_info {
u16 device_id_mask; /* used for others */
};
erofs_nid_t packed_nid;
+
+ u32 ea_prefix_off;
+ u8 ea_prefix_count;
};
/* make sure that any user of the erofs headers has atleast 64bit off_t type */
diff --git a/lib/xattr.c b/lib/xattr.c
index ec40aad..f1db8bf 100644
--- a/lib/xattr.c
+++ b/lib/xattr.c
@@ -17,6 +17,7 @@
#include "erofs/xattr.h"
#include "erofs/cache.h"
#include "erofs/io.h"
+#include "erofs/fragments.h"
#include "liberofs_private.h"
#define EA_HASHTABLE_BITS 16
@@ -138,7 +139,16 @@ static struct xattr_item *get_xattritem(u8 prefix, char *kvbuf,
static bool match_prefix(const char *key, u8 *index, u16 *len)
{
struct xattr_prefix *p;
+ struct ea_type_node *tnode;
+ list_for_each_entry(tnode, &ea_types, list) {
+ p = &tnode->type;
+ if (p->prefix && !strncmp(p->prefix, key, p->prefix_len)) {
+ *len = p->prefix_len;
+ *index = tnode->index;
+ return true;
+ }
+ }
for (p = xattr_types; p < xattr_types + ARRAY_SIZE(xattr_types); ++p) {
if (p->prefix && !strncmp(p->prefix, key, p->prefix_len)) {
*len = p->prefix_len;
@@ -587,6 +597,34 @@ static int comp_xattr_item(const void *a, const void *b)
return la > lb;
}
+static int erofs_xattr_write_ea_prefix(void)
+{
+ struct ea_type_node *tnode;
+ struct xattr_prefix *p;
+#ifdef HAVE_FTELLO64
+ off64_t offset = ftello64(packedfile);
+#else
+ off_t offset = ftello(packedfile);
+#endif
+
+ if (offset < 0)
+ return -errno;
+ if (offset > UINT32_MAX)
+ return -EOVERFLOW;
+
+ sbi.ea_prefix_count = ea_types_count;
+ sbi.ea_prefix_off = (u32)offset;
+
+ list_for_each_entry(tnode, &ea_types, list) {
+ p = &tnode->type;
+ if (fwrite(&p->prefix_len, sizeof(u8), 1, packedfile) != 1)
+ return -EIO;
+ if (fwrite(p->prefix, p->prefix_len + 1, 1, packedfile) != 1)
+ return -EIO;
+ }
+ return 0;
+}
+
int erofs_build_shared_xattrs_from_path(const char *path)
{
int ret;
@@ -610,6 +648,12 @@ int erofs_build_shared_xattrs_from_path(const char *path)
if (ret)
return ret;
+ if (ea_types_count) {
+ ret = erofs_xattr_write_ea_prefix();
+ if (ret)
+ return ret;
+ }
+
if (!shared_xattrs_size)
goto out;
diff --git a/mkfs/main.c b/mkfs/main.c
index 50fd908..56b100c 100644
--- a/mkfs/main.c
+++ b/mkfs/main.c
@@ -574,6 +574,8 @@ int erofs_mkfs_update_super_block(struct erofs_buffer_head *bh,
.blocks = 0,
.meta_blkaddr = sbi.meta_blkaddr,
.xattr_blkaddr = sbi.xattr_blkaddr,
+ .ea_prefix_count = sbi.ea_prefix_count,
+ .ea_prefix_off = cpu_to_le32(sbi.ea_prefix_off),
.feature_incompat = cpu_to_le32(sbi.feature_incompat),
.feature_compat = cpu_to_le32(sbi.feature_compat &
~EROFS_FEATURE_COMPAT_SB_CHKSUM),
--
2.19.1.6.gb485710b
next prev 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 ` [PATCH 4/6] erofs-utils: introduce init/cleanup routine " Jingbo Xu
2023-04-04 8:02 ` Jingbo Xu [this message]
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-6-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