linux-erofs.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] erofs-utils: fsck: extract chunk-based file with hole correctly
@ 2024-04-22 10:05 Yifan Zhao
  2024-04-22 10:28 ` Gao Xiang
  2024-04-22 11:31 ` [PATCH v2] " Yifan Zhao
  0 siblings, 2 replies; 4+ messages in thread
From: Yifan Zhao @ 2024-04-22 10:05 UTC (permalink / raw)
  To: linux-erofs; +Cc: Yifan Zhao

Currently fsck skips file extraction if it finds that EROFS_MAP_MAPPED
is unset, which is not the case for chunk-based files with hole. This
patch handles the corner case correctly.

Signed-off-by: Yifan Zhao <zhaoyifan@sjtu.edu.cn>
---
 fsck/main.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/fsck/main.c b/fsck/main.c
index e5c37be..c10b68e 100644
--- a/fsck/main.c
+++ b/fsck/main.c
@@ -470,7 +470,7 @@ static int erofs_verify_inode_data(struct erofs_inode *inode, int outfd)
 		pos += map.m_llen;
 
 		/* should skip decomp? */
-		if (!(map.m_flags & EROFS_MAP_MAPPED) || !fsckcfg.check_decomp)
+		if (map.m_la >= inode->i_size || !fsckcfg.check_decomp)
 			continue;
 
 		if (map.m_plen > Z_EROFS_PCLUSTER_MAX_SIZE) {
@@ -517,9 +517,14 @@ static int erofs_verify_inode_data(struct erofs_inode *inode, int outfd)
 				u64 count = min_t(u64, alloc_rawsize,
 						  map.m_llen);
 
-				ret = erofs_read_one_data(inode, &map, raw, p, count);
-				if (ret)
-					goto out;
+				if (!(map.m_flags & EROFS_MAP_MAPPED)) {
+					memset(raw, 0, count);
+				} else {
+					ret = erofs_read_one_data(
+						inode, &map, raw, p, count);
+					if (ret)
+						goto out;
+				}
 
 				if (outfd >= 0 && write(outfd, raw, count) < 0)
 					goto fail_eio;
-- 
2.44.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] erofs-utils: fsck: extract chunk-based file with hole correctly
  2024-04-22 10:05 [PATCH] erofs-utils: fsck: extract chunk-based file with hole correctly Yifan Zhao
@ 2024-04-22 10:28 ` Gao Xiang
  2024-04-22 11:31 ` [PATCH v2] " Yifan Zhao
  1 sibling, 0 replies; 4+ messages in thread
From: Gao Xiang @ 2024-04-22 10:28 UTC (permalink / raw)
  To: Yifan Zhao, linux-erofs



