Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 73E75EE3EC1 for ; Sat, 9 Sep 2023 16:33:29 +0000 (UTC) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Rjdp0177sz3c2w for ; Sun, 10 Sep 2023 02:33:28 +1000 (AEST) Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.alibaba.com (client-ip=115.124.30.97; helo=out30-97.freemail.mail.aliyun.com; envelope-from=hsiangkao@linux.alibaba.com; receiver=lists.ozlabs.org) Received: from out30-97.freemail.mail.aliyun.com (out30-97.freemail.mail.aliyun.com [115.124.30.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4Rjdnd6qFvz3cGk for ; Sun, 10 Sep 2023 02:33:09 +1000 (AEST) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R161e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046050;MF=hsiangkao@linux.alibaba.com;NM=1;PH=DS;RN=3;SR=0;TI=SMTPD_---0VrfyqUx_1694277183; Received: from e18g06460.et15sqa.tbsite.net(mailfrom:hsiangkao@linux.alibaba.com fp:SMTPD_---0VrfyqUx_1694277183) by smtp.aliyun-inc.com; Sun, 10 Sep 2023 00:33:04 +0800 From: Gao Xiang To: linux-erofs@lists.ozlabs.org Subject: [PATCH v7 08/13] erofs-utils: lib: add erofs_read_xattrs_from_disk() helper Date: Sun, 10 Sep 2023 00:32:35 +0800 Message-Id: <20230909163240.42057-9-hsiangkao@linux.alibaba.com> X-Mailer: git-send-email 2.24.4 In-Reply-To: <20230909163240.42057-1-hsiangkao@linux.alibaba.com> References: <20230909163240.42057-1-hsiangkao@linux.alibaba.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: linux-erofs@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development of Linux EROFS file system List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Gao Xiang Errors-To: linux-erofs-bounces+linux-erofs=archiver.kernel.org@lists.ozlabs.org Sender: "Linux-erofs" From: Jingbo Xu Add erofs_read_xattrs_from_disk() helper to reading extended attributes from disk. Signed-off-by: Jingbo Xu Signed-off-by: Gao Xiang --- 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 ba4d6c6..c711c71 100644 --- a/include/erofs/internal.h +++ b/include/erofs/internal.h @@ -192,6 +192,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 d755760..5ed0f0f 100644 --- a/lib/xattr.c +++ b/lib/xattr.c @@ -558,6 +558,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; +} + int erofs_prepare_xattr_ibody(struct erofs_inode *inode) { int ret; -- 2.24.4