summaryrefslogtreecommitdiffstats
path: root/libflash
diff options
context:
space:
mode:
authorCyril Bur <cyril.bur@au1.ibm.com>2017-09-28 10:59:54 +1000
committerStewart Smith <stewart@linux.vnet.ibm.com>2017-09-27 23:02:52 -0500
commitc06ed583d05d8c8b86584b3c4afda71adbd5301a (patch)
treeee029eaa1443d3386313301f3228def719673e03 /libflash
parentec5fa9960ffb8e7299f4eb4370bff6f1c3ac9e44 (diff)
downloadtalos-skiboot-c06ed583d05d8c8b86584b3c4afda71adbd5301a.tar.gz
talos-skiboot-c06ed583d05d8c8b86584b3c4afda71adbd5301a.zip
libflash/file: Handle short read()s and write()s correctly
Currently we don't move the buffer along for a short read() or write() and nor do we request only the remaining amount. Fixes: c7c3a4cd53d libflash/file: Add a file access backend to for the blocklevel interface. Signed-off-by: Cyril Bur <cyril.bur@au1.ibm.com> Reviewed-by: Suraj Jitindar Singh <sjitindarsingh@gmail.com> Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
Diffstat (limited to 'libflash')
-rw-r--r--libflash/file.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/libflash/file.c b/libflash/file.c
index 7065eb4f..49f61778 100644
--- a/libflash/file.c
+++ b/libflash/file.c
@@ -72,11 +72,12 @@ static int file_read(struct blocklevel_device *bl, uint64_t pos, void *buf, uint
return FLASH_ERR_PARM_ERROR;
while (count < len) {
- rc = read(file_data->fd, buf, len);
+ rc = read(file_data->fd, buf, len - count);
/* errno should remain set */
if (rc == -1 || rc == 0)
return FLASH_ERR_BAD_READ;
+ buf += rc;
count += rc;
}
@@ -95,11 +96,12 @@ static int file_write(struct blocklevel_device *bl, uint64_t dst, const void *sr
return FLASH_ERR_PARM_ERROR;
while (count < len) {
- rc = write(file_data->fd, src, len);
+ rc = write(file_data->fd, src, len - count);
/* errno should remain set */
if (rc == -1)
return FLASH_ERR_VERIFY_FAILURE;
+ src += rc;
count += rc;
}
OpenPOWER on IntegriCloud