Skip to content

Commit 37ad1f1

Browse files
Michael RungeAndroid (Google) Code Review
authored andcommitted
Merge "Force write to disk while doing uncrypt" into lmp-mr1-dev
2 parents 5b9c4ce + 4b54239 commit 37ad1f1

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

uncrypt/uncrypt.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@ char* parse_recovery_command_file()
164164
if (f == NULL) {
165165
return NULL;
166166
}
167-
FILE* fo = fopen(RECOVERY_COMMAND_FILE_TMP, "w");
167+
int fd = open(RECOVERY_COMMAND_FILE_TMP, O_WRONLY | O_SYNC);
168+
FILE* fo = fdopen(fd, "w");
168169

169170
while (fgets(temp, sizeof(temp), f)) {
170171
printf("read: %s", temp);
@@ -175,6 +176,7 @@ char* parse_recovery_command_file()
175176
fputs(temp, fo);
176177
}
177178
fclose(f);
179+
fsync(fd);
178180
fclose(fo);
179181

180182
if (fn) {
@@ -190,7 +192,8 @@ int produce_block_map(const char* path, const char* map_file, const char* blk_de
190192
struct stat sb;
191193
int ret;
192194

193-
FILE* mapf = fopen(map_file, "w");
195+
int mapfd = open(map_file, O_WRONLY | O_SYNC);
196+
FILE* mapf = fdopen(mapfd, "w");
194197

195198
ret = stat(path, &sb);
196199
if (ret != 0) {
@@ -232,7 +235,7 @@ int produce_block_map(const char* path, const char* map_file, const char* blk_de
232235

233236
int wfd = -1;
234237
if (encrypted) {
235-
wfd = open(blk_dev, O_WRONLY);
238+
wfd = open(blk_dev, O_WRONLY | O_SYNC);
236239
if (wfd < 0) {
237240
ALOGE("failed to open fd for writing: %s\n", strerror(errno));
238241
return -1;
@@ -302,9 +305,11 @@ int produce_block_map(const char* path, const char* map_file, const char* blk_de
302305
fprintf(mapf, "%d %d\n", ranges[i*2], ranges[i*2+1]);
303306
}
304307

308+
fsync(mapfd);
305309
fclose(mapf);
306310
close(fd);
307311
if (encrypted) {
312+
fsync(wfd);
308313
close(wfd);
309314
}
310315

@@ -318,7 +323,7 @@ void wipe_misc() {
318323
struct fstab_rec* v = &fstab->recs[i];
319324
if (!v->mount_point) continue;
320325
if (strcmp(v->mount_point, "/misc") == 0) {
321-
int fd = open(v->blk_device, O_WRONLY);
326+
int fd = open(v->blk_device, O_WRONLY | O_SYNC);
322327
uint8_t zeroes[1088]; // sizeof(bootloader_message) from recovery
323328
memset(zeroes, 0, sizeof(zeroes));
324329

@@ -333,7 +338,7 @@ void wipe_misc() {
333338
written += w;
334339
}
335340
}
336-
341+
fsync(fd);
337342
close(fd);
338343
}
339344
}

0 commit comments

Comments
 (0)