Skip to contentSkip to conversation

erofs-utils: fix the erofs_io_pread and erofs_io_pwrite

PATCH New Hongzhen Luo 1 participant 1 message Jun 18, 2024 Library code

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 erofs-utils: fix the erofs_io_pread and erofs_io_pwrite

When vf->ops is not null, vf->ops->pread returns the number of bytes successfully read, which is inconsistent with the semantics of erofs_io_pread. Similar situation occurs in erofs_io_pwrite. This fixes this issue.

This also fixes erofs_dev_close.

---
v2: https://lore.kernel.org/all/[email protected]/
v1: https://lore.kernel.org/all/[email protected]/

---
 include/erofs/internal.h |  5 ++++-
 lib/io.c                 | 47 ++++++++++++++++++++++++++++++----------
 2 files changed, 40 insertions(+), 12 deletions(-)
include/erofs/internal.h +4 -1
index f8a01ce..dfbd958 100644
@@ -460,7 +460,10 @@ 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);
+	ssize_t ret;
+
+	ret = erofs_io_pwrite(&sbi->bdev, buf, offset, len);
+	return (size_t)ret == len ? 0 : -EIO;
 }
 
 static inline int erofs_dev_fillzero(struct erofs_sb_info *sbi, u64 offset,
lib/io.c +36 -11

105 lines not on this page · raw message

Signature · 1 line
2.39.3