Skip to contentSkip to conversation

erofs-utils: fix erofs_io_p{read,write} and erofs_dev_close

PATCH New Gao Xiang 1 participant 1 message Jun 19, 2024 Library code

lore
Share & tools
lore

Gao Xiang

author
#0 lore raw

PATCH v4 1/1 erofs-utils: fix erofs_io_p{read,write} and erofs_dev_close

From: Hongzhen Luo <[email protected]>

erofs_io_p{read,write} should return the number of bytes successfully {read,wrrite}.

This also fixes erofs_dev_close which could close random fds if vf->ops is NULL.

---
v3: https://lore.kernel.org/r/[email protected]
v4:
- minor cleanups for applying.

 include/erofs/internal.h |  4 ++-
 lib/io.c                 | 62 +++++++++++++++++++++++++---------------
 2 files changed, 42 insertions(+), 24 deletions(-)
include/erofs/internal.h +3 -1
index 1d6496a..f61a453 100644
@@ -465,7 +465,9 @@ ssize_t erofs_dev_read(struct erofs_sb_info *sbi, int device_id,
 static inline int erofs_dev_write(struct erofs_sb_info *sbi, const void *buf,
 				  u64 offset, size_t len)
 {
-	return erofs_io_pwrite(&sbi->bdev, buf, offset, len);
+	if (erofs_io_pwrite(&sbi->bdev, buf, offset, len) != (ssize_t)len)
+		return -EIO;
+	return 0;
 }
 
 static inline int erofs_dev_fillzero(struct erofs_sb_info *sbi, u64 offset,
lib/io.c +39 -23

119 lines not on this page · raw message

Signature · 1 line
2.39.3