summaryrefslogtreecommitdiffstats
path: root/uncrypt
diff options
context:
space:
mode:
authorBill Yi <byi@google.com>2015-02-19 23:30:26 +0100
committerBill Yi <byi@google.com>2015-02-19 23:30:26 +0100
commitc2b60b9870955c14ec8434353d617ebca6f44368 (patch)
treeb4e77beaa28fb350fd94ad2f9dbc1e032bdc39a1 /uncrypt
parentMerge "Move adb_main to its own file." (diff)
parentam ff934d02: Merge "Fix Droid and animation color in recovery mode" (diff)
downloadandroid_bootable_recovery-c2b60b9870955c14ec8434353d617ebca6f44368.tar
android_bootable_recovery-c2b60b9870955c14ec8434353d617ebca6f44368.tar.gz
android_bootable_recovery-c2b60b9870955c14ec8434353d617ebca6f44368.tar.bz2
android_bootable_recovery-c2b60b9870955c14ec8434353d617ebca6f44368.tar.lz
android_bootable_recovery-c2b60b9870955c14ec8434353d617ebca6f44368.tar.xz
android_bootable_recovery-c2b60b9870955c14ec8434353d617ebca6f44368.tar.zst
android_bootable_recovery-c2b60b9870955c14ec8434353d617ebca6f44368.zip
Diffstat (limited to 'uncrypt')
-rw-r--r--uncrypt/uncrypt.c23
1 files changed, 18 insertions, 5 deletions
diff --git a/uncrypt/uncrypt.c b/uncrypt/uncrypt.c
index b90bd6b87..aa75210b0 100644
--- a/uncrypt/uncrypt.c
+++ b/uncrypt/uncrypt.c
@@ -166,7 +166,12 @@ char* parse_recovery_command_file()
if (f == NULL) {
return NULL;
}
- FILE* fo = fopen(RECOVERY_COMMAND_FILE_TMP, "w");
+ int fd = open(RECOVERY_COMMAND_FILE_TMP, O_WRONLY | O_CREAT | O_SYNC, S_IRUSR | S_IWUSR);
+ if (fd < 0) {
+ ALOGE("failed to open %s\n", RECOVERY_COMMAND_FILE_TMP);
+ return NULL;
+ }
+ FILE* fo = fdopen(fd, "w");
while (fgets(temp, sizeof(temp), f)) {
printf("read: %s", temp);
@@ -177,6 +182,7 @@ char* parse_recovery_command_file()
fputs(temp, fo);
}
fclose(f);
+ fsync(fd);
fclose(fo);
if (fn) {
@@ -192,7 +198,12 @@ int produce_block_map(const char* path, const char* map_file, const char* blk_de
struct stat sb;
int ret;
- FILE* mapf = fopen(map_file, "w");
+ int mapfd = open(map_file, O_WRONLY | O_CREAT | O_SYNC, S_IRUSR | S_IWUSR);
+ if (mapfd < 0) {
+ ALOGE("failed to open %s\n", map_file);
+ return -1;
+ }
+ FILE* mapf = fdopen(mapfd, "w");
ret = stat(path, &sb);
if (ret != 0) {
@@ -234,7 +245,7 @@ int produce_block_map(const char* path, const char* map_file, const char* blk_de
int wfd = -1;
if (encrypted) {
- wfd = open(blk_dev, O_WRONLY);
+ wfd = open(blk_dev, O_WRONLY | O_SYNC);
if (wfd < 0) {
ALOGE("failed to open fd for writing: %s\n", strerror(errno));
return -1;
@@ -304,9 +315,11 @@ int produce_block_map(const char* path, const char* map_file, const char* blk_de
fprintf(mapf, "%d %d\n", ranges[i*2], ranges[i*2+1]);
}
+ fsync(mapfd);
fclose(mapf);
close(fd);
if (encrypted) {
+ fsync(wfd);
close(wfd);
}
@@ -320,7 +333,7 @@ void wipe_misc() {
struct fstab_rec* v = &fstab->recs[i];
if (!v->mount_point) continue;
if (strcmp(v->mount_point, "/misc") == 0) {
- int fd = open(v->blk_device, O_WRONLY);
+ int fd = open(v->blk_device, O_WRONLY | O_SYNC);
uint8_t zeroes[1088]; // sizeof(bootloader_message) from recovery
memset(zeroes, 0, sizeof(zeroes));
@@ -335,7 +348,7 @@ void wipe_misc() {
written += w;
}
}
-
+ fsync(fd);
close(fd);
}
}