diff options
author | Tianjie Xu <xunchang@google.com> | 2016-03-10 22:27:26 +0100 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2016-03-10 22:27:26 +0100 |
commit | d345de66efb919e8c0d09ee5b4d8ae0d443d6c94 (patch) | |
tree | 33e073f4f17960b19336a03fb15e1a40141cb0a2 /otafault/ota_io.cpp | |
parent | Revert "recovery: More refactoring of WearUI" (diff) | |
parent | Reboot and retry on I/O errors (diff) | |
download | android_bootable_recovery-d345de66efb919e8c0d09ee5b4d8ae0d443d6c94.tar android_bootable_recovery-d345de66efb919e8c0d09ee5b4d8ae0d443d6c94.tar.gz android_bootable_recovery-d345de66efb919e8c0d09ee5b4d8ae0d443d6c94.tar.bz2 android_bootable_recovery-d345de66efb919e8c0d09ee5b4d8ae0d443d6c94.tar.lz android_bootable_recovery-d345de66efb919e8c0d09ee5b4d8ae0d443d6c94.tar.xz android_bootable_recovery-d345de66efb919e8c0d09ee5b4d8ae0d443d6c94.tar.zst android_bootable_recovery-d345de66efb919e8c0d09ee5b4d8ae0d443d6c94.zip |
Diffstat (limited to 'otafault/ota_io.cpp')
-rw-r--r-- | otafault/ota_io.cpp | 68 |
1 files changed, 58 insertions, 10 deletions
diff --git a/otafault/ota_io.cpp b/otafault/ota_io.cpp index 02e80f9bf..a37804088 100644 --- a/otafault/ota_io.cpp +++ b/otafault/ota_io.cpp @@ -38,6 +38,8 @@ static std::string FaultFileName = #endif // defined (TARGET_READ_FAULT) #endif // defined (TARGET_INJECT_FAULTS) +bool have_eio_error = false; + int ota_open(const char* path, int oflags) { #if defined (TARGET_INJECT_FAULTS) // Let the caller handle errors; we do not care if open succeeds or fails @@ -90,12 +92,22 @@ size_t ota_fread(void* ptr, size_t size, size_t nitems, FILE* stream) { && FilenameCache[(intptr_t)stream] == FaultFileName) { FaultFileName = ""; errno = EIO; + have_eio_error = true; return 0; } else { - return fread(ptr, size, nitems, stream); + size_t status = fread(ptr, size, nitems, stream); + // If I/O error occurs, set the retry-update flag. + if (status != nitems && errno == EIO) { + have_eio_error = true; + } + return status; } #else - return fread(ptr, size, nitems, stream); + size_t status = fread(ptr, size, nitems, stream); + if (status != nitems && errno == EIO) { + have_eio_error = true; + } + return status; #endif } @@ -105,12 +117,21 @@ ssize_t ota_read(int fd, void* buf, size_t nbyte) { && FilenameCache[fd] == FaultFileName) { FaultFileName = ""; errno = EIO; + have_eio_error = true; return -1; } else { - return read(fd, buf, nbyte); + ssize_t status = read(fd, buf, nbyte); + if (status == -1 && errno == EIO) { + have_eio_error = true; + } + return status; } #else - return read(fd, buf, nbyte); + ssize_t status = read(fd, buf, nbyte); + if (status == -1 && errno == EIO) { + have_eio_error = true; + } + return status; #endif } @@ -120,12 +141,21 @@ size_t ota_fwrite(const void* ptr, size_t size, size_t count, FILE* stream) { && FilenameCache[(intptr_t)stream] == FaultFileName) { FaultFileName = ""; errno = EIO; + have_eio_error = true; return 0; } else { - return fwrite(ptr, size, count, stream); + size_t status = fwrite(ptr, size, count, stream); + if (status != count && errno == EIO) { + have_eio_error = true; + } + return status; } #else - return fwrite(ptr, size, count, stream); + size_t status = fwrite(ptr, size, count, stream); + if (status != count && errno == EIO) { + have_eio_error = true; + } + return status; #endif } @@ -135,12 +165,21 @@ ssize_t ota_write(int fd, const void* buf, size_t nbyte) { && FilenameCache[fd] == FaultFileName) { FaultFileName = ""; errno = EIO; + have_eio_error = true; return -1; } else { - return write(fd, buf, nbyte); + ssize_t status = write(fd, buf, nbyte); + if (status == -1 && errno == EIO) { + have_eio_error = true; + } + return status; } #else - return write(fd, buf, nbyte); + ssize_t status = write(fd, buf, nbyte); + if (status == -1 && errno == EIO) { + have_eio_error = true; + } + return status; #endif } @@ -151,10 +190,19 @@ int ota_fsync(int fd) { FaultFileName = ""; errno = EIO; return -1; + have_eio_error = true; } else { - return fsync(fd); + int status = fsync(fd); + if (status == -1 && errno == EIO) { + have_eio_error = true; + } + return status; } #else - return fsync(fd); + int status = fsync(fd); + if (status == -1 && errno == EIO) { + have_eio_error = true; + } + return status; #endif } |