From 4b54239173f685a558a65e53c01b461c65006e5c Mon Sep 17 00:00:00 2001 From: Michael Runge Date: Fri, 21 Nov 2014 16:00:45 -0800 Subject: Force write to disk while doing uncrypt This should reduce errors if the device reboots before the blocks are commited to disk. Bug: 18481902 Change-Id: I13cda1c78955e4c83522fbcf87ddb16cc9f97683 --- uncrypt/uncrypt.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'uncrypt') diff --git a/uncrypt/uncrypt.c b/uncrypt/uncrypt.c index 189fa57e1..361c80483 100644 --- a/uncrypt/uncrypt.c +++ b/uncrypt/uncrypt.c @@ -164,7 +164,8 @@ 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_SYNC); + FILE* fo = fdopen(fd, "w"); while (fgets(temp, sizeof(temp), f)) { printf("read: %s", temp); @@ -175,6 +176,7 @@ char* parse_recovery_command_file() fputs(temp, fo); } fclose(f); + fsync(fd); fclose(fo); if (fn) { @@ -190,7 +192,8 @@ 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_SYNC); + FILE* mapf = fdopen(mapfd, "w"); ret = stat(path, &sb); if (ret != 0) { @@ -232,7 +235,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; @@ -302,9 +305,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); } @@ -318,7 +323,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)); @@ -333,7 +338,7 @@ void wipe_misc() { written += w; } } - + fsync(fd); close(fd); } } -- cgit v1.2.3 From a72512cd058da7de4cdb667776ed47fad873f12c Mon Sep 17 00:00:00 2001 From: Sungmin Choi Date: Wed, 10 Dec 2014 21:57:09 +0900 Subject: Add O_CREAT option for open Factory reset fails if there is no file, for example, RECOVERY_COMMAND_FILE_TMP. So create file as adding O_CREAT option if it does not exist. error log: --------- beginning of crash 12-10 02:35:17.190 3059 3059 F libc : Fatal signal 11 (SIGSEGV), code 1, fault addr 0x30 in tid 3059 (uncrypt) 12-10 02:35:17.296 766 1528 W NativeCrashListener: Couldn't find ProcessRecord for pid 3059 12-10 02:35:17.296 191 191 I DEBUG : *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** 12-10 02:35:17.296 191 191 E DEBUG : AM write failure (32 / Broken pipe) 12-10 02:35:17.296 191 191 I DEBUG : Build fingerprint: 'Android/aosp_hammerhead/hammerhead:5.1/LMP/hopemini12052127:userdebug/test-keys' 12-10 02:35:17.296 191 191 I DEBUG : Revision: '10' 12-10 02:35:17.297 191 191 I DEBUG : ABI: 'arm' 12-10 02:35:17.297 191 191 I DEBUG : pid: 3059, tid: 3059, name: uncrypt >>> /system/bin/uncrypt <<< 12-10 02:35:17.297 191 191 I DEBUG : signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x30 12-10 02:35:17.302 191 191 I DEBUG : r0 00000001 r1 be94b690 r2 fffffe90 r3 b6fdbf7c 12-10 02:35:17.302 191 191 I DEBUG : r4 00000000 r5 00000000 r6 b6fd8ca4 r7 be94b67c 12-10 02:35:17.302 191 191 I DEBUG : r8 00000000 r9 ffffffff sl b6ff582b fp be94b68d 12-10 02:35:17.302 191 191 I DEBUG : ip b6fcfd08 sp be94b648 lr b6f98fe5 pc b6f98fe4 cpsr 20070030 12-10 02:35:17.303 191 191 I DEBUG : 12-10 02:35:17.303 191 191 I DEBUG : backtrace: 12-10 02:35:17.303 191 191 I DEBUG : #00 pc 00032fe4 /system/lib/libc.so (fputs+29) 12-10 02:35:17.303 191 191 I DEBUG : #01 pc 000016a1 /system/bin/uncrypt 12-10 02:35:17.303 191 191 I DEBUG : #02 pc 0000114b /system/bin/uncrypt 12-10 02:35:17.303 191 191 I DEBUG : #03 pc 00012df5 /system/lib/libc.so (__libc_init+44) 12-10 02:35:17.303 191 191 I DEBUG : #04 pc 000013cc /system/bin/uncrypt 12-10 02:35:17.325 191 191 I DEBUG : 12-10 02:35:17.325 191 191 I DEBUG : Tombstone written to: /data/tombstones/tombstone_00 Bug: 18709330 Change-Id: Ib5dccdd366e829049938a188ea5f98d9e4e282db --- uncrypt/uncrypt.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'uncrypt') diff --git a/uncrypt/uncrypt.c b/uncrypt/uncrypt.c index 361c80483..7fb0989a7 100644 --- a/uncrypt/uncrypt.c +++ b/uncrypt/uncrypt.c @@ -164,7 +164,11 @@ char* parse_recovery_command_file() if (f == NULL) { return NULL; } - int fd = open(RECOVERY_COMMAND_FILE_TMP, O_WRONLY | O_SYNC); + 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)) { @@ -192,7 +196,11 @@ int produce_block_map(const char* path, const char* map_file, const char* blk_de struct stat sb; int ret; - int mapfd = open(map_file, O_WRONLY | O_SYNC); + 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); -- cgit v1.2.3