All of lore.kernel.org
 help / color / mirror / Atom feed
From: Danny Lin via Linux-erofs <linux-erofs@lists.ozlabs.org>
To: linux-erofs@lists.ozlabs.org
Cc: Danny Lin <danny@orbstack.dev>
Subject: [PATCH] erofs-utils: lib: fix compressed packed inodes
Date: Mon, 16 Sep 2024 00:38:30 -0700	[thread overview]
Message-ID: <20240916073835.77470-1-danny@orbstack.dev> (raw)

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


             reply	other threads:[~2024-09-16  7:39 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-16  7:38 Danny Lin via Linux-erofs [this message]
2024-09-22  5:08 ` [PATCH] erofs-utils: lib: fix compressed packed inodes 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

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=20240916073835.77470-1-danny@orbstack.dev \
    --to=linux-erofs@lists.ozlabs.org \
    --cc=danny@orbstack.dev \
    /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.