summaryrefslogtreecommitdiffstats
path: root/otafault/ota_io.cpp
diff options
context:
space:
mode:
authorTianjie Xu <xunchang@google.com>2016-02-06 03:25:58 +0100
committerTianjie Xu <xunchang@google.com>2016-03-10 20:50:28 +0100
commitfa12b9737dd4ab36c3b4abaf25eb79f692e6eba6 (patch)
treee05c8721f0961c963391ea5a0cdb56609304eb8e /otafault/ota_io.cpp
parentMerge "Restore labels on /postinstall during recovery." into nyc-dev (diff)
downloadandroid_bootable_recovery-fa12b9737dd4ab36c3b4abaf25eb79f692e6eba6.tar
android_bootable_recovery-fa12b9737dd4ab36c3b4abaf25eb79f692e6eba6.tar.gz
android_bootable_recovery-fa12b9737dd4ab36c3b4abaf25eb79f692e6eba6.tar.bz2
android_bootable_recovery-fa12b9737dd4ab36c3b4abaf25eb79f692e6eba6.tar.lz
android_bootable_recovery-fa12b9737dd4ab36c3b4abaf25eb79f692e6eba6.tar.xz
android_bootable_recovery-fa12b9737dd4ab36c3b4abaf25eb79f692e6eba6.tar.zst
android_bootable_recovery-fa12b9737dd4ab36c3b4abaf25eb79f692e6eba6.zip
Diffstat (limited to 'otafault/ota_io.cpp')
-rw-r--r--otafault/ota_io.cpp68
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
}