blob: 11766f14c24e548b5308609be3784d0c703c57a8 [file] [log] [blame]
Doug Zongker76adfc52014-01-13 10:04:25 -08001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17// This program takes a file on an ext4 filesystem and produces a list
18// of the blocks that file occupies, which enables the file contents
19// to be read directly from the block device without mounting the
20// filesystem.
21//
22// If the filesystem is using an encrypted block device, it will also
23// read the file and rewrite it to the same blocks of the underlying
24// (unencrypted) block device, so the file contents can be read
25// without the need for the decryption key.
26//
27// The output of this program is a "block map" which looks like this:
28//
29// /dev/block/platform/msm_sdcc.1/by-name/userdata # block device
30// 49652 4096 # file size in bytes, block size
31// 3 # count of block ranges
32// 1000 1008 # block range 0
33// 2100 2102 # ... block range 1
34// 30 33 # ... block range 2
35//
36// Each block range represents a half-open interval; the line "30 33"
37// reprents the blocks [30, 31, 32].
38//
39// Recovery can take this block map file and retrieve the underlying
40// file data to use as an update package.
41
Elliott Hughesd4d4c242014-12-29 12:46:43 -080042#include <errno.h>
Doug Zongker76adfc52014-01-13 10:04:25 -080043#include <stdio.h>
44#include <stdlib.h>
Elliott Hughescd3c55a2015-01-29 20:50:08 -080045#include <string.h>
Doug Zongker76adfc52014-01-13 10:04:25 -080046#include <stdarg.h>
47#include <sys/types.h>
48#include <sys/stat.h>
49#include <fcntl.h>
50#include <linux/fs.h>
51#include <sys/mman.h>
52
Doug Zongkerf449db22014-08-26 09:15:08 -070053#define LOG_TAG "uncrypt"
54#include <log/log.h>
Doug Zongker76adfc52014-01-13 10:04:25 -080055#include <cutils/properties.h>
56#include <fs_mgr.h>
57
58#define WINDOW_SIZE 5
59#define RECOVERY_COMMAND_FILE "/cache/recovery/command"
60#define RECOVERY_COMMAND_FILE_TMP "/cache/recovery/command.tmp"
61#define CACHE_BLOCK_MAP "/cache/recovery/block.map"
62
Doug Zongker2efc9d92014-08-18 15:55:28 -070063static struct fstab* fstab = NULL;
64
Tao Bao3e8d28b2015-05-05 18:36:45 -070065static int write_at_offset(unsigned char* buffer, size_t size, int wfd, off64_t offset) {
Elliott Hughes2f5feed2015-04-28 17:24:24 -070066 if (TEMP_FAILURE_RETRY(lseek64(wfd, offset, SEEK_SET)) == -1) {
67 ALOGE("error seeking to offset %lld: %s\n", offset, strerror(errno));
68 return -1;
69 }
Doug Zongker76adfc52014-01-13 10:04:25 -080070 size_t written = 0;
71 while (written < size) {
Elliott Hughes2f5feed2015-04-28 17:24:24 -070072 ssize_t wrote = TEMP_FAILURE_RETRY(write(wfd, buffer + written, size - written));
73 if (wrote == -1) {
74 ALOGE("error writing offset %lld: %s\n", (offset + written), strerror(errno));
Doug Zongker76adfc52014-01-13 10:04:25 -080075 return -1;
76 }
77 written += wrote;
78 }
79 return 0;
80}
81
Tao Bao3e8d28b2015-05-05 18:36:45 -070082static void add_block_to_ranges(int** ranges, int* range_alloc, int* range_used, int new_block) {
Doug Zongker76adfc52014-01-13 10:04:25 -080083 // If the current block start is < 0, set the start to the new
84 // block. (This only happens for the very first block of the very
85 // first range.)
86 if ((*ranges)[*range_used*2-2] < 0) {
87 (*ranges)[*range_used*2-2] = new_block;
88 (*ranges)[*range_used*2-1] = new_block;
89 }
90
91 if (new_block == (*ranges)[*range_used*2-1]) {
92 // If the new block comes immediately after the current range,
93 // all we have to do is extend the current range.
94 ++(*ranges)[*range_used*2-1];
95 } else {
96 // We need to start a new range.
97
98 // If there isn't enough room in the array, we need to expand it.
99 if (*range_used >= *range_alloc) {
100 *range_alloc *= 2;
Tao Bao3e8d28b2015-05-05 18:36:45 -0700101 *ranges = reinterpret_cast<int*>(realloc(*ranges, *range_alloc * 2 * sizeof(int)));
Doug Zongker76adfc52014-01-13 10:04:25 -0800102 }
103
104 ++*range_used;
105 (*ranges)[*range_used*2-2] = new_block;
106 (*ranges)[*range_used*2-1] = new_block+1;
107 }
108}
109
Tao Bao3e8d28b2015-05-05 18:36:45 -0700110static struct fstab* read_fstab() {
Doug Zongker2efc9d92014-08-18 15:55:28 -0700111 fstab = NULL;
112
Doug Zongker76adfc52014-01-13 10:04:25 -0800113 // The fstab path is always "/fstab.${ro.hardware}".
114 char fstab_path[PATH_MAX+1] = "/fstab.";
115 if (!property_get("ro.hardware", fstab_path+strlen(fstab_path), "")) {
Doug Zongkerf449db22014-08-26 09:15:08 -0700116 ALOGE("failed to get ro.hardware\n");
Doug Zongker76adfc52014-01-13 10:04:25 -0800117 return NULL;
118 }
119
Doug Zongker2efc9d92014-08-18 15:55:28 -0700120 fstab = fs_mgr_read_fstab(fstab_path);
Doug Zongker76adfc52014-01-13 10:04:25 -0800121 if (!fstab) {
Doug Zongkerf449db22014-08-26 09:15:08 -0700122 ALOGE("failed to read %s\n", fstab_path);
Doug Zongker76adfc52014-01-13 10:04:25 -0800123 return NULL;
124 }
125
Doug Zongker2efc9d92014-08-18 15:55:28 -0700126 return fstab;
127}
128
Tao Bao3e8d28b2015-05-05 18:36:45 -0700129static const char* find_block_device(const char* path, bool* encryptable, bool* encrypted) {
Doug Zongker76adfc52014-01-13 10:04:25 -0800130 // Look for a volume whose mount point is the prefix of path and
131 // return its block device. Set encrypted if it's currently
132 // encrypted.
Tao Bao3e8d28b2015-05-05 18:36:45 -0700133 for (int i = 0; i < fstab->num_entries; ++i) {
Doug Zongker76adfc52014-01-13 10:04:25 -0800134 struct fstab_rec* v = &fstab->recs[i];
Tao Bao3e8d28b2015-05-05 18:36:45 -0700135 if (!v->mount_point) {
136 continue;
137 }
Doug Zongker76adfc52014-01-13 10:04:25 -0800138 int len = strlen(v->mount_point);
139 if (strncmp(path, v->mount_point, len) == 0 &&
140 (path[len] == '/' || path[len] == 0)) {
Tao Bao3e8d28b2015-05-05 18:36:45 -0700141 *encrypted = false;
142 *encryptable = false;
Doug Zongker76adfc52014-01-13 10:04:25 -0800143 if (fs_mgr_is_encryptable(v)) {
Tao Bao3e8d28b2015-05-05 18:36:45 -0700144 *encryptable = true;
Doug Zongker76adfc52014-01-13 10:04:25 -0800145 char buffer[PROPERTY_VALUE_MAX+1];
146 if (property_get("ro.crypto.state", buffer, "") &&
147 strcmp(buffer, "encrypted") == 0) {
Tao Bao3e8d28b2015-05-05 18:36:45 -0700148 *encrypted = true;
Doug Zongker76adfc52014-01-13 10:04:25 -0800149 }
150 }
151 return v->blk_device;
152 }
153 }
154
155 return NULL;
156}
157
Tao Bao8853cb22015-05-04 10:10:13 -0700158// Parse the command file RECOVERY_COMMAND_FILE to find the update package
159// name. If it's on the /data partition, replace the package name with the
160// block map file name and store it temporarily in RECOVERY_COMMAND_FILE_TMP.
161// It will be renamed to RECOVERY_COMMAND_FILE if uncrypt finishes
162// successfully.
163static char* find_update_package()
Doug Zongker76adfc52014-01-13 10:04:25 -0800164{
Doug Zongker76adfc52014-01-13 10:04:25 -0800165 FILE* f = fopen(RECOVERY_COMMAND_FILE, "r");
Maxim Siniavinee7b28882014-02-13 15:48:53 -0800166 if (f == NULL) {
167 return NULL;
168 }
Sungmin Choia72512c2014-12-10 21:57:09 +0900169 int fd = open(RECOVERY_COMMAND_FILE_TMP, O_WRONLY | O_CREAT | O_SYNC, S_IRUSR | S_IWUSR);
170 if (fd < 0) {
171 ALOGE("failed to open %s\n", RECOVERY_COMMAND_FILE_TMP);
172 return NULL;
173 }
Michael Runge4b542392014-11-21 16:00:45 -0800174 FILE* fo = fdopen(fd, "w");
Tao Bao8853cb22015-05-04 10:10:13 -0700175 char* fn = NULL;
176 char* line = NULL;
177 size_t len = 0;
178 while (getline(&line, &len, f) != -1) {
179 if (strncmp(line, "--update_package=", strlen("--update_package=")) == 0) {
180 fn = strdup(line + strlen("--update_package="));
181 // Replace the package name with block map file if it's on /data partition.
182 if (strncmp(fn, "/data/", strlen("/data/")) == 0) {
183 fputs("--update_package=@" CACHE_BLOCK_MAP "\n", fo);
184 continue;
185 }
Doug Zongker76adfc52014-01-13 10:04:25 -0800186 }
Tao Bao8853cb22015-05-04 10:10:13 -0700187 fputs(line, fo);
Doug Zongker76adfc52014-01-13 10:04:25 -0800188 }
Tao Bao8853cb22015-05-04 10:10:13 -0700189 free(line);
Doug Zongker76adfc52014-01-13 10:04:25 -0800190 fclose(f);
Tao Bao8853cb22015-05-04 10:10:13 -0700191 if (fsync(fd) == -1) {
192 ALOGE("failed to fsync \"%s\": %s\n", RECOVERY_COMMAND_FILE_TMP, strerror(errno));
193 fclose(fo);
194 return NULL;
195 }
Doug Zongker76adfc52014-01-13 10:04:25 -0800196 fclose(fo);
197
198 if (fn) {
199 char* newline = strchr(fn, '\n');
Tao Bao3e8d28b2015-05-05 18:36:45 -0700200 if (newline) {
201 *newline = 0;
202 }
Doug Zongker76adfc52014-01-13 10:04:25 -0800203 }
204 return fn;
205}
206
Tao Bao3e8d28b2015-05-05 18:36:45 -0700207static int produce_block_map(const char* path, const char* map_file, const char* blk_dev,
208 bool encrypted) {
Doug Zongker76adfc52014-01-13 10:04:25 -0800209
Sungmin Choia72512c2014-12-10 21:57:09 +0900210 int mapfd = open(map_file, O_WRONLY | O_CREAT | O_SYNC, S_IRUSR | S_IWUSR);
211 if (mapfd < 0) {
212 ALOGE("failed to open %s\n", map_file);
213 return -1;
214 }
Michael Runge4b542392014-11-21 16:00:45 -0800215 FILE* mapf = fdopen(mapfd, "w");
Doug Zongker76adfc52014-01-13 10:04:25 -0800216
Tao Bao3e8d28b2015-05-05 18:36:45 -0700217 struct stat sb;
218 int ret = stat(path, &sb);
Doug Zongker76adfc52014-01-13 10:04:25 -0800219 if (ret != 0) {
Doug Zongkerf449db22014-08-26 09:15:08 -0700220 ALOGE("failed to stat %s\n", path);
Doug Zongker76adfc52014-01-13 10:04:25 -0800221 return -1;
222 }
223
Doug Zongkerf449db22014-08-26 09:15:08 -0700224 ALOGI(" block size: %ld bytes\n", (long)sb.st_blksize);
Doug Zongker76adfc52014-01-13 10:04:25 -0800225
226 int blocks = ((sb.st_size-1) / sb.st_blksize) + 1;
Doug Zongkerf449db22014-08-26 09:15:08 -0700227 ALOGI(" file size: %lld bytes, %d blocks\n", (long long)sb.st_size, blocks);
Doug Zongker76adfc52014-01-13 10:04:25 -0800228
Doug Zongker76adfc52014-01-13 10:04:25 -0800229 int range_alloc = 1;
230 int range_used = 1;
Tao Bao3e8d28b2015-05-05 18:36:45 -0700231 int* ranges = reinterpret_cast<int*>(malloc(range_alloc * 2 * sizeof(int)));
Doug Zongker76adfc52014-01-13 10:04:25 -0800232 ranges[0] = -1;
233 ranges[1] = -1;
234
Mark Salyzyn2605dec2014-03-19 15:30:25 -0700235 fprintf(mapf, "%s\n%lld %lu\n", blk_dev, (long long)sb.st_size, (unsigned long)sb.st_blksize);
Doug Zongker76adfc52014-01-13 10:04:25 -0800236
237 unsigned char* buffers[WINDOW_SIZE];
Doug Zongker76adfc52014-01-13 10:04:25 -0800238 if (encrypted) {
Tao Bao3e8d28b2015-05-05 18:36:45 -0700239 for (size_t i = 0; i < WINDOW_SIZE; ++i) {
240 buffers[i] = reinterpret_cast<unsigned char*>(malloc(sb.st_blksize));
Doug Zongker76adfc52014-01-13 10:04:25 -0800241 }
242 }
243 int head_block = 0;
244 int head = 0, tail = 0;
245 size_t pos = 0;
246
247 int fd = open(path, O_RDONLY);
248 if (fd < 0) {
Doug Zongkerf449db22014-08-26 09:15:08 -0700249 ALOGE("failed to open fd for reading: %s\n", strerror(errno));
Doug Zongker76adfc52014-01-13 10:04:25 -0800250 return -1;
251 }
Doug Zongker76adfc52014-01-13 10:04:25 -0800252
253 int wfd = -1;
254 if (encrypted) {
Michael Runge4b542392014-11-21 16:00:45 -0800255 wfd = open(blk_dev, O_WRONLY | O_SYNC);
Doug Zongker76adfc52014-01-13 10:04:25 -0800256 if (wfd < 0) {
Doug Zongkerf449db22014-08-26 09:15:08 -0700257 ALOGE("failed to open fd for writing: %s\n", strerror(errno));
Doug Zongker76adfc52014-01-13 10:04:25 -0800258 return -1;
259 }
260 }
261
262 while (pos < sb.st_size) {
263 if ((tail+1) % WINDOW_SIZE == head) {
264 // write out head buffer
265 int block = head_block;
266 ret = ioctl(fd, FIBMAP, &block);
267 if (ret != 0) {
Doug Zongkerf449db22014-08-26 09:15:08 -0700268 ALOGE("failed to find block %d\n", head_block);
Doug Zongker76adfc52014-01-13 10:04:25 -0800269 return -1;
270 }
271 add_block_to_ranges(&ranges, &range_alloc, &range_used, block);
272 if (encrypted) {
Tao Bao3e8d28b2015-05-05 18:36:45 -0700273 if (write_at_offset(buffers[head], sb.st_blksize, wfd,
274 (off64_t)sb.st_blksize * block) != 0) {
Doug Zongker76adfc52014-01-13 10:04:25 -0800275 return -1;
276 }
277 }
278 head = (head + 1) % WINDOW_SIZE;
279 ++head_block;
280 }
281
282 // read next block to tail
283 if (encrypted) {
284 size_t so_far = 0;
285 while (so_far < sb.st_blksize && pos < sb.st_size) {
Elliott Hughes2f5feed2015-04-28 17:24:24 -0700286 ssize_t this_read =
287 TEMP_FAILURE_RETRY(read(fd, buffers[tail] + so_far, sb.st_blksize - so_far));
288 if (this_read == -1) {
Doug Zongkerf449db22014-08-26 09:15:08 -0700289 ALOGE("failed to read: %s\n", strerror(errno));
Doug Zongker76adfc52014-01-13 10:04:25 -0800290 return -1;
291 }
292 so_far += this_read;
293 pos += this_read;
294 }
295 } else {
296 // If we're not encrypting; we don't need to actually read
297 // anything, just skip pos forward as if we'd read a
298 // block.
299 pos += sb.st_blksize;
300 }
301 tail = (tail+1) % WINDOW_SIZE;
302 }
303
304 while (head != tail) {
305 // write out head buffer
306 int block = head_block;
307 ret = ioctl(fd, FIBMAP, &block);
308 if (ret != 0) {
Doug Zongkerf449db22014-08-26 09:15:08 -0700309 ALOGE("failed to find block %d\n", head_block);
Doug Zongker76adfc52014-01-13 10:04:25 -0800310 return -1;
311 }
312 add_block_to_ranges(&ranges, &range_alloc, &range_used, block);
313 if (encrypted) {
Tao Bao3e8d28b2015-05-05 18:36:45 -0700314 if (write_at_offset(buffers[head], sb.st_blksize, wfd,
315 (off64_t)sb.st_blksize * block) != 0) {
Doug Zongker76adfc52014-01-13 10:04:25 -0800316 return -1;
317 }
318 }
319 head = (head + 1) % WINDOW_SIZE;
320 ++head_block;
321 }
322
323 fprintf(mapf, "%d\n", range_used);
Tao Bao3e8d28b2015-05-05 18:36:45 -0700324 for (int i = 0; i < range_used; ++i) {
Doug Zongker76adfc52014-01-13 10:04:25 -0800325 fprintf(mapf, "%d %d\n", ranges[i*2], ranges[i*2+1]);
326 }
327
Tao Bao8853cb22015-05-04 10:10:13 -0700328 if (fsync(mapfd) == -1) {
329 ALOGE("failed to fsync \"%s\": %s\n", map_file, strerror(errno));
330 return -1;
331 }
Doug Zongker76adfc52014-01-13 10:04:25 -0800332 fclose(mapf);
333 close(fd);
334 if (encrypted) {
Tao Bao8853cb22015-05-04 10:10:13 -0700335 if (fsync(wfd) == -1) {
336 ALOGE("failed to fsync \"%s\": %s\n", blk_dev, strerror(errno));
337 return -1;
338 }
Doug Zongker76adfc52014-01-13 10:04:25 -0800339 close(wfd);
340 }
341
342 return 0;
343}
344
Tao Bao3e8d28b2015-05-05 18:36:45 -0700345static void wipe_misc() {
Doug Zongkerf449db22014-08-26 09:15:08 -0700346 ALOGI("removing old commands from misc");
Tao Bao3e8d28b2015-05-05 18:36:45 -0700347 for (int i = 0; i < fstab->num_entries; ++i) {
Doug Zongker2efc9d92014-08-18 15:55:28 -0700348 struct fstab_rec* v = &fstab->recs[i];
349 if (!v->mount_point) continue;
350 if (strcmp(v->mount_point, "/misc") == 0) {
Michael Runge4b542392014-11-21 16:00:45 -0800351 int fd = open(v->blk_device, O_WRONLY | O_SYNC);
Doug Zongker2efc9d92014-08-18 15:55:28 -0700352 uint8_t zeroes[1088]; // sizeof(bootloader_message) from recovery
353 memset(zeroes, 0, sizeof(zeroes));
354
355 size_t written = 0;
356 size_t size = sizeof(zeroes);
357 while (written < size) {
Elliott Hughes2f5feed2015-04-28 17:24:24 -0700358 ssize_t w = TEMP_FAILURE_RETRY(write(fd, zeroes, size-written));
359 if (w == -1) {
Doug Zongkerf449db22014-08-26 09:15:08 -0700360 ALOGE("zero write failed: %s\n", strerror(errno));
Doug Zongker2efc9d92014-08-18 15:55:28 -0700361 return;
362 } else {
363 written += w;
364 }
365 }
Tao Bao8853cb22015-05-04 10:10:13 -0700366 if (fsync(fd) == -1) {
367 ALOGE("failed to fsync \"%s\": %s\n", v->blk_device, strerror(errno));
368 close(fd);
369 return;
370 }
Doug Zongker2efc9d92014-08-18 15:55:28 -0700371 close(fd);
372 }
373 }
374}
375
Tao Bao3e8d28b2015-05-05 18:36:45 -0700376static void reboot_to_recovery() {
Doug Zongkerf449db22014-08-26 09:15:08 -0700377 ALOGI("rebooting to recovery");
Doug Zongker76adfc52014-01-13 10:04:25 -0800378 property_set("sys.powerctl", "reboot,recovery");
379 sleep(10);
Doug Zongkerf449db22014-08-26 09:15:08 -0700380 ALOGE("reboot didn't succeed?");
Doug Zongker76adfc52014-01-13 10:04:25 -0800381}
382
383int main(int argc, char** argv)
384{
385 const char* input_path;
386 const char* map_file;
Tao Bao3e8d28b2015-05-05 18:36:45 -0700387 bool do_reboot = true;
Doug Zongker76adfc52014-01-13 10:04:25 -0800388
389 if (argc != 1 && argc != 3) {
390 fprintf(stderr, "usage: %s [<transform_path> <map_file>]\n", argv[0]);
391 return 2;
392 }
393
394 if (argc == 3) {
395 // when command-line args are given this binary is being used
396 // for debugging; don't reboot to recovery at the end.
397 input_path = argv[1];
398 map_file = argv[2];
Tao Bao3e8d28b2015-05-05 18:36:45 -0700399 do_reboot = false;
Doug Zongker76adfc52014-01-13 10:04:25 -0800400 } else {
Tao Bao8853cb22015-05-04 10:10:13 -0700401 input_path = find_update_package();
Doug Zongker76adfc52014-01-13 10:04:25 -0800402 if (input_path == NULL) {
403 // if we're rebooting to recovery without a package (say,
404 // to wipe data), then we don't need to do anything before
405 // going to recovery.
Doug Zongkerf449db22014-08-26 09:15:08 -0700406 ALOGI("no recovery command file or no update package arg");
Doug Zongker76adfc52014-01-13 10:04:25 -0800407 reboot_to_recovery();
408 return 1;
409 }
410 map_file = CACHE_BLOCK_MAP;
411 }
412
Doug Zongkerf449db22014-08-26 09:15:08 -0700413 ALOGI("update package is %s", input_path);
414
Doug Zongker76adfc52014-01-13 10:04:25 -0800415 // Turn the name of the file we're supposed to convert into an
416 // absolute path, so we can find what filesystem it's on.
417 char path[PATH_MAX+1];
418 if (realpath(input_path, path) == NULL) {
Doug Zongkerf449db22014-08-26 09:15:08 -0700419 ALOGE("failed to convert %s to absolute path: %s", input_path, strerror(errno));
Doug Zongker76adfc52014-01-13 10:04:25 -0800420 return 1;
421 }
422
Doug Zongker2efc9d92014-08-18 15:55:28 -0700423 if (read_fstab() == NULL) {
424 return 1;
425 }
Tao Bao3e8d28b2015-05-05 18:36:45 -0700426
427 bool encryptable;
428 bool encrypted;
Doug Zongker76adfc52014-01-13 10:04:25 -0800429 const char* blk_dev = find_block_device(path, &encryptable, &encrypted);
430 if (blk_dev == NULL) {
Doug Zongkerf449db22014-08-26 09:15:08 -0700431 ALOGE("failed to find block device for %s", path);
Doug Zongker76adfc52014-01-13 10:04:25 -0800432 return 1;
433 }
434
435 // If the filesystem it's on isn't encrypted, we only produce the
436 // block map, we don't rewrite the file contents (it would be
437 // pointless to do so).
Doug Zongkerf449db22014-08-26 09:15:08 -0700438 ALOGI("encryptable: %s\n", encryptable ? "yes" : "no");
439 ALOGI(" encrypted: %s\n", encrypted ? "yes" : "no");
Doug Zongker76adfc52014-01-13 10:04:25 -0800440
Doug Zongker574443d2014-09-05 08:22:12 -0700441 // Recovery supports installing packages from 3 paths: /cache,
442 // /data, and /sdcard. (On a particular device, other locations
443 // may work, but those are three we actually expect.)
444 //
445 // On /data we want to convert the file to a block map so that we
446 // can read the package without mounting the partition. On /cache
447 // and /sdcard we leave the file alone.
448 if (strncmp(path, "/data/", 6) != 0) {
449 // path does not start with "/data/"; leave it alone.
Doug Zongker76adfc52014-01-13 10:04:25 -0800450 unlink(RECOVERY_COMMAND_FILE_TMP);
Tao Bao8853cb22015-05-04 10:10:13 -0700451 wipe_misc();
Doug Zongker76adfc52014-01-13 10:04:25 -0800452 } else {
Doug Zongkerf449db22014-08-26 09:15:08 -0700453 ALOGI("writing block map %s", map_file);
Doug Zongker76adfc52014-01-13 10:04:25 -0800454 if (produce_block_map(path, map_file, blk_dev, encrypted) != 0) {
455 return 1;
456 }
Tao Bao8853cb22015-05-04 10:10:13 -0700457 wipe_misc();
458 rename(RECOVERY_COMMAND_FILE_TMP, RECOVERY_COMMAND_FILE);
Doug Zongker76adfc52014-01-13 10:04:25 -0800459 }
460
Tao Bao3e8d28b2015-05-05 18:36:45 -0700461 if (do_reboot) {
462 reboot_to_recovery();
463 }
Doug Zongker76adfc52014-01-13 10:04:25 -0800464 return 0;
465}