summaryrefslogtreecommitdiffstats
path: root/updater
diff options
context:
space:
mode:
authorTao Bao <tbao@google.com>2016-02-10 20:00:02 +0100
committerGerrit Code Review <noreply-gerritcodereview@google.com>2016-02-10 20:00:02 +0100
commit704320650308bcdf43580b46aeba3af35c4ec92d (patch)
treeda799688bdf8d673220eccd24e21f20722578ffd /updater
parentMerge "applypatch: Add a Makefile to build imgdiff in Chrome OS." (diff)
parentIO fault injection for OTA packages (diff)
downloadandroid_bootable_recovery-704320650308bcdf43580b46aeba3af35c4ec92d.tar
android_bootable_recovery-704320650308bcdf43580b46aeba3af35c4ec92d.tar.gz
android_bootable_recovery-704320650308bcdf43580b46aeba3af35c4ec92d.tar.bz2
android_bootable_recovery-704320650308bcdf43580b46aeba3af35c4ec92d.tar.lz
android_bootable_recovery-704320650308bcdf43580b46aeba3af35c4ec92d.tar.xz
android_bootable_recovery-704320650308bcdf43580b46aeba3af35c4ec92d.tar.zst
android_bootable_recovery-704320650308bcdf43580b46aeba3af35c4ec92d.zip
Diffstat (limited to 'updater')
-rw-r--r--updater/Android.mk2
-rw-r--r--updater/blockimg.cpp25
-rw-r--r--updater/install.cpp43
3 files changed, 36 insertions, 34 deletions
diff --git a/updater/Android.mk b/updater/Android.mk
index 6fdd30895..d7aa613e9 100644
--- a/updater/Android.mk
+++ b/updater/Android.mk
@@ -45,7 +45,7 @@ LOCAL_STATIC_LIBRARIES += \
endif
LOCAL_STATIC_LIBRARIES += $(TARGET_RECOVERY_UPDATER_LIBS) $(TARGET_RECOVERY_UPDATER_EXTRA_LIBS)
-LOCAL_STATIC_LIBRARIES += libapplypatch libbase libedify libmtdutils libminzip libz
+LOCAL_STATIC_LIBRARIES += libapplypatch libbase libotafault libedify libmtdutils libminzip libz
LOCAL_STATIC_LIBRARIES += libbz
LOCAL_STATIC_LIBRARIES += libcutils liblog libc
LOCAL_STATIC_LIBRARIES += libselinux
diff --git a/updater/blockimg.cpp b/updater/blockimg.cpp
index 6e056006c..44de4e031 100644
--- a/updater/blockimg.cpp
+++ b/updater/blockimg.cpp
@@ -45,6 +45,7 @@
#include "install.h"
#include "openssl/sha.h"
#include "minzip/Hash.h"
+#include "otafault/ota_io.h"
#include "print_sha1.h"
#include "unique_fd.h"
#include "updater.h"
@@ -139,7 +140,7 @@ static bool range_overlaps(const RangeSet& r1, const RangeSet& r2) {
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(read(fd, data+so_far, size-so_far));
+ ssize_t r = TEMP_FAILURE_RETRY(ota_read(fd, data+so_far, size-so_far));
if (r == -1) {
fprintf(stderr, "read failed: %s\n", strerror(errno));
return -1;
@@ -156,7 +157,7 @@ static int read_all(int fd, std::vector<uint8_t>& buffer, size_t 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(write(fd, data+written, size-written));
+ ssize_t w = TEMP_FAILURE_RETRY(ota_write(fd, data+written, size-written));
if (w == -1) {
fprintf(stderr, "write failed: %s\n", strerror(errno));
return -1;
@@ -553,7 +554,7 @@ static int LoadStash(const std::string& base, const std::string& id, bool verify
return -1;
}
- int fd = TEMP_FAILURE_RETRY(open(fn.c_str(), O_RDONLY));
+ int fd = TEMP_FAILURE_RETRY(ota_open(fn.c_str(), O_RDONLY));
unique_fd fd_holder(fd);
if (fd == -1) {
@@ -610,7 +611,7 @@ static int WriteStash(const std::string& base, const std::string& id, int blocks
fprintf(stderr, " writing %d blocks to %s\n", blocks, cn.c_str());
- int fd = TEMP_FAILURE_RETRY(open(fn.c_str(), O_WRONLY | O_CREAT | O_TRUNC, STASH_FILE_MODE));
+ int fd = TEMP_FAILURE_RETRY(ota_open(fn.c_str(), O_WRONLY | O_CREAT | O_TRUNC, STASH_FILE_MODE));
unique_fd fd_holder(fd);
if (fd == -1) {
@@ -622,7 +623,7 @@ static int WriteStash(const std::string& base, const std::string& id, int blocks
return -1;
}
- if (fsync(fd) == -1) {
+ if (ota_fsync(fd) == -1) {
fprintf(stderr, "fsync \"%s\" failed: %s\n", fn.c_str(), strerror(errno));
return -1;
}
@@ -634,7 +635,7 @@ static int WriteStash(const std::string& base, const std::string& id, int blocks
}
std::string dname = GetStashFileName(base, "", "");
- int dfd = TEMP_FAILURE_RETRY(open(dname.c_str(), O_RDONLY | O_DIRECTORY));
+ int dfd = TEMP_FAILURE_RETRY(ota_open(dname.c_str(), O_RDONLY | O_DIRECTORY));
unique_fd dfd_holder(dfd);
if (dfd == -1) {
@@ -642,7 +643,7 @@ static int WriteStash(const std::string& base, const std::string& id, int blocks
return -1;
}
- if (fsync(dfd) == -1) {
+ if (ota_fsync(dfd) == -1) {
fprintf(stderr, "fsync \"%s\" failed: %s\n", dname.c_str(), strerror(errno));
return -1;
}
@@ -1346,7 +1347,7 @@ static Value* PerformBlockImageUpdate(const char* name, State* state, int /* arg
return StringValue(strdup(""));
}
- params.fd = TEMP_FAILURE_RETRY(open(blockdev_filename->data, O_RDWR));
+ params.fd = TEMP_FAILURE_RETRY(ota_open(blockdev_filename->data, O_RDWR));
unique_fd fd_holder(params.fd);
if (params.fd == -1) {
@@ -1465,7 +1466,7 @@ static Value* PerformBlockImageUpdate(const char* name, State* state, int /* arg
}
if (params.canwrite) {
- if (fsync(params.fd) == -1) {
+ if (ota_fsync(params.fd) == -1) {
fprintf(stderr, "fsync failed: %s\n", strerror(errno));
goto pbiudone;
}
@@ -1490,7 +1491,7 @@ static Value* PerformBlockImageUpdate(const char* name, State* state, int /* arg
rc = 0;
pbiudone:
- if (fsync(params.fd) == -1) {
+ if (ota_fsync(params.fd) == -1) {
fprintf(stderr, "fsync failed: %s\n", strerror(errno));
}
// params.fd will be automatically closed because of the fd_holder above.
@@ -1614,7 +1615,7 @@ Value* RangeSha1Fn(const char* name, State* state, int /* argc */, Expr* argv[])
return StringValue(strdup(""));
}
- int fd = open(blockdev_filename->data, O_RDWR);
+ int fd = ota_open(blockdev_filename->data, O_RDWR);
unique_fd fd_holder(fd);
if (fd < 0) {
ErrorAbort(state, "open \"%s\" failed: %s", blockdev_filename->data, strerror(errno));
@@ -1668,7 +1669,7 @@ Value* CheckFirstBlockFn(const char* name, State* state, int argc, Expr* argv[])
return StringValue(strdup(""));
}
- int fd = open(arg_filename->data, O_RDONLY);
+ int fd = ota_open(arg_filename->data, O_RDONLY);
unique_fd fd_holder(fd);
if (fd == -1) {
ErrorAbort(state, "open \"%s\" failed: %s", arg_filename->data, strerror(errno));
diff --git a/updater/install.cpp b/updater/install.cpp
index 45bbf2bc1..1cd9a5690 100644
--- a/updater/install.cpp
+++ b/updater/install.cpp
@@ -51,6 +51,7 @@
#include "minzip/DirUtil.h"
#include "mtdutils/mounts.h"
#include "mtdutils/mtdutils.h"
+#include "otafault/ota_io.h"
#include "updater.h"
#include "install.h"
#include "tune2fs.h"
@@ -557,18 +558,18 @@ Value* PackageExtractFileFn(const char* name, State* state,
}
{
- int fd = TEMP_FAILURE_RETRY(open(dest_path, O_WRONLY | O_CREAT | O_TRUNC | O_SYNC,
+ int fd = TEMP_FAILURE_RETRY(ota_open(dest_path, O_WRONLY | O_CREAT | O_TRUNC | O_SYNC,
S_IRUSR | S_IWUSR));
if (fd == -1) {
printf("%s: can't open %s for write: %s\n", name, dest_path, strerror(errno));
goto done2;
}
success = mzExtractZipEntryToFile(za, entry, fd);
- if (fsync(fd) == -1) {
+ if (ota_fsync(fd) == -1) {
printf("fsync of \"%s\" failed: %s\n", dest_path, strerror(errno));
success = false;
}
- if (close(fd) == -1) {
+ if (ota_close(fd) == -1) {
printf("close of \"%s\" failed: %s\n", dest_path, strerror(errno));
success = false;
}
@@ -995,21 +996,21 @@ Value* FileGetPropFn(const char* name, State* state, int argc, Expr* argv[]) {
}
FILE* f;
- f = fopen(filename, "rb");
+ f = ota_fopen(filename, "rb");
if (f == NULL) {
ErrorAbort(state, "%s: failed to open %s: %s", name, filename, strerror(errno));
goto done;
}
- if (fread(buffer, 1, st.st_size, f) != static_cast<size_t>(st.st_size)) {
+ if (ota_fread(buffer, 1, st.st_size, f) != static_cast<size_t>(st.st_size)) {
ErrorAbort(state, "%s: failed to read %lld bytes from %s",
name, (long long)st.st_size+1, filename);
- fclose(f);
+ ota_fclose(f);
goto done;
}
buffer[st.st_size] = '\0';
- fclose(f);
+ ota_fclose(f);
char* line;
line = strtok(buffer, "\n");
@@ -1104,7 +1105,7 @@ Value* WriteRawImageFn(const char* name, State* state, int argc, Expr* argv[]) {
if (contents->type == VAL_STRING) {
// we're given a filename as the contents
char* filename = contents->data;
- FILE* f = fopen(filename, "rb");
+ FILE* f = ota_fopen(filename, "rb");
if (f == NULL) {
printf("%s: can't open %s: %s\n", name, filename, strerror(errno));
result = strdup("");
@@ -1114,12 +1115,12 @@ Value* WriteRawImageFn(const char* name, State* state, int argc, Expr* argv[]) {
success = true;
char* buffer = reinterpret_cast<char*>(malloc(BUFSIZ));
int read;
- while (success && (read = fread(buffer, 1, BUFSIZ, f)) > 0) {
+ while (success && (read = ota_fread(buffer, 1, BUFSIZ, f)) > 0) {
int wrote = mtd_write_data(ctx, buffer, read);
success = success && (wrote == read);
}
free(buffer);
- fclose(f);
+ ota_fclose(f);
} else {
// we're given a blob as the contents
ssize_t wrote = mtd_write_data(ctx, contents->data, contents->size);
@@ -1438,10 +1439,10 @@ Value* RebootNowFn(const char* name, State* state, int argc, Expr* argv[]) {
// zero out the 'command' field of the bootloader message.
memset(buffer, 0, sizeof(((struct bootloader_message*)0)->command));
- FILE* f = fopen(filename, "r+b");
+ FILE* f = ota_fopen(filename, "r+b");
fseek(f, offsetof(struct bootloader_message, command), SEEK_SET);
- fwrite(buffer, sizeof(((struct bootloader_message*)0)->command), 1, f);
- fclose(f);
+ ota_fwrite(buffer, sizeof(((struct bootloader_message*)0)->command), 1, f);
+ ota_fclose(f);
free(filename);
strcpy(buffer, "reboot,");
@@ -1480,7 +1481,7 @@ Value* SetStageFn(const char* name, State* state, int argc, Expr* argv[]) {
// bootloader message that the main recovery uses to save its
// arguments in case of the device restarting midway through
// package installation.
- FILE* f = fopen(filename, "r+b");
+ FILE* f = ota_fopen(filename, "r+b");
fseek(f, offsetof(struct bootloader_message, stage), SEEK_SET);
int to_write = strlen(stagestr)+1;
int max_size = sizeof(((struct bootloader_message*)0)->stage);
@@ -1488,8 +1489,8 @@ Value* SetStageFn(const char* name, State* state, int argc, Expr* argv[]) {
to_write = max_size;
stagestr[max_size-1] = 0;
}
- fwrite(stagestr, to_write, 1, f);
- fclose(f);
+ ota_fwrite(stagestr, to_write, 1, f);
+ ota_fclose(f);
free(stagestr);
return StringValue(filename);
@@ -1506,10 +1507,10 @@ Value* GetStageFn(const char* name, State* state, int argc, Expr* argv[]) {
if (ReadArgs(state, argv, 1, &filename) < 0) return NULL;
char buffer[sizeof(((struct bootloader_message*)0)->stage)];
- FILE* f = fopen(filename, "rb");
+ FILE* f = ota_fopen(filename, "rb");
fseek(f, offsetof(struct bootloader_message, stage), SEEK_SET);
- fread(buffer, sizeof(buffer), 1, f);
- fclose(f);
+ ota_fread(buffer, sizeof(buffer), 1, f);
+ ota_fclose(f);
buffer[sizeof(buffer)-1] = '\0';
return StringValue(strdup(buffer));
@@ -1526,13 +1527,13 @@ Value* WipeBlockDeviceFn(const char* name, State* state, int argc, Expr* argv[])
size_t len;
android::base::ParseUint(len_str, &len);
- int fd = open(filename, O_WRONLY, 0644);
+ int fd = ota_open(filename, O_WRONLY, 0644);
int success = wipe_block_device(fd, len);
free(filename);
free(len_str);
- close(fd);
+ ota_close(fd);
return StringValue(strdup(success ? "t" : ""));
}