All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] erofs-utils: lib: fix compressed packed inodes
@ 2024-09-16  7:38 Danny Lin via Linux-erofs
  2024-09-22  5:08 ` Danny Lin via Linux-erofs
  0 siblings, 1 reply; 9+ messages in thread
From: Danny Lin via Linux-erofs @ 2024-09-16  7:38 UTC (permalink / raw)
  To: linux-erofs; +Cc: Danny Lin

Commit b9b6493 fixed uncompressed packed inodes by not always writing
compressed data, but it broke compressed packed inodes because now
uncompressed file data is always written after the compressed data.

The new error handling always rewinds with lseek and falls through to
write_uncompressed_file_from_fd, regardless of whether the compressed
data was written successfully (ret = 0) or not (ret = -ENOSPC). This
can result in corrupted files.

Fix it by simplifying the error handling to better match the old code.

Fixes: b9b6493 ("erofs-utils: lib: fix uncompressed packed inode")
Signed-off-by: Danny Lin <danny@orbstack.dev>
---
 lib/inode.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/lib/inode.c b/lib/inode.c
index bc3cb76..797c622 100644
--- a/lib/inode.c
+++ b/lib/inode.c
@@ -1927,14 +1927,16 @@ struct erofs_inode *erofs_mkfs_build_special_from_fd(struct erofs_sb_info *sbi,
 
 		DBG_BUGON(!ictx);
 		ret = erofs_write_compressed_file(ictx);
-		if (ret && ret != -ENOSPC)
-			 return ERR_PTR(ret);
+		if (ret == -ENOSPC) {
+			ret = lseek(fd, 0, SEEK_SET);
+			if (ret < 0)
+				return ERR_PTR(-errno);
 
-		ret = lseek(fd, 0, SEEK_SET);
-		if (ret < 0)
-			return ERR_PTR(-errno);
+			ret = write_uncompressed_file_from_fd(inode, fd);
+		}
+	} else {
+		ret = write_uncompressed_file_from_fd(inode, fd);
 	}
-	ret = write_uncompressed_file_from_fd(inode, fd);
 	if (ret)
 		return ERR_PTR(ret);
 	erofs_prepare_inode_buffer(inode);
-- 
2.46.0


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

end of thread, other threads:[~2024-09-23  5:32 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-16  7:38 [PATCH] erofs-utils: lib: fix compressed packed inodes Danny Lin via Linux-erofs
2024-09-22  5:08 ` Danny Lin via Linux-erofs
2024-09-23  0:08   ` Gao Xiang
2024-09-23  3:03     ` Gao Xiang
2024-09-23  4:30       ` Danny Lin via Linux-erofs
2024-09-23  4:36         ` Danny Lin via Linux-erofs
2024-09-23  5:02           ` Gao Xiang
2024-09-23  5:17           ` [PATCH v2] " danny--- via Linux-erofs
2024-09-23  5:32             ` Gao Xiang

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.