struct fstab *fstab_auto_load(void) { char path[64]; path[0] = 0; if(access("/mrom.fstab", F_OK) >= 0) strcpy(path, "/mrom.fstab"); else { DIR *d = opendir("/"); if(!d) { ERROR("Failed to open /\n"); return NULL; } struct dirent *dt; while((dt = readdir(d))) { if(dt->d_type != DT_REG) continue; // For some reason, CM includes goldfish's fstab, ignore it // (goldfish is the virtual device for emulator) if(strcmp(dt->d_name, "fstab.goldfish") == 0) continue; if(strncmp(dt->d_name, "fstab.", sizeof("fstab.")-1) == 0) { strcpy(path, "/"); strcat(path, dt->d_name); // try to find specifically fstab.device if(strcmp(dt->d_name, "fstab."TARGET_DEVICE) == 0) break; } } closedir(d); } if(path[0] == 0) { ERROR("Failed to find fstab!\n"); return NULL; } ERROR("Loading fstab \"%s\"...\n", path); return fstab_load(path); }
// 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); }