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