int ensure_path_unmounted(const char* path) { const Volume* volume = get_volume_for_path(path); if(volume == NULL) { ui_print("RECOVERY::ensure_path_unmounted: Unable to locate a volume suitable for path %s\n", path); return -1; } return unmount_volume(volume, NULL); // Mount the volume if necessary }
static int submenu_restoreonevolume(const Volume* volume) { char** headers = NULL; // UI menu headers const Volume* sdvolume; // SDCARD volume int sdmounted; // Flag if SDCARD was mounted char filter[256]; // Directory browse filter string char imgfile[256]; // Selected image file to restore int nav; // Menu navigation code int result; // Result from function call // Allocate a standard header headers = alloc_standard_header(SUBHEADER_RESTOREVOLUMES); if(headers == NULL) { LOGE("submenu_restoreonevolume: Cannot allocate menu headers"); return NAVIGATE_ERROR; } // Grab a reference to the SDCARD volume sdvolume = get_volume("SDCARD"); if(sdvolume == NULL) { LOGE("submenu_restoreonevolume: Cannot locate SDCARD volume entry in fstab"); return NAVIGATE_ERROR; } // The SDCARD volume has to be mounted before we can browse it (obviously) result = mount_volume(sdvolume, &sdmounted); if(result != 0) { LOGE("submenu_restoreonevolume: Cannot mount SDCARD volume"); return NAVIGATE_ERROR; } // Generate the directory browse filter string. Backup files can have a number of different // extensions, but if they were created by this recovery they will have the volume name in // ALL CAPS as the base file name snprintf(filter, 256, "%s*.*", volume->name); // Invoke the directory browser against the root of the SDCARD ... nav = navigate_menu_browse(headers, sdvolume->mount_point, filter, imgfile, 256); if(nav == NAVIGATE_SELECT) nav = submenu_restoreonevolume_confirm(volume, imgfile); // Unmount the SDCARD volume if it was mounted by this function if(sdmounted) unmount_volume(sdvolume, NULL); free_menu_list(headers); // Release the string array return nav; // Return navigation code }
int main(int argc, char **argv) { int interactive = 1; time_t start = time(NULL); // If these fail, there's not really anywhere to complain... freopen(TEMPORARY_LOG_FILE, "a", stdout); setbuf(stdout, NULL); freopen(TEMPORARY_LOG_FILE, "a", stderr); setbuf(stderr, NULL); printf("Starting recovery on %s", ctime(&start)); ui_init(); ui_set_background(BACKGROUND_ICON_INSTALLING); // djp952 - at least for now I want to see everything ui_show_text(1); volumes_init("/sbin/recovery.fstab"); get_args(&argc, &argv); int previous_runs = 0; const char *send_intent = NULL; const char *update_package = NULL; int wipe_data = 0, wipe_cache = 0; int toggle_secure_fs = 0; // TEMP: Dump arguments to see what they look like //int index = 0; //for(index = 0; index < argc; index++) ui_print("ARG%d = [%s]\n", index, argv[index]); int arg; while ((arg = getopt_long(argc, argv, "", OPTIONS, NULL)) != -1) { switch (arg) { case 'p': previous_runs = atoi(optarg); break; case 's': send_intent = optarg; break; case 'u': update_package = optarg; break; case 'w': wipe_data = 1; break; case 'c': wipe_cache = 1; break; case 't': ui_show_text(1); break; case '?': LOGE("Invalid command argument: %c\n", arg); continue; } } device_recovery_start(); //if (update_package) { // // For backwards compatibility on the cache partition only, if // // we're given an old 'root' path "CACHE:foo", change it to // // "/cache/foo". // if (strncmp(update_package, "CACHE:", 6) == 0) { // int len = strlen(update_package) + 10; // char* modified_path = malloc(len); // strlcpy(modified_path, "/cache/", len); // strlcat(modified_path, update_package+6, len); // printf("(replacing path \"%s\" with \"%s\")\n", // update_package, modified_path); // update_package = modified_path; // } //} //printf("\n"); property_list(print_property, NULL); printf("\n"); // // EXECUTE RECOVERY // // Automatic: --wipe_data if(wipe_data) { interactive = 0; // No interactive menu mode cmd_wipe_device(); // Wipe the device } // Automatic: --wipe_cache if(wipe_cache) { interactive = 0; // No interactive menu mode cmd_wipe_cache(); // Wipe the cache } // Interactive if(interactive) { cmd_show_usage(); // Explain how to navigate menu_mainmenu(); // Launch the main menu } // // FINISH RECOVERY // // Clean up and write out the logs finish_recovery(send_intent); // Unmount all volumes const Volume* iterator = foreach_volume(NULL); while(iterator != NULL) { unmount_volume(iterator, NULL); iterator = foreach_volume(iterator); } sync(); // One more sync for good luck reboot(RB_AUTOBOOT); // Reboot return EXIT_SUCCESS; // Done }