Doug Zongker | 76adfc5 | 2014-01-13 10:04:25 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 42 | #include <stdio.h> |
| 43 | #include <stdlib.h> |
| 44 | #include <stdarg.h> |
| 45 | #include <sys/types.h> |
| 46 | #include <sys/stat.h> |
| 47 | #include <fcntl.h> |
| 48 | #include <linux/fs.h> |
| 49 | #include <sys/mman.h> |
| 50 | |
Doug Zongker | f449db2 | 2014-08-26 09:15:08 -0700 | [diff] [blame] | 51 | #define LOG_TAG "uncrypt" |
| 52 | #include <log/log.h> |
Doug Zongker | 76adfc5 | 2014-01-13 10:04:25 -0800 | [diff] [blame] | 53 | #include <cutils/properties.h> |
| 54 | #include <fs_mgr.h> |
| 55 | |
| 56 | #define WINDOW_SIZE 5 |
| 57 | #define RECOVERY_COMMAND_FILE "/cache/recovery/command" |
| 58 | #define RECOVERY_COMMAND_FILE_TMP "/cache/recovery/command.tmp" |
| 59 | #define CACHE_BLOCK_MAP "/cache/recovery/block.map" |
| 60 | |
Doug Zongker | 2efc9d9 | 2014-08-18 15:55:28 -0700 | [diff] [blame] | 61 | static struct fstab* fstab = NULL; |
| 62 | |
Doug Zongker | 76adfc5 | 2014-01-13 10:04:25 -0800 | [diff] [blame] | 63 | static int write_at_offset(unsigned char* buffer, size_t size, |
| 64 | int wfd, off64_t offset) |
| 65 | { |
| 66 | lseek64(wfd, offset, SEEK_SET); |
| 67 | size_t written = 0; |
| 68 | while (written < size) { |
| 69 | ssize_t wrote = write(wfd, buffer + written, size - written); |
| 70 | if (wrote < 0) { |
Doug Zongker | f449db2 | 2014-08-26 09:15:08 -0700 | [diff] [blame] | 71 | ALOGE("error writing offset %lld: %s\n", offset, strerror(errno)); |
Doug Zongker | 76adfc5 | 2014-01-13 10:04:25 -0800 | [diff] [blame] | 72 | return -1; |
| 73 | } |
| 74 | written += wrote; |
| 75 | } |
| 76 | return 0; |
| 77 | } |
| 78 | |
| 79 | void add_block_to_ranges(int** ranges, int* range_alloc, int* range_used, int new_block) |
| 80 | { |
| 81 | // If the current block start is < 0, set the start to the new |
| 82 | // block. (This only happens for the very first block of the very |
| 83 | // first range.) |
| 84 | if ((*ranges)[*range_used*2-2] < 0) { |
| 85 | (*ranges)[*range_used*2-2] = new_block; |
| 86 | (*ranges)[*range_used*2-1] = new_block; |
| 87 | } |
| 88 | |
| 89 | if (new_block == (*ranges)[*range_used*2-1]) { |
| 90 | // If the new block comes immediately after the current range, |
| 91 | // all we have to do is extend the current range. |
| 92 | ++(*ranges)[*range_used*2-1]; |
| 93 | } else { |
| 94 | // We need to start a new range. |
| 95 | |
| 96 | // If there isn't enough room in the array, we need to expand it. |
| 97 | if (*range_used >= *range_alloc) { |
| 98 | *range_alloc *= 2; |
| 99 | *ranges = realloc(*ranges, *range_alloc * 2 * sizeof(int)); |
| 100 | } |
| 101 | |
| 102 | ++*range_used; |
| 103 | (*ranges)[*range_used*2-2] = new_block; |
| 104 | (*ranges)[*range_used*2-1] = new_block+1; |
| 105 | } |
| 106 | } |
| 107 | |
Doug Zongker | 2efc9d9 | 2014-08-18 15:55:28 -0700 | [diff] [blame] | 108 | static struct fstab* read_fstab() |
Doug Zongker | 76adfc5 | 2014-01-13 10:04:25 -0800 | [diff] [blame] | 109 | { |
Doug Zongker | 2efc9d9 | 2014-08-18 15:55:28 -0700 | [diff] [blame] | 110 | fstab = NULL; |
| 111 | |
Doug Zongker | 76adfc5 | 2014-01-13 10:04:25 -0800 | [diff] [blame] | 112 | // The fstab path is always "/fstab.${ro.hardware}". |
| 113 | char fstab_path[PATH_MAX+1] = "/fstab."; |
| 114 | if (!property_get("ro.hardware", fstab_path+strlen(fstab_path), "")) { |
Doug Zongker | f449db2 | 2014-08-26 09:15:08 -0700 | [diff] [blame] | 115 | ALOGE("failed to get ro.hardware\n"); |
Doug Zongker | 76adfc5 | 2014-01-13 10:04:25 -0800 | [diff] [blame] | 116 | return NULL; |
| 117 | } |
| 118 | |
Doug Zongker | 2efc9d9 | 2014-08-18 15:55:28 -0700 | [diff] [blame] | 119 | fstab = fs_mgr_read_fstab(fstab_path); |
Doug Zongker | 76adfc5 | 2014-01-13 10:04:25 -0800 | [diff] [blame] | 120 | if (!fstab) { |
Doug Zongker | f449db2 | 2014-08-26 09:15:08 -0700 | [diff] [blame] | 121 | ALOGE("failed to read %s\n", fstab_path); |
Doug Zongker | 76adfc5 | 2014-01-13 10:04:25 -0800 | [diff] [blame] | 122 | return NULL; |
| 123 | } |
| 124 | |
Doug Zongker | 2efc9d9 | 2014-08-18 15:55:28 -0700 | [diff] [blame] | 125 | return fstab; |
| 126 | } |
| 127 | |
| 128 | const char* find_block_device(const char* path, int* encryptable, int* encrypted) |
| 129 | { |
Doug Zongker | 76adfc5 | 2014-01-13 10:04:25 -0800 | [diff] [blame] | 130 | // 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. |
| 133 | int i; |
| 134 | for (i = 0; i < fstab->num_entries; ++i) { |
| 135 | struct fstab_rec* v = &fstab->recs[i]; |
| 136 | if (!v->mount_point) continue; |
| 137 | int len = strlen(v->mount_point); |
| 138 | if (strncmp(path, v->mount_point, len) == 0 && |
| 139 | (path[len] == '/' || path[len] == 0)) { |
| 140 | *encrypted = 0; |
| 141 | *encryptable = 0; |
| 142 | if (fs_mgr_is_encryptable(v)) { |
| 143 | *encryptable = 1; |
| 144 | char buffer[PROPERTY_VALUE_MAX+1]; |
| 145 | if (property_get("ro.crypto.state", buffer, "") && |
| 146 | strcmp(buffer, "encrypted") == 0) { |
| 147 | *encrypted = 1; |
| 148 | } |
| 149 | } |
| 150 | return v->blk_device; |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | return NULL; |
| 155 | } |
| 156 | |
| 157 | char* parse_recovery_command_file() |
| 158 | { |
| 159 | char* fn = NULL; |
| 160 | int count = 0; |
| 161 | char temp[1024]; |
| 162 | |
Doug Zongker | 76adfc5 | 2014-01-13 10:04:25 -0800 | [diff] [blame] | 163 | FILE* f = fopen(RECOVERY_COMMAND_FILE, "r"); |
Maxim Siniavine | e7b2888 | 2014-02-13 15:48:53 -0800 | [diff] [blame] | 164 | if (f == NULL) { |
| 165 | return NULL; |
| 166 | } |
| 167 | FILE* fo = fopen(RECOVERY_COMMAND_FILE_TMP, "w"); |
| 168 | |
Doug Zongker | 76adfc5 | 2014-01-13 10:04:25 -0800 | [diff] [blame] | 169 | while (fgets(temp, sizeof(temp), f)) { |
| 170 | printf("read: %s", temp); |
Doug Zongker | eaf3365 | 2014-07-31 14:59:01 -0700 | [diff] [blame] | 171 | if (strncmp(temp, "--update_package=/data/", strlen("--update_package=/data/")) == 0) { |
Doug Zongker | 76adfc5 | 2014-01-13 10:04:25 -0800 | [diff] [blame] | 172 | fn = strdup(temp + strlen("--update_package=")); |
| 173 | strcpy(temp, "--update_package=@" CACHE_BLOCK_MAP "\n"); |
| 174 | } |
| 175 | fputs(temp, fo); |
| 176 | } |
| 177 | fclose(f); |
| 178 | fclose(fo); |
| 179 | |
| 180 | if (fn) { |
| 181 | char* newline = strchr(fn, '\n'); |
| 182 | if (newline) *newline = 0; |
| 183 | } |
| 184 | return fn; |
| 185 | } |
| 186 | |
| 187 | int produce_block_map(const char* path, const char* map_file, const char* blk_dev, |
| 188 | int encrypted) |
| 189 | { |
| 190 | struct stat sb; |
| 191 | int ret; |
| 192 | |
| 193 | FILE* mapf = fopen(map_file, "w"); |
| 194 | |
| 195 | ret = stat(path, &sb); |
| 196 | if (ret != 0) { |
Doug Zongker | f449db2 | 2014-08-26 09:15:08 -0700 | [diff] [blame] | 197 | ALOGE("failed to stat %s\n", path); |
Doug Zongker | 76adfc5 | 2014-01-13 10:04:25 -0800 | [diff] [blame] | 198 | return -1; |
| 199 | } |
| 200 | |
Doug Zongker | f449db2 | 2014-08-26 09:15:08 -0700 | [diff] [blame] | 201 | ALOGI(" block size: %ld bytes\n", (long)sb.st_blksize); |
Doug Zongker | 76adfc5 | 2014-01-13 10:04:25 -0800 | [diff] [blame] | 202 | |
| 203 | int blocks = ((sb.st_size-1) / sb.st_blksize) + 1; |
Doug Zongker | f449db2 | 2014-08-26 09:15:08 -0700 | [diff] [blame] | 204 | ALOGI(" file size: %lld bytes, %d blocks\n", (long long)sb.st_size, blocks); |
Doug Zongker | 76adfc5 | 2014-01-13 10:04:25 -0800 | [diff] [blame] | 205 | |
| 206 | int* ranges; |
| 207 | int range_alloc = 1; |
| 208 | int range_used = 1; |
| 209 | ranges = malloc(range_alloc * 2 * sizeof(int)); |
| 210 | ranges[0] = -1; |
| 211 | ranges[1] = -1; |
| 212 | |
Mark Salyzyn | 2605dec | 2014-03-19 15:30:25 -0700 | [diff] [blame] | 213 | fprintf(mapf, "%s\n%lld %lu\n", blk_dev, (long long)sb.st_size, (unsigned long)sb.st_blksize); |
Doug Zongker | 76adfc5 | 2014-01-13 10:04:25 -0800 | [diff] [blame] | 214 | |
| 215 | unsigned char* buffers[WINDOW_SIZE]; |
| 216 | int i; |
| 217 | if (encrypted) { |
| 218 | for (i = 0; i < WINDOW_SIZE; ++i) { |
| 219 | buffers[i] = malloc(sb.st_blksize); |
| 220 | } |
| 221 | } |
| 222 | int head_block = 0; |
| 223 | int head = 0, tail = 0; |
| 224 | size_t pos = 0; |
| 225 | |
| 226 | int fd = open(path, O_RDONLY); |
| 227 | if (fd < 0) { |
Doug Zongker | f449db2 | 2014-08-26 09:15:08 -0700 | [diff] [blame] | 228 | ALOGE("failed to open fd for reading: %s\n", strerror(errno)); |
Doug Zongker | 76adfc5 | 2014-01-13 10:04:25 -0800 | [diff] [blame] | 229 | return -1; |
| 230 | } |
| 231 | fsync(fd); |
| 232 | |
| 233 | int wfd = -1; |
| 234 | if (encrypted) { |
| 235 | wfd = open(blk_dev, O_WRONLY); |
| 236 | if (wfd < 0) { |
Doug Zongker | f449db2 | 2014-08-26 09:15:08 -0700 | [diff] [blame] | 237 | ALOGE("failed to open fd for writing: %s\n", strerror(errno)); |
Doug Zongker | 76adfc5 | 2014-01-13 10:04:25 -0800 | [diff] [blame] | 238 | return -1; |
| 239 | } |
| 240 | } |
| 241 | |
| 242 | while (pos < sb.st_size) { |
| 243 | if ((tail+1) % WINDOW_SIZE == head) { |
| 244 | // write out head buffer |
| 245 | int block = head_block; |
| 246 | ret = ioctl(fd, FIBMAP, &block); |
| 247 | if (ret != 0) { |
Doug Zongker | f449db2 | 2014-08-26 09:15:08 -0700 | [diff] [blame] | 248 | ALOGE("failed to find block %d\n", head_block); |
Doug Zongker | 76adfc5 | 2014-01-13 10:04:25 -0800 | [diff] [blame] | 249 | return -1; |
| 250 | } |
| 251 | add_block_to_ranges(&ranges, &range_alloc, &range_used, block); |
| 252 | if (encrypted) { |
| 253 | if (write_at_offset(buffers[head], sb.st_blksize, wfd, (off64_t)sb.st_blksize * block) != 0) { |
| 254 | return -1; |
| 255 | } |
| 256 | } |
| 257 | head = (head + 1) % WINDOW_SIZE; |
| 258 | ++head_block; |
| 259 | } |
| 260 | |
| 261 | // read next block to tail |
| 262 | if (encrypted) { |
| 263 | size_t so_far = 0; |
| 264 | while (so_far < sb.st_blksize && pos < sb.st_size) { |
| 265 | ssize_t this_read = read(fd, buffers[tail] + so_far, sb.st_blksize - so_far); |
| 266 | if (this_read < 0) { |
Doug Zongker | f449db2 | 2014-08-26 09:15:08 -0700 | [diff] [blame] | 267 | ALOGE("failed to read: %s\n", strerror(errno)); |
Doug Zongker | 76adfc5 | 2014-01-13 10:04:25 -0800 | [diff] [blame] | 268 | return -1; |
| 269 | } |
| 270 | so_far += this_read; |
| 271 | pos += this_read; |
| 272 | } |
| 273 | } else { |
| 274 | // If we're not encrypting; we don't need to actually read |
| 275 | // anything, just skip pos forward as if we'd read a |
| 276 | // block. |
| 277 | pos += sb.st_blksize; |
| 278 | } |
| 279 | tail = (tail+1) % WINDOW_SIZE; |
| 280 | } |
| 281 | |
| 282 | while (head != tail) { |
| 283 | // write out head buffer |
| 284 | int block = head_block; |
| 285 | ret = ioctl(fd, FIBMAP, &block); |
| 286 | if (ret != 0) { |
Doug Zongker | f449db2 | 2014-08-26 09:15:08 -0700 | [diff] [blame] | 287 | ALOGE("failed to find block %d\n", head_block); |
Doug Zongker | 76adfc5 | 2014-01-13 10:04:25 -0800 | [diff] [blame] | 288 | return -1; |
| 289 | } |
| 290 | add_block_to_ranges(&ranges, &range_alloc, &range_used, block); |
| 291 | if (encrypted) { |
| 292 | if (write_at_offset(buffers[head], sb.st_blksize, wfd, (off64_t)sb.st_blksize * block) != 0) { |
| 293 | return -1; |
| 294 | } |
| 295 | } |
| 296 | head = (head + 1) % WINDOW_SIZE; |
| 297 | ++head_block; |
| 298 | } |
| 299 | |
| 300 | fprintf(mapf, "%d\n", range_used); |
| 301 | for (i = 0; i < range_used; ++i) { |
| 302 | fprintf(mapf, "%d %d\n", ranges[i*2], ranges[i*2+1]); |
| 303 | } |
| 304 | |
| 305 | fclose(mapf); |
| 306 | close(fd); |
| 307 | if (encrypted) { |
| 308 | close(wfd); |
| 309 | } |
| 310 | |
| 311 | return 0; |
| 312 | } |
| 313 | |
Doug Zongker | 2efc9d9 | 2014-08-18 15:55:28 -0700 | [diff] [blame] | 314 | void wipe_misc() { |
Doug Zongker | f449db2 | 2014-08-26 09:15:08 -0700 | [diff] [blame] | 315 | ALOGI("removing old commands from misc"); |
Doug Zongker | 2efc9d9 | 2014-08-18 15:55:28 -0700 | [diff] [blame] | 316 | int i; |
| 317 | for (i = 0; i < fstab->num_entries; ++i) { |
| 318 | struct fstab_rec* v = &fstab->recs[i]; |
| 319 | if (!v->mount_point) continue; |
| 320 | if (strcmp(v->mount_point, "/misc") == 0) { |
Doug Zongker | f449db2 | 2014-08-26 09:15:08 -0700 | [diff] [blame] | 321 | int fd = open(v->blk_device, O_WRONLY); |
Doug Zongker | 2efc9d9 | 2014-08-18 15:55:28 -0700 | [diff] [blame] | 322 | uint8_t zeroes[1088]; // sizeof(bootloader_message) from recovery |
| 323 | memset(zeroes, 0, sizeof(zeroes)); |
| 324 | |
| 325 | size_t written = 0; |
| 326 | size_t size = sizeof(zeroes); |
| 327 | while (written < size) { |
| 328 | ssize_t w = write(fd, zeroes, size-written); |
| 329 | if (w < 0 && errno != EINTR) { |
Doug Zongker | f449db2 | 2014-08-26 09:15:08 -0700 | [diff] [blame] | 330 | ALOGE("zero write failed: %s\n", strerror(errno)); |
Doug Zongker | 2efc9d9 | 2014-08-18 15:55:28 -0700 | [diff] [blame] | 331 | return; |
| 332 | } else { |
| 333 | written += w; |
| 334 | } |
| 335 | } |
| 336 | |
| 337 | close(fd); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | |
Doug Zongker | 76adfc5 | 2014-01-13 10:04:25 -0800 | [diff] [blame] | 342 | void reboot_to_recovery() { |
Doug Zongker | f449db2 | 2014-08-26 09:15:08 -0700 | [diff] [blame] | 343 | ALOGI("rebooting to recovery"); |
Doug Zongker | 76adfc5 | 2014-01-13 10:04:25 -0800 | [diff] [blame] | 344 | property_set("sys.powerctl", "reboot,recovery"); |
| 345 | sleep(10); |
Doug Zongker | f449db2 | 2014-08-26 09:15:08 -0700 | [diff] [blame] | 346 | ALOGE("reboot didn't succeed?"); |
Doug Zongker | 76adfc5 | 2014-01-13 10:04:25 -0800 | [diff] [blame] | 347 | } |
| 348 | |
| 349 | int main(int argc, char** argv) |
| 350 | { |
| 351 | const char* input_path; |
| 352 | const char* map_file; |
| 353 | int do_reboot = 1; |
| 354 | |
| 355 | if (argc != 1 && argc != 3) { |
| 356 | fprintf(stderr, "usage: %s [<transform_path> <map_file>]\n", argv[0]); |
| 357 | return 2; |
| 358 | } |
| 359 | |
| 360 | if (argc == 3) { |
| 361 | // when command-line args are given this binary is being used |
| 362 | // for debugging; don't reboot to recovery at the end. |
| 363 | input_path = argv[1]; |
| 364 | map_file = argv[2]; |
| 365 | do_reboot = 0; |
| 366 | } else { |
| 367 | input_path = parse_recovery_command_file(); |
| 368 | if (input_path == NULL) { |
| 369 | // if we're rebooting to recovery without a package (say, |
| 370 | // to wipe data), then we don't need to do anything before |
| 371 | // going to recovery. |
Doug Zongker | f449db2 | 2014-08-26 09:15:08 -0700 | [diff] [blame] | 372 | ALOGI("no recovery command file or no update package arg"); |
Doug Zongker | 76adfc5 | 2014-01-13 10:04:25 -0800 | [diff] [blame] | 373 | reboot_to_recovery(); |
| 374 | return 1; |
| 375 | } |
| 376 | map_file = CACHE_BLOCK_MAP; |
| 377 | } |
| 378 | |
Doug Zongker | f449db2 | 2014-08-26 09:15:08 -0700 | [diff] [blame] | 379 | ALOGI("update package is %s", input_path); |
| 380 | |
Doug Zongker | 76adfc5 | 2014-01-13 10:04:25 -0800 | [diff] [blame] | 381 | // Turn the name of the file we're supposed to convert into an |
| 382 | // absolute path, so we can find what filesystem it's on. |
| 383 | char path[PATH_MAX+1]; |
| 384 | if (realpath(input_path, path) == NULL) { |
Doug Zongker | f449db2 | 2014-08-26 09:15:08 -0700 | [diff] [blame] | 385 | ALOGE("failed to convert %s to absolute path: %s", input_path, strerror(errno)); |
Doug Zongker | 76adfc5 | 2014-01-13 10:04:25 -0800 | [diff] [blame] | 386 | return 1; |
| 387 | } |
| 388 | |
| 389 | int encryptable; |
| 390 | int encrypted; |
Doug Zongker | 2efc9d9 | 2014-08-18 15:55:28 -0700 | [diff] [blame] | 391 | if (read_fstab() == NULL) { |
| 392 | return 1; |
| 393 | } |
Doug Zongker | 76adfc5 | 2014-01-13 10:04:25 -0800 | [diff] [blame] | 394 | const char* blk_dev = find_block_device(path, &encryptable, &encrypted); |
| 395 | if (blk_dev == NULL) { |
Doug Zongker | f449db2 | 2014-08-26 09:15:08 -0700 | [diff] [blame] | 396 | ALOGE("failed to find block device for %s", path); |
Doug Zongker | 76adfc5 | 2014-01-13 10:04:25 -0800 | [diff] [blame] | 397 | return 1; |
| 398 | } |
| 399 | |
| 400 | // If the filesystem it's on isn't encrypted, we only produce the |
| 401 | // block map, we don't rewrite the file contents (it would be |
| 402 | // pointless to do so). |
Doug Zongker | f449db2 | 2014-08-26 09:15:08 -0700 | [diff] [blame] | 403 | ALOGI("encryptable: %s\n", encryptable ? "yes" : "no"); |
| 404 | ALOGI(" encrypted: %s\n", encrypted ? "yes" : "no"); |
Doug Zongker | 76adfc5 | 2014-01-13 10:04:25 -0800 | [diff] [blame] | 405 | |
Doug Zongker | 574443d | 2014-09-05 08:22:12 -0700 | [diff] [blame] | 406 | // Recovery supports installing packages from 3 paths: /cache, |
| 407 | // /data, and /sdcard. (On a particular device, other locations |
| 408 | // may work, but those are three we actually expect.) |
| 409 | // |
| 410 | // On /data we want to convert the file to a block map so that we |
| 411 | // can read the package without mounting the partition. On /cache |
| 412 | // and /sdcard we leave the file alone. |
| 413 | if (strncmp(path, "/data/", 6) != 0) { |
| 414 | // path does not start with "/data/"; leave it alone. |
Doug Zongker | 76adfc5 | 2014-01-13 10:04:25 -0800 | [diff] [blame] | 415 | unlink(RECOVERY_COMMAND_FILE_TMP); |
| 416 | } else { |
Doug Zongker | f449db2 | 2014-08-26 09:15:08 -0700 | [diff] [blame] | 417 | ALOGI("writing block map %s", map_file); |
Doug Zongker | 76adfc5 | 2014-01-13 10:04:25 -0800 | [diff] [blame] | 418 | if (produce_block_map(path, map_file, blk_dev, encrypted) != 0) { |
| 419 | return 1; |
| 420 | } |
| 421 | } |
| 422 | |
Doug Zongker | 2efc9d9 | 2014-08-18 15:55:28 -0700 | [diff] [blame] | 423 | wipe_misc(); |
Doug Zongker | 76adfc5 | 2014-01-13 10:04:25 -0800 | [diff] [blame] | 424 | rename(RECOVERY_COMMAND_FILE_TMP, RECOVERY_COMMAND_FILE); |
Doug Zongker | 2efc9d9 | 2014-08-18 15:55:28 -0700 | [diff] [blame] | 425 | if (do_reboot) reboot_to_recovery(); |
Doug Zongker | 76adfc5 | 2014-01-13 10:04:25 -0800 | [diff] [blame] | 426 | return 0; |
| 427 | } |