summaryrefslogtreecommitdiffstats
path: root/otafault
diff options
context:
space:
mode:
authorTianjie Xu <xunchang@google.com>2016-02-06 03:25:58 +0100
committerTianjie Xu <xunchang@google.com>2016-03-03 02:31:05 +0100
commit3c62b67faf8a25f1dd1c44dc19759c3997fdfd36 (patch)
tree5b5de8d81fe220d4331cc2284c87686708283d7a /otafault
parentMerge "Remove dumpkey build guards after completing code move." (diff)
downloadandroid_bootable_recovery-3c62b67faf8a25f1dd1c44dc19759c3997fdfd36.tar
android_bootable_recovery-3c62b67faf8a25f1dd1c44dc19759c3997fdfd36.tar.gz
android_bootable_recovery-3c62b67faf8a25f1dd1c44dc19759c3997fdfd36.tar.bz2
android_bootable_recovery-3c62b67faf8a25f1dd1c44dc19759c3997fdfd36.tar.lz
android_bootable_recovery-3c62b67faf8a25f1dd1c44dc19759c3997fdfd36.tar.xz
android_bootable_recovery-3c62b67faf8a25f1dd1c44dc19759c3997fdfd36.tar.zst
android_bootable_recovery-3c62b67faf8a25f1dd1c44dc19759c3997fdfd36.zip
Diffstat (limited to 'otafault')
-rw-r--r--otafault/ota_io.cpp37
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;
}