[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v6 2/4] hw/core/loader.c: Read as long as possible i
From: |
Li Zhijian |
Subject: |
[Qemu-devel] [PATCH v6 2/4] hw/core/loader.c: Read as long as possible in load_image_size() |
Date: |
Thu, 17 Jan 2019 20:49:02 +0800 |
Don't expect read(2) can always read as many as it's told.
CC: Richard Henderson <address@hidden>
CC: Stefano Garzarella <address@hidden>
Signed-off-by: Li Zhijian <address@hidden>
Reviewed-by: Richard Henderson <address@hidden>
Reviewed-by: Stefano Garzarella <address@hidden>
---
V5: update subject and add reviewed-by tag (Stefano Garzarella)
V4: add reviewed-by tag
---
hw/core/loader.c | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/hw/core/loader.c b/hw/core/loader.c
index c4f62fe..bf2951f 100644
--- a/hw/core/loader.c
+++ b/hw/core/loader.c
@@ -77,21 +77,20 @@ int64_t get_image_size(const char *filename)
ssize_t load_image_size(const char *filename, void *addr, size_t size)
{
int fd;
- ssize_t actsize;
+ ssize_t actsize, l = 0;
fd = open(filename, O_RDONLY | O_BINARY);
if (fd < 0) {
return -1;
}
- actsize = read(fd, addr, size);
- if (actsize < 0) {
- close(fd);
- return -1;
+ while ((actsize = read(fd, addr + l, size - l)) > 0) {
+ l += actsize;
}
+
close(fd);
- return actsize;
+ return actsize < 0 ? -1 : l;
}
/* read()-like version */
--
2.7.4
- [Qemu-devel] [PATCH v6 0/4] allow to load initrd below 4G for recent kernel, Li Zhijian, 2019/01/17
- [Qemu-devel] [PATCH v6 1/4] unify len and addr type for memory/address APIs, Li Zhijian, 2019/01/17
- [Qemu-devel] [PATCH v6 4/4] i386: allow to load initrd below 4 GB for recent linux, Li Zhijian, 2019/01/17
- [Qemu-devel] [PATCH v6 3/4] i386: import & use bootparam.h, Li Zhijian, 2019/01/17
- [Qemu-devel] [PATCH v6 2/4] hw/core/loader.c: Read as long as possible in load_image_size(),
Li Zhijian <=
- Re: [Qemu-devel] [PATCH v6 0/4] allow to load initrd below 4G for recent kernel, Paolo Bonzini, 2019/01/21
- Re: [Qemu-devel] [PATCH v6 0/4] allow to load initrd below 4G for recent kernel, no-reply, 2019/01/31