[PATCH v2] erofs-utils: lib: fix compressed packed inodes
danny at orbstack.dev
danny at orbstack.dev
Mon Sep 23 15:17:29 AEST 2024
From: Danny Lin <danny at orbstack.dev>
Commit 2fdbd28 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: 2fdbd28 ("erofs-utils: lib: fix uncompressed packed inode")
Co-authored-by: Gao Xiang <hsiangkao at linux.alibaba.com>
Signed-off-by: Danny Lin <danny at orbstack.dev>
---
lib/inode.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/lib/inode.c b/lib/inode.c
index bc3cb76..4c37a0d 100644
--- a/lib/inode.c
+++ b/lib/inode.c
@@ -1927,7 +1927,9 @@ 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)
+ if (!ret)
+ goto out;
+ if (ret != -ENOSPC)
return ERR_PTR(ret);
ret = lseek(fd, 0, SEEK_SET);
@@ -1937,6 +1939,7 @@ struct erofs_inode *erofs_mkfs_build_special_from_fd(struct erofs_sb_info *sbi,
ret = write_uncompressed_file_from_fd(inode, fd);
if (ret)
return ERR_PTR(ret);
+out:
erofs_prepare_inode_buffer(inode);
erofs_write_tail_end(inode);
return inode;
--
2.46.1
More information about the Linux-erofs
mailing list