summaryrefslogtreecommitdiffstats
path: root/updater
diff options
context:
space:
mode:
authorTianjie Xu <xunchang@google.com>2018-08-27 19:50:31 +0200
committerTianjie Xu <xunchang@google.com>2018-08-28 02:16:19 +0200
commit22f11205a1f0d534c10e88e40f09b92c9faa161c (patch)
tree9b6e1bd187fe17b71654a83ebe61859191559a49 /updater
parentMerge "updater: Add TransferList class." (diff)
downloadandroid_bootable_recovery-22f11205a1f0d534c10e88e40f09b92c9faa161c.tar
android_bootable_recovery-22f11205a1f0d534c10e88e40f09b92c9faa161c.tar.gz
android_bootable_recovery-22f11205a1f0d534c10e88e40f09b92c9faa161c.tar.bz2
android_bootable_recovery-22f11205a1f0d534c10e88e40f09b92c9faa161c.tar.lz
android_bootable_recovery-22f11205a1f0d534c10e88e40f09b92c9faa161c.tar.xz
android_bootable_recovery-22f11205a1f0d534c10e88e40f09b92c9faa161c.tar.zst
android_bootable_recovery-22f11205a1f0d534c10e88e40f09b92c9faa161c.zip
Diffstat (limited to '')
-rw-r--r--updater/Android.bp1
-rw-r--r--updater/Android.mk1
-rw-r--r--updater/blockimg.cpp116
-rw-r--r--updater/install.cpp45
-rw-r--r--updater/updater.cpp11
5 files changed, 64 insertions, 110 deletions
diff --git a/updater/Android.bp b/updater/Android.bp
index c77bac8fb..c95ec5e90 100644
--- a/updater/Android.bp
+++ b/updater/Android.bp
@@ -24,7 +24,6 @@ cc_defaults {
"libbootloader_message",
"libbspatch",
"libedify",
- "libotafault",
"libotautil",
"libext4_utils",
"libfec",
diff --git a/updater/Android.mk b/updater/Android.mk
index 5478a7df6..78e32ba39 100644
--- a/updater/Android.mk
+++ b/updater/Android.mk
@@ -27,7 +27,6 @@ updater_common_static_libraries := \
libbootloader_message \
libbspatch \
libedify \
- libotafault \
libotautil \
libext4_utils \
libfec \
diff --git a/updater/blockimg.cpp b/updater/blockimg.cpp
index 96b2d9feb..823a1cbbd 100644
--- a/updater/blockimg.cpp
+++ b/updater/blockimg.cpp
@@ -53,7 +53,6 @@
#include <ziparchive/zip_archive.h>
#include "edify/expr.h"
-#include "otafault/ota_io.h"
#include "otautil/error_code.h"
#include "otautil/paths.h"
#include "otautil/print_sha1.h"
@@ -119,15 +118,14 @@ static bool ParseLastCommandFile(size_t* last_command_index) {
}
static bool FsyncDir(const std::string& dirname) {
- android::base::unique_fd dfd(
- TEMP_FAILURE_RETRY(ota_open(dirname.c_str(), O_RDONLY | O_DIRECTORY)));
+ android::base::unique_fd dfd(TEMP_FAILURE_RETRY(open(dirname.c_str(), O_RDONLY | O_DIRECTORY)));
if (dfd == -1) {
- failure_type = kFileOpenFailure;
+ failure_type = errno == EIO ? kEioFailure : kFileOpenFailure;
PLOG(ERROR) << "Failed to open " << dirname;
return false;
}
if (fsync(dfd) == -1) {
- failure_type = kFsyncFailure;
+ failure_type = errno == EIO ? kEioFailure : kFsyncFailure;
PLOG(ERROR) << "Failed to fsync " << dirname;
return false;
}
@@ -180,47 +178,6 @@ static bool SetPartitionUpdatedMarker(const std::string& marker) {
return true;
}
-static int read_all(int fd, uint8_t* data, size_t size) {
- size_t so_far = 0;
- while (so_far < size) {
- ssize_t r = TEMP_FAILURE_RETRY(ota_read(fd, data+so_far, size-so_far));
- if (r == -1) {
- failure_type = kFreadFailure;
- PLOG(ERROR) << "read failed";
- return -1;
- } else if (r == 0) {
- failure_type = kFreadFailure;
- LOG(ERROR) << "read reached unexpected EOF.";
- return -1;
- }
- so_far += r;
- }
- return 0;
-}
-
-static int read_all(int fd, std::vector<uint8_t>* buffer, size_t size) {
- return read_all(fd, buffer->data(), size);
-}
-
-static int write_all(int fd, const uint8_t* data, size_t size) {
- size_t written = 0;
- while (written < size) {
- ssize_t w = TEMP_FAILURE_RETRY(ota_write(fd, data+written, size-written));
- if (w == -1) {
- failure_type = kFwriteFailure;
- PLOG(ERROR) << "write failed";
- return -1;
- }
- written += w;
- }
-
- return 0;
-}
-
-static int write_all(int fd, const std::vector<uint8_t>& buffer, size_t size) {
- return write_all(fd, buffer.data(), size);
-}
-
static bool discard_blocks(int fd, off64_t offset, uint64_t size) {
// Don't discard blocks unless the update is a retry run.
if (!is_retry) {
@@ -293,7 +250,9 @@ class RangeSinkWriter {
write_now = current_range_left_;
}
- if (write_all(fd_, data, write_now) == -1) {
+ if (!android::base::WriteFully(fd_, data, write_now)) {
+ failure_type = errno == EIO ? kEioFailure : kFwriteFailure;
+ PLOG(ERROR) << "Failed to write " << write_now << " bytes of data";
break;
}
@@ -510,7 +469,9 @@ static int ReadBlocks(const RangeSet& src, std::vector<uint8_t>* buffer, int fd)
}
size_t size = (range.second - range.first) * BLOCKSIZE;
- if (read_all(fd, buffer->data() + p, size) == -1) {
+ if (!android::base::ReadFully(fd, buffer->data() + p, size)) {
+ failure_type = errno == EIO ? kEioFailure : kFreadFailure;
+ PLOG(ERROR) << "Failed to read " << size << " bytes of data";
return -1;
}
@@ -533,7 +494,9 @@ static int WriteBlocks(const RangeSet& tgt, const std::vector<uint8_t>& buffer,
return -1;
}
- if (write_all(fd, buffer.data() + written, size) == -1) {
+ if (!android::base::WriteFully(fd, buffer.data() + written, size)) {
+ failure_type = errno == EIO ? kEioFailure : kFwriteFailure;
+ PLOG(ERROR) << "Failed to write " << size << " bytes of data";
return -1;
}
@@ -793,15 +756,18 @@ static int LoadStash(const CommandParameters& params, const std::string& id, boo
return -1;
}
- android::base::unique_fd fd(TEMP_FAILURE_RETRY(ota_open(fn.c_str(), O_RDONLY)));
+ android::base::unique_fd fd(TEMP_FAILURE_RETRY(open(fn.c_str(), O_RDONLY)));
if (fd == -1) {
+ failure_type = errno == EIO ? kEioFailure : kFileOpenFailure;
PLOG(ERROR) << "open \"" << fn << "\" failed";
return -1;
}
allocate(sb.st_size, buffer);
- if (read_all(fd, buffer, sb.st_size) == -1) {
+ if (!android::base::ReadFully(fd, buffer->data(), sb.st_size)) {
+ failure_type = errno == EIO ? kEioFailure : kFreadFailure;
+ PLOG(ERROR) << "Failed to read " << sb.st_size << " bytes of data";
return -1;
}
@@ -855,8 +821,9 @@ static int WriteStash(const std::string& base, const std::string& id, int blocks
LOG(INFO) << " writing " << blocks << " blocks to " << cn;
android::base::unique_fd fd(
- TEMP_FAILURE_RETRY(ota_open(fn.c_str(), O_WRONLY | O_CREAT | O_TRUNC, STASH_FILE_MODE)));
+ TEMP_FAILURE_RETRY(open(fn.c_str(), O_WRONLY | O_CREAT | O_TRUNC, STASH_FILE_MODE)));
if (fd == -1) {
+ failure_type = errno == EIO ? kEioFailure : kFileOpenFailure;
PLOG(ERROR) << "failed to create \"" << fn << "\"";
return -1;
}
@@ -866,12 +833,14 @@ static int WriteStash(const std::string& base, const std::string& id, int blocks
return -1;
}
- if (write_all(fd, buffer, blocks * BLOCKSIZE) == -1) {
+ if (!android::base::WriteFully(fd, buffer.data(), blocks * BLOCKSIZE)) {
+ failure_type = errno == EIO ? kEioFailure : kFwriteFailure;
+ PLOG(ERROR) << "Failed to write " << blocks * BLOCKSIZE << " bytes of data";
return -1;
}
- if (ota_fsync(fd) == -1) {
- failure_type = kFsyncFailure;
+ if (fsync(fd) == -1) {
+ failure_type = errno == EIO ? kEioFailure : kFsyncFailure;
PLOG(ERROR) << "fsync \"" << fn << "\" failed";
return -1;
}
@@ -883,7 +852,6 @@ static int WriteStash(const std::string& base, const std::string& id, int blocks
std::string dname = GetStashFileName(base, "", "");
if (!FsyncDir(dname)) {
- failure_type = kFsyncFailure;
return -1;
}
@@ -1313,7 +1281,9 @@ static int PerformCommandZero(CommandParameters& params) {
}
for (size_t j = range.first; j < range.second; ++j) {
- if (write_all(params.fd, params.buffer, BLOCKSIZE) == -1) {
+ if (!android::base::WriteFully(params.fd, params.buffer.data(), BLOCKSIZE)) {
+ failure_type = errno == EIO ? kEioFailure : kFwriteFailure;
+ PLOG(ERROR) << "Failed to write " << BLOCKSIZE << " bytes of data";
return -1;
}
}
@@ -1560,7 +1530,8 @@ static int PerformCommandComputeHashTree(CommandParameters& params) {
}
for (size_t i = range.first; i < range.second; i++) {
- if (read_all(params.fd, buffer, BLOCKSIZE) == -1) {
+ if (!android::base::ReadFully(params.fd, buffer, BLOCKSIZE)) {
+ failure_type = errno == EIO ? kEioFailure : kFreadFailure;
LOG(ERROR) << "Failed to read data in " << range.first << ":" << range.second;
return -1;
}
@@ -1676,8 +1647,9 @@ static Value* PerformBlockImageUpdate(const char* name, State* state,
return StringValue("");
}
- params.fd.reset(TEMP_FAILURE_RETRY(ota_open(blockdev_filename->data.c_str(), O_RDWR)));
+ params.fd.reset(TEMP_FAILURE_RETRY(open(blockdev_filename->data.c_str(), O_RDWR)));
if (params.fd == -1) {
+ failure_type = errno == EIO ? kEioFailure : kFileOpenFailure;
PLOG(ERROR) << "open \"" << blockdev_filename->data << "\" failed";
return StringValue("");
}
@@ -1859,8 +1831,8 @@ static Value* PerformBlockImageUpdate(const char* name, State* state,
}
if (params.canwrite) {
- if (ota_fsync(params.fd) == -1) {
- failure_type = kFsyncFailure;
+ if (fsync(params.fd) == -1) {
+ failure_type = errno == EIO ? kEioFailure : kFsyncFailure;
PLOG(ERROR) << "fsync failed";
goto pbiudone;
}
@@ -1920,8 +1892,8 @@ pbiudone:
LOG(INFO) << "verified partition contents; update may be resumed";
}
- if (ota_fsync(params.fd) == -1) {
- failure_type = kFsyncFailure;
+ if (fsync(params.fd) == -1) {
+ failure_type = errno == EIO ? kEioFailure : kFsyncFailure;
PLOG(ERROR) << "fsync failed";
}
// params.fd will be automatically closed because it's a unique_fd.
@@ -2059,9 +2031,10 @@ Value* RangeSha1Fn(const char* name, State* state, const std::vector<std::unique
return StringValue("");
}
- android::base::unique_fd fd(ota_open(blockdev_filename->data.c_str(), O_RDWR));
+ android::base::unique_fd fd(open(blockdev_filename->data.c_str(), O_RDWR));
if (fd == -1) {
- ErrorAbort(state, kFileOpenFailure, "open \"%s\" failed: %s", blockdev_filename->data.c_str(),
+ CauseCode cause_code = errno == EIO ? kEioFailure : kFileOpenFailure;
+ ErrorAbort(state, cause_code, "open \"%s\" failed: %s", blockdev_filename->data.c_str(),
strerror(errno));
return StringValue("");
}
@@ -2081,8 +2054,9 @@ Value* RangeSha1Fn(const char* name, State* state, const std::vector<std::unique
}
for (size_t j = range.first; j < range.second; ++j) {
- if (read_all(fd, &buffer, BLOCKSIZE) == -1) {
- ErrorAbort(state, kFreadFailure, "failed to read %s: %s", blockdev_filename->data.c_str(),
+ if (!android::base::ReadFully(fd, buffer.data(), BLOCKSIZE)) {
+ CauseCode cause_code = errno == EIO ? kEioFailure : kFreadFailure;
+ ErrorAbort(state, cause_code, "failed to read %s: %s", blockdev_filename->data.c_str(),
strerror(errno));
return StringValue("");
}
@@ -2121,9 +2095,10 @@ Value* CheckFirstBlockFn(const char* name, State* state,
return StringValue("");
}
- android::base::unique_fd fd(ota_open(arg_filename->data.c_str(), O_RDONLY));
+ android::base::unique_fd fd(open(arg_filename->data.c_str(), O_RDONLY));
if (fd == -1) {
- ErrorAbort(state, kFileOpenFailure, "open \"%s\" failed: %s", arg_filename->data.c_str(),
+ CauseCode cause_code = errno == EIO ? kEioFailure : kFileOpenFailure;
+ ErrorAbort(state, cause_code, "open \"%s\" failed: %s", arg_filename->data.c_str(),
strerror(errno));
return StringValue("");
}
@@ -2132,7 +2107,8 @@ Value* CheckFirstBlockFn(const char* name, State* state,
std::vector<uint8_t> block0_buffer(BLOCKSIZE);
if (ReadBlocks(blk0, &block0_buffer, fd) == -1) {
- ErrorAbort(state, kFreadFailure, "failed to read %s: %s", arg_filename->data.c_str(),
+ CauseCode cause_code = errno == EIO ? kEioFailure : kFreadFailure;
+ ErrorAbort(state, cause_code, "failed to read %s: %s", arg_filename->data.c_str(),
strerror(errno));
return StringValue("");
}
diff --git a/updater/install.cpp b/updater/install.cpp
index f9333459b..34514b65a 100644
--- a/updater/install.cpp
+++ b/updater/install.cpp
@@ -46,6 +46,7 @@
#include <android-base/properties.h>
#include <android-base/stringprintf.h>
#include <android-base/strings.h>
+#include <android-base/unique_fd.h>
#include <applypatch/applypatch.h>
#include <bootloader_message/bootloader_message.h>
#include <ext4_utils/wipe.h>
@@ -56,7 +57,6 @@
#include <ziparchive/zip_archive.h>
#include "edify/expr.h"
-#include "otafault/ota_io.h"
#include "otautil/dirutil.h"
#include "otautil/error_code.h"
#include "otautil/mounts.h"
@@ -137,8 +137,8 @@ Value* PackageExtractFileFn(const char* name, State* state,
return StringValue("");
}
- unique_fd fd(TEMP_FAILURE_RETRY(
- ota_open(dest_path.c_str(), O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR)));
+ android::base::unique_fd fd(TEMP_FAILURE_RETRY(
+ open(dest_path.c_str(), O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR)));
if (fd == -1) {
PLOG(ERROR) << name << ": can't open " << dest_path << " for write";
return StringValue("");
@@ -152,11 +152,12 @@ Value* PackageExtractFileFn(const char* name, State* state,
<< "\": " << ErrorCodeString(ret);
success = false;
}
- if (ota_fsync(fd) == -1) {
+ if (fsync(fd) == -1) {
PLOG(ERROR) << "fsync of \"" << dest_path << "\" failed";
success = false;
}
- if (ota_close(fd) == -1) {
+
+ if (close(fd.release()) != 0) {
PLOG(ERROR) << "close of \"" << dest_path << "\" failed";
success = false;
}
@@ -614,33 +615,12 @@ Value* FileGetPropFn(const char* name, State* state,
const std::string& filename = args[0];
const std::string& key = args[1];
- struct stat st;
- if (stat(filename.c_str(), &st) < 0) {
- return ErrorAbort(state, kFileGetPropFailure, "%s: failed to stat \"%s\": %s", name,
- filename.c_str(), strerror(errno));
- }
-
- constexpr off_t MAX_FILE_GETPROP_SIZE = 65536;
- if (st.st_size > MAX_FILE_GETPROP_SIZE) {
- return ErrorAbort(state, kFileGetPropFailure, "%s too large for %s (max %lld)",
- filename.c_str(), name, static_cast<long long>(MAX_FILE_GETPROP_SIZE));
- }
-
- std::string buffer(st.st_size, '\0');
- unique_file f(ota_fopen(filename.c_str(), "rb"));
- if (f == nullptr) {
- return ErrorAbort(state, kFileOpenFailure, "%s: failed to open %s: %s", name, filename.c_str(),
- strerror(errno));
- }
-
- if (ota_fread(&buffer[0], 1, st.st_size, f.get()) != static_cast<size_t>(st.st_size)) {
- ErrorAbort(state, kFreadFailure, "%s: failed to read %zu bytes from %s", name,
- static_cast<size_t>(st.st_size), filename.c_str());
+ std::string buffer;
+ if (!android::base::ReadFileToString(filename, &buffer)) {
+ ErrorAbort(state, kFreadFailure, "%s: failed to read %s", name, filename.c_str());
return nullptr;
}
- ota_fclose(f);
-
std::vector<std::string> lines = android::base::Split(buffer, "\n");
for (size_t i = 0; i < lines.size(); i++) {
std::string line = android::base::Trim(lines[i]);
@@ -913,7 +893,12 @@ Value* WipeBlockDeviceFn(const char* name, State* state, const std::vector<std::
if (!android::base::ParseUint(len_str.c_str(), &len)) {
return nullptr;
}
- unique_fd fd(ota_open(filename.c_str(), O_WRONLY, 0644));
+ android::base::unique_fd fd(open(filename.c_str(), O_WRONLY));
+ if (fd == -1) {
+ PLOG(ERROR) << "Failed to open " << filename;
+ return StringValue("");
+ }
+
// The wipe_block_device function in ext4_utils returns 0 on success and 1
// for failure.
int status = wipe_block_device(fd, len);
diff --git a/updater/updater.cpp b/updater/updater.cpp
index e06d45355..e87c57a5c 100644
--- a/updater/updater.cpp
+++ b/updater/updater.cpp
@@ -31,7 +31,6 @@
#include <ziparchive/zip_archive.h>
#include "edify/expr.h"
-#include "otafault/config.h"
#include "otautil/dirutil.h"
#include "otautil/error_code.h"
#include "otautil/sysutil.h"
@@ -47,8 +46,6 @@
// (Note it's "updateR-script", not the older "update-script".)
static constexpr const char* SCRIPT_NAME = "META-INF/com/google/android/updater-script";
-extern bool have_eio_error;
-
struct selabel_handle *sehandle;
static void UpdaterLogger(android::base::LogId /* id */, android::base::LogSeverity /* severity */,
@@ -166,15 +163,10 @@ int main(int argc, char** argv) {
printf("unexpected argument: %s", argv[4]);
}
}
- ota_io_init(za, state.is_retry);
std::string result;
bool status = Evaluate(&state, root, &result);
- if (have_eio_error) {
- fprintf(cmd_pipe, "retry_update\n");
- }
-
if (!status) {
if (state.errmsg.empty()) {
LOG(ERROR) << "script aborted (no error message)";
@@ -206,6 +198,9 @@ int main(int argc, char** argv) {
if (state.cause_code == kPatchApplicationFailure) {
LOG(INFO) << "Patch application failed, retry update.";
fprintf(cmd_pipe, "retry_update\n");
+ } else if (state.cause_code == kEioFailure) {
+ LOG(INFO) << "Update failed due to EIO, retry update.";
+ fprintf(cmd_pipe, "retry_update\n");
}
}