On 2024/4/22 18:05, Yifan Zhao wrote:
> Currently fsck skips file extraction if it finds that EROFS_MAP_MAPPED
> is unset, which is not the case for chunk-based files with hole. This
> patch handles the corner case correctly.
> 
> Signed-off-by: Yifan Zhao <zhaoyifan@sjtu.edu.cn>
> ---
>   fsck/main.c | 13 +++++++++----
>   1 file changed, 9 insertions(+), 4 deletions(-)
> 
> diff --git a/fsck/main.c b/fsck/main.c
> index e5c37be..c10b68e 100644
> --- a/fsck/main.c
> +++ b/fsck/main.c
> @@ -470,7 +470,7 @@ static int erofs_verify_inode_data(struct erofs_inode *inode, int outfd)
>   		pos += map.m_llen;
>   
>   		/* should skip decomp? */
> -		if (!(map.m_flags & EROFS_MAP_MAPPED) || !fsckcfg.check_decomp)
> +		if (map.m_la >= inode->i_size || !fsckcfg.check_decomp)
>   			continue;
>   
>   		if (map.m_plen > Z_EROFS_PCLUSTER_MAX_SIZE) {
> @@ -517,9 +517,14 @@ static int erofs_verify_inode_data(struct erofs_inode *inode, int outfd)
>   				u64 count = min_t(u64, alloc_rawsize,
>   						  map.m_llen);
>   
> -				ret = erofs_read_one_data(inode, &map, raw, p, count);
> -				if (ret)
> -					goto out;
> +				if (!(map.m_flags & EROFS_MAP_MAPPED)) {
> +					memset(raw, 0, count);

I think we could use lseek instead of write
zeros explicitly..


Thanks,
Gao Xiang

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2] erofs-utils: fsck: extract chunk-based file with hole correctly
  2024-04-22 10:05 [PATCH] erofs-utils: fsck: extract chunk-based file with hole correctly Yifan Zhao
  2024-04-22 10:28 ` Gao Xiang
@ 2024-04-22 11:31 ` Yifan Zhao
  2024-04-24  6:02   ` Gao Xiang
  1 sibling, 1 reply; 4+ messages in thread
From: Yifan Zhao @ 2024-04-22 11:31 UTC (permalink / raw)
  To: linux-erofs; +Cc: Yifan Zhao

Currently fsck skips file extraction if it finds that EROFS_MAP_MAPPED
is unset, which is not the case for chunk-based files with hole. This
patch handles the corner case correctly.

Signed-off-by: Yifan Zhao <zhaoyifan@sjtu.edu.cn>
---
changelog since v1:
- use lseek instead of write zero to the hole

 fsck/main.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/fsck/main.c b/fsck/main.c
index e5c37be..249ccd4 100644
--- a/fsck/main.c
+++ b/fsck/main.c
@@ -470,7 +470,7 @@ static int erofs_verify_inode_data(struct erofs_inode *inode, int outfd)
 		pos += map.m_llen;
 
 		/* should skip decomp? */
-		if (!(map.m_flags & EROFS_MAP_MAPPED) || !fsckcfg.check_decomp)
+		if (map.m_la >= inode->i_size || !fsckcfg.check_decomp)
 			continue;
 
 		if (map.m_plen > Z_EROFS_PCLUSTER_MAX_SIZE) {
@@ -513,6 +513,15 @@ static int erofs_verify_inode_data(struct erofs_inode *inode, int outfd)
 		} else {
 			u64 p = 0;
 
+			if (!(map.m_flags & EROFS_MAP_MAPPED)) {
+				ret = lseek(outfd, map.m_llen, SEEK_CUR);
+				if (ret < 0) {
+					ret = -errno;
+					goto out;
+				}
+				continue;
+			}
+
 			do {
 				u64 count = min_t(u64, alloc_rawsize,
 						  map.m_llen);
-- 
2.44.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] erofs-utils: fsck: extract chunk-based file with hole correctly
  2024-04-22 11:31 ` [PATCH v2] " Yifan Zhao
@ 2024-04-24  6:02   ` Gao Xiang
  0 siblings, 0 replies; 4+ messages in thread
From: Gao Xiang @ 2024-04-24  6:02 UTC (permalink / raw)
  To: Yifan Zhao; +Cc: linux-erofs

On Mon, Apr 22, 2024 at 07:31:32PM +0800, Yifan Zhao wrote:
> Currently fsck skips file extraction if it finds that EROFS_MAP_MAPPED
> is unset, which is not the case for chunk-based files with hole. This
> patch handles the corner case correctly.
> 
> Signed-off-by: Yifan Zhao <zhaoyifan@sjtu.edu.cn>

I will apply the following version:

From 56e2f73cec3fa45d8b1dd1e9ec571b1f075d2275 Mon Sep 17 00:00:00 2001
From: Yifan Zhao <zhaoyifan@sjtu.edu.cn>
Date: Mon, 22 Apr 2024 19:31:32 +0800
Subject: [PATCH] erofs-utils: fsck: extract chunk-based file with hole correctly

Currently fsck skips file extraction if it finds that EROFS_MAP_MAPPED
is unset, which is not the case for chunk-based files with holes.

This patch handles the corner case correctly.

Signed-off-by: Yifan Zhao <zhaoyifan@sjtu.edu.cn>
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
---
 fsck/main.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/fsck/main.c b/fsck/main.c
index e5c37be..4dcb49d 100644
--- a/fsck/main.c
+++ b/fsck/main.c
@@ -470,9 +470,18 @@ static int erofs_verify_inode_data(struct erofs_inode *inode, int outfd)
 		pos += map.m_llen;
 
 		/* should skip decomp? */
-		if (!(map.m_flags & EROFS_MAP_MAPPED) || !fsckcfg.check_decomp)
+		if (map.m_la >= inode->i_size || !fsckcfg.check_decomp)
 			continue;
 
+		if (outfd >= 0 && !(map.m_flags & EROFS_MAP_MAPPED)) {
+			ret = lseek(outfd, map.m_llen, SEEK_CUR);
+			if (ret < 0) {
+				ret = -errno;
+				goto out;
+			}
+			continue;
+		}
+
 		if (map.m_plen > Z_EROFS_PCLUSTER_MAX_SIZE) {
 			if (compressed) {
 				erofs_err("invalid pcluster size %" PRIu64 " @ offset %" PRIu64 " of nid %" PRIu64,
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-04-24  6:02 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-22 10:05 [PATCH] erofs-utils: fsck: extract chunk-based file with hole correctly Yifan Zhao
2024-04-22 10:28 ` Gao Xiang
2024-04-22 11:31 ` [PATCH v2] " Yifan Zhao
2024-04-24  6:02   ` Gao Xiang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).