static int mount_and_run(struct fstab *fstab) { struct fstab_part *datap = fstab_find_first_by_path(fstab, "/data"); if(!datap) { ERROR("Failed to find /data partition in fstab\n"); return -1; } if(access(datap->device, R_OK) < 0) { INFO("Waiting for %s\n", datap->device); if(wait_for_file(datap->device, 5) < 0) { ERROR("Waiting too long for dev %s\n", datap->device); return -1; } } mkdir(REALDATA, 0755); if(try_mount_all_entries(fstab, datap) < 0) { #ifndef MR_ENCRYPTION ERROR("Failed to mount /data with all possible filesystems!\n"); return -1; #else INFO("Failed to mount /data, trying encryption...\n"); switch(encryption_before_mount(fstab)) { case ENC_RES_ERR: ERROR("/data decryption failed!\n"); return -1; case ENC_RES_BOOT_INTERNAL: return 0; default: case ENC_RES_OK: { if(try_mount_all_entries(fstab, datap) < 0) { ERROR("Failed to mount decrypted /data with all possible filesystems!\n"); return -1; } break; } } #endif } if(find_multirom() == -1) { ERROR("Could not find multirom folder!\n"); return -1; } adb_init(path_multirom); run_multirom(); adb_quit(); return 0; }
// functions used by workaround char *nokexec_find_boot_mmcblk_path(struct multirom_status *s) { struct fstab_part *boot = NULL; INFO(NO_KEXEC_LOG_TEXT ": locating boot partition...\n"); if (!s) { INFO(NO_KEXEC_LOG_TEXT ": 'multirom_status' not set up yet, fstab_auto_load ourselves\n"); struct fstab *fstab; fstab = fstab_auto_load(); if (fstab) { boot = fstab_find_first_by_path(fstab, "/boot"); fstab_destroy(fstab); } } else if (s->fstab) boot = fstab_find_first_by_path(s->fstab, "/boot"); if (boot) INFO(NO_KEXEC_LOG_TEXT ": found boot at '%s'\n", boot->device); else { INFO(NO_KEXEC_LOG_TEXT ": not found in fstab, try looking at mrom.fstab...\n"); struct fstab *mrom_fstab; char path_mrom_fstab[256]; sprintf(path_mrom_fstab, "%s/%s", mrom_dir(), "mrom.fstab"); mrom_fstab = fstab_load(path_mrom_fstab, 1); if (!mrom_fstab) { ERROR(NO_KEXEC_LOG_TEXT ": couldn't load mrom.fstab '%s'\n", path_mrom_fstab); return NULL; } boot = fstab_find_first_by_path(mrom_fstab, "/boot"); if (boot) INFO(NO_KEXEC_LOG_TEXT ": found boot (using mrom.fstab) at '%s'\n", boot->device); else return NULL; } return strdup(boot->device); }
int main(int argc, char *argv[]) { mrom_set_log_tag("fw_mounter"); struct fstab *f = fstab_load(FW_MOUNTER_FSTAB, 0); if(!f) { ERROR("Failed to load %s\n", FW_MOUNTER_FSTAB); return -1; } struct fstab_part *fw_part = fstab_find_first_by_path(f, "/firmware"); if(!fw_part) { ERROR("Unable to find partition /firmware in %s!\n", FW_MOUNTER_FSTAB); return -1; } ERROR("Mounting %s to %s\n", fw_part->device, fw_part->path); return mount_image(fw_part->device, fw_part->path, fw_part->type, fw_part->mountflags, fw_part->options); }
int main(int argc, char *argv[]) { int i; int res = 1; int cmd = CMD_NONE; int stdout_fd; char footer_location[256]; struct fstab *fstab; struct fstab_part *p; char *argument = NULL; klog_init(); // output all messages to dmesg, // but it is possible to filter out INFO messages klog_set_level(6); mrom_set_log_tag("trampoline_encmnt"); mrom_set_dir("/mrom_enc/"); for(i = 1; i < argc; ++i) { if(!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) { print_help(argv); return 0; } else if(cmd == CMD_NONE) { if(strcmp(argv[i], "decrypt") == 0) cmd = CMD_DECRYPT; else if(strcmp(argv[i], "remove") == 0) cmd = CMD_REMOVE; else if(strcmp(argv[i], "pwtype") == 0) cmd = CMD_PWTYPE; } else if(!argument) { argument = argv[i]; } } if(argc == 1 || cmd == CMD_NONE) { print_help(argv); return 0; } fstab = fstab_auto_load(); if(!fstab) { ERROR("Failed to load fstab!"); return 1; } p = fstab_find_first_by_path(fstab, "/data"); if(!p) { ERROR("Failed to find /data partition in fstab\n"); goto exit; } strcpy(footer_location, ""); if(p->options != NULL && get_footer_from_opts(footer_location, sizeof(footer_location), p->options) < 0) goto exit; if(p->options2 != NULL && strcmp(footer_location, "") == 0 && get_footer_from_opts(footer_location, sizeof(footer_location), p->options2) < 0) goto exit; INFO("Setting encrypted partition data to %s %s %s\n", p->device, footer_location, p->type); set_partition_data(p->device, footer_location, p->type); // cryptfs prints informations, we don't want that stdout_fd = dup(1); freopen("/dev/null", "ae", stdout); switch(cmd) { case CMD_PWTYPE: if(handle_pwtype(stdout_fd) < 0) goto exit; break; case CMD_DECRYPT: if(handle_decrypt(stdout_fd, argument) < 0) goto exit; break; case CMD_REMOVE: if(handle_remove() < 0) goto exit; break; } res = 0; exit: fstab_destroy(fstab); return res; }