diff options
author | Tao Bao <tbao@google.com> | 2015-07-27 14:07:08 -0700 |
---|---|---|
committer | Steve Kondik <steve@cyngn.com> | 2015-11-07 19:02:26 -0800 |
commit | a0b7a8b4c77f764b564b9bd4283c61662f16e37d (patch) | |
tree | 47232453b8ab24f055ccb87540a736508d0fff1d /updater | |
parent | 41a859d9062c7877789089eaaa866090feda70f9 (diff) | |
download | bootable_recovery-a0b7a8b4c77f764b564b9bd4283c61662f16e37d.zip bootable_recovery-a0b7a8b4c77f764b564b9bd4283c61662f16e37d.tar.gz bootable_recovery-a0b7a8b4c77f764b564b9bd4283c61662f16e37d.tar.bz2 |
updater: Hoist fsync() to outer loop.
Currently the fsync() inside write_all() may be called multiple times
when performing a command. Move that to the outer loop and call it
only after completing the command.
Also remove the O_SYNC flag when writing a stash.
Change-Id: I71e51d76051a2f7f504eef1aa585d2cb7a000d80
Diffstat (limited to 'updater')
-rw-r--r-- | updater/blockimg.c | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/updater/blockimg.c b/updater/blockimg.c index e0be039..8b9519d 100644 --- a/updater/blockimg.c +++ b/updater/blockimg.c @@ -196,11 +196,6 @@ static int write_all(int fd, const uint8_t* data, size_t size) { written += w; } - if (fsync(fd) == -1) { - fprintf(stderr, "fsync failed: %s\n", strerror(errno)); - return -1; - } - return 0; } @@ -732,7 +727,7 @@ static int WriteStash(const char* base, const char* id, int blocks, uint8_t* buf fprintf(stderr, " writing %d blocks to %s\n", blocks, cn); - fd = TEMP_FAILURE_RETRY(open(fn, O_WRONLY | O_CREAT | O_TRUNC | O_SYNC, STASH_FILE_MODE)); + fd = TEMP_FAILURE_RETRY(open(fn, O_WRONLY | O_CREAT | O_TRUNC, STASH_FILE_MODE)); if (fd == -1) { fprintf(stderr, "failed to create \"%s\": %s\n", fn, strerror(errno)); @@ -1787,6 +1782,10 @@ static Value* PerformBlockImageUpdate(const char* name, State* state, int argc, } if (params.canwrite) { + if (fsync(params.fd) == -1) { + fprintf(stderr, "fsync failed: %s\n", strerror(errno)); + goto pbiudone; + } fprintf(cmd_pipe, "set_progress %.4f\n", (double) params.written / total_blocks); fflush(cmd_pipe); } |