diff options
author | Tianjie Xu <xunchang@google.com> | 2016-03-08 08:44:47 +0100 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2016-03-08 08:44:47 +0100 |
commit | 9a83ca02a32a21f00c7328269ab2c05940928452 (patch) | |
tree | 53a83e7a981a6000a4b5f572c00e840a679a0713 /otafault | |
parent | Merge "Restore labels on /postinstall during recovery." into nyc-dev (diff) | |
parent | Merge "Reboot and retry on I/O errors" (diff) | |
download | android_bootable_recovery-9a83ca02a32a21f00c7328269ab2c05940928452.tar android_bootable_recovery-9a83ca02a32a21f00c7328269ab2c05940928452.tar.gz android_bootable_recovery-9a83ca02a32a21f00c7328269ab2c05940928452.tar.bz2 android_bootable_recovery-9a83ca02a32a21f00c7328269ab2c05940928452.tar.lz android_bootable_recovery-9a83ca02a32a21f00c7328269ab2c05940928452.tar.xz android_bootable_recovery-9a83ca02a32a21f00c7328269ab2c05940928452.tar.zst android_bootable_recovery-9a83ca02a32a21f00c7328269ab2c05940928452.zip |
Diffstat (limited to 'otafault')
-rw-r--r-- | otafault/ota_io.cpp | 37 |
1 files changed, 32 insertions, 5 deletions
diff --git a/otafault/ota_io.cpp b/otafault/ota_io.cpp index 2ce3dfcc2..dd805e56e 100644 --- a/otafault/ota_io.cpp +++ b/otafault/ota_io.cpp @@ -29,6 +29,7 @@ static std::map<intptr_t, const char*> filename_cache; static std::string read_fault_file_name = ""; static std::string write_fault_file_name = ""; static std::string fsync_fault_file_name = ""; +bool have_eio_error = false; static bool get_hit_file(const char* cached_path, std::string ffn) { return should_hit_cache() @@ -85,10 +86,16 @@ size_t ota_fread(void* ptr, size_t size, size_t nitems, FILE* stream) { get_hit_file(cached_path, read_fault_file_name)) { read_fault_file_name = ""; errno = EIO; + have_eio_error = true; return 0; } } - 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; } ssize_t ota_read(int fd, void* buf, size_t nbyte) { @@ -99,10 +106,15 @@ ssize_t ota_read(int fd, void* buf, size_t nbyte) { && get_hit_file(cached_path, read_fault_file_name)) { read_fault_file_name = ""; errno = EIO; + have_eio_error = true; return -1; } } - return read(fd, buf, nbyte); + ssize_t status = read(fd, buf, nbyte); + if (status == -1 && errno == EIO) { + have_eio_error = true; + } + return status; } size_t ota_fwrite(const void* ptr, size_t size, size_t count, FILE* stream) { @@ -113,10 +125,15 @@ size_t ota_fwrite(const void* ptr, size_t size, size_t count, FILE* stream) { get_hit_file(cached_path, write_fault_file_name)) { write_fault_file_name = ""; errno = EIO; + have_eio_error = true; return 0; } } - 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; } ssize_t ota_write(int fd, const void* buf, size_t nbyte) { @@ -127,10 +144,15 @@ ssize_t ota_write(int fd, const void* buf, size_t nbyte) { get_hit_file(cached_path, write_fault_file_name)) { write_fault_file_name = ""; errno = EIO; + have_eio_error = true; return -1; } } - return write(fd, buf, nbyte); + ssize_t status = write(fd, buf, nbyte); + if (status == -1 && errno == EIO) { + have_eio_error = true; + } + return status; } int ota_fsync(int fd) { @@ -141,9 +163,14 @@ int ota_fsync(int fd) { get_hit_file(cached_path, fsync_fault_file_name)) { fsync_fault_file_name = ""; errno = EIO; + have_eio_error = true; return -1; } } - return fsync(fd); + int status = fsync(fd); + if (status == -1 && errno == EIO) { + have_eio_error = true; + } + return status; } |