aboutsummaryrefslogtreecommitdiff
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-10-11 14:12:28 +1100
commit45ae411cfdadfd2173cb34c665ccaf26d98a0729 (patch)
tree36112fcdd15dd2e8f50897c60b62d6d5eb089af7
parent6c96f3b13a4901ae7e060203cfa26d2c7ccc68a4 (diff)
downloadskiboot-45ae411cfdadfd2173cb34c665ccaf26d98a0729.zip
skiboot-45ae411cfdadfd2173cb34c665ccaf26d98a0729.tar.gz
skiboot-45ae411cfdadfd2173cb34c665ccaf26d98a0729.tar.bz2
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> (cherry picked from commit c06ed583d05d8c8b86584b3c4afda71adbd5301a) Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
-rw-r--r--libflash/file.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/libflash/file.c b/libflash/file.c
index 5f074cf..aad02f1 100644
--- a/libflash/file.c
+++ b/libflash/file.c
@@ -70,11 +70,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;
}
@@ -93,11 +94,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;
}