From: Jingbo Xu <jefflexu@linux.alibaba.com>
To: hsiangkao@linux.alibaba.com, linux-erofs@lists.ozlabs.org
Subject: [PATCH v8 3/8] erofs-utils: lib: add erofs_read_xattrs_from_disk() helper
Date: Wed, 13 Sep 2023 20:02:58 +0800 [thread overview]
Message-ID: <20230913120304.15741-4-jefflexu@linux.alibaba.com> (raw)
In-Reply-To: <20230913120304.15741-1-jefflexu@linux.alibaba.com>
Add erofs_read_xattrs_from_disk() helper to reading extended
attributes from disk.
Signed-off-by: Jingbo Xu <jefflexu@linux.alibaba.com>
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
---
include/erofs/internal.h | 1 +
include/erofs/xattr.h | 1 +
lib/xattr.c | 69 ++++++++++++++++++++++++++++++++++++++++
3 files changed, 71 insertions(+)
diff --git a/include/erofs/internal.h b/include/erofs/internal.h
index c36bb24..3b866c9 100644
--- a/include/erofs/internal.h
+++ b/include/erofs/internal.h
@@ -196,6 +196,7 @@ struct erofs_inode {
bool compressed_idata;
bool lazy_tailblock;
bool with_tmpfile;
+ bool opaque;
/* OVL: non-merge dir that may contain whiteout entries */
bool whiteouts;
diff --git a/include/erofs/xattr.h b/include/erofs/xattr.h
index 2ecb18e..0364f24 100644
--- a/include/erofs/xattr.h
+++ b/include/erofs/xattr.h
@@ -58,6 +58,7 @@ int erofs_setxattr(struct erofs_inode *inode, char *key,
const void *value, size_t size);
int erofs_set_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);
#ifdef __cplusplus
}
diff --git a/lib/xattr.c b/lib/xattr.c
index bf63a81..e3a1b44 100644
--- a/lib/xattr.c
+++ b/lib/xattr.c
@@ -566,6 +566,75 @@ int erofs_scan_file_xattrs(struct erofs_inode *inode)
return erofs_droid_xattr_set_caps(inode);
}
+int erofs_read_xattrs_from_disk(struct erofs_inode *inode)
+{
+ ssize_t kllen;
+ char *keylst, *key;
+ int ret;
+
+ init_list_head(&inode->i_xattrs);
+ kllen = erofs_listxattr(inode, NULL, 0);
+ if (kllen < 0)
+ return kllen;
+ if (kllen <= 1)
+ return 0;
+
+ keylst = malloc(kllen);
+ if (!keylst)
+ return -ENOMEM;
+
+ ret = erofs_listxattr(inode, keylst, kllen);
+ if (ret < 0)
+ goto out;
+
+ for (key = keylst; key < keylst + kllen; key += strlen(key) + 1) {
+ void *value = NULL;
+ size_t size = 0;
+
+ if (!strcmp(key, OVL_XATTR_OPAQUE)) {
+ if (!S_ISDIR(inode->i_mode)) {
+ erofs_dbg("file %s: opaque xattr on non-dir",
+ inode->i_srcpath);
+ ret = -EINVAL;
+ goto out;
+ }
+ inode->opaque = true;
+ }
+
+ ret = erofs_getxattr(inode, key, NULL, 0);
+ if (ret < 0)
+ goto out;
+ if (ret) {
+ size = ret;
+ value = malloc(size);
+ if (!value) {
+ ret = -ENOMEM;
+ goto out;
+ }
+
+ ret = erofs_getxattr(inode, key, value, size);
+ if (ret < 0) {
+ free(value);
+ goto out;
+ }
+ DBG_BUGON(ret != size);
+ } else if (S_ISDIR(inode->i_mode) &&
+ !strcmp(key, OVL_XATTR_ORIGIN)) {
+ ret = 0;
+ inode->whiteouts = true;
+ continue;
+ }
+
+ ret = erofs_setxattr(inode, key, value, size);
+ free(value);
+ if (ret)
+ break;
+ }
+out:
+ free(keylst);
+ return ret;
+}
+
static inline unsigned int erofs_next_xattr_align(unsigned int pos,
struct xattr_item *item)
{
--
2.19.1.6.gb485710b
next prev parent reply other threads:[~2023-09-13 12:03 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-13 12:02 [PATCH v8 0/8] erofs-utils: mkfs: introduce rebuild mode Jingbo Xu
2023-09-13 12:02 ` [PATCH v8 1/8] erofs-utils: lib: add list_splice_tail() helper Jingbo Xu
2023-09-13 12:02 ` [PATCH v8 2/8] erofs-utils: lib: make erofs_get_unhashed_chunk() global Jingbo Xu
2023-09-13 12:02 ` Jingbo Xu [this message]
2023-09-13 12:02 ` [PATCH v8 4/8] erofs-utils: lib: add erofs_insert_ihash() helper Jingbo Xu
2023-09-13 12:03 ` [PATCH v8 5/8] erofs-utils: lib: add erofs_rebuild_get_dentry() helper Jingbo Xu
2023-09-13 12:03 ` [PATCH v8 6/8] erofs-utils: lib: add erofs_rebuild_load_tree() helper Jingbo Xu
2023-09-13 12:03 ` [PATCH v8 7/8] erofs-utils: mkfs: introduce rebuild mode Jingbo Xu
2023-09-14 7:49 ` Gao Xiang
2023-09-13 12:03 ` [PATCH v8 8/8] erofs-utils: mkfs: add `--ovlfs-strip` option Jingbo Xu
2023-09-13 13:47 ` Gao Xiang
2023-09-13 12:03 ` [PATCH v3] erofs-utils: lib: refactor extended attribute name prefixes Jingbo Xu
2023-09-13 12:13 ` 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=20230913120304.15741-4-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.