diff options
author | Cyril Bur <cyril.bur@au1.ibm.com> | 2017-12-01 14:50:23 +1100 |
---|---|---|
committer | Stewart Smith <stewart@linux.vnet.ibm.com> | 2017-12-18 17:58:32 -0600 |
commit | 8e88ab0e66a201a1d786e7e95c98314bf4e806e7 (patch) | |
tree | 2134291df344bdfa2d9a15d1884516942c39e8ae | |
parent | b9774c47eecd0c90e503919432ec1e4a86355398 (diff) | |
download | talos-skiboot-8e88ab0e66a201a1d786e7e95c98314bf4e806e7.tar.gz talos-skiboot-8e88ab0e66a201a1d786e7e95c98314bf4e806e7.zip |
pflash: Respect write(2) return values
The write(2) system call returns the number of bytes written, this is
important since it is entitled to write less than what we requested.
Currently we ignore the return value and assume it wrote everything we
requested. While in practice this is likely to always be the case, it
isn't actually correct.
This patch addresses this.
Signed-off-by: Cyril Bur <cyril.bur@au1.ibm.com>
Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
-rw-r--r-- | external/pflash/pflash.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/external/pflash/pflash.c b/external/pflash/pflash.c index b3ceef0c..3ac94849 100644 --- a/external/pflash/pflash.c +++ b/external/pflash/pflash.c @@ -501,13 +501,18 @@ static int do_read_file(struct blocklevel_device *bl, const char *file, break; } rc = write(fd, file_buf, len); - if (rc < 0) { + /* + * zero isn't strictly an error. + * Treat it as such so we can be sure we'lre always + * making forward progress. + */ + if (rc <= 0) { perror("Error writing file"); break; } - start += len; - size -= len; - done += len; + start += rc; + size -= rc; + done += rc; progress_tick(done >> 8); } progress_end(); |