From e3ba93a60f2af21c0aeb8538ca3bbda083b83475 Mon Sep 17 00:00:00 2001 From: Alessandro Astone Date: Sun, 1 Mar 2020 13:33:27 +0100 Subject: recovery: make /etc/fstab only include entries that match the detected fs type * toybox's `mount` does not support multiple entries like we do, so if we can detect the filesystem of an fstab enrtry print that and only that one to /etc/fstab, so that mounting via toybox has a better chance of succeding. * as a bonus, this patch also gets rid of duplicates in /etc/fstab caused by the fact that ReadDefaultFstab() combines entries from DT and from recovery.fstab Change-Id: Iec4ab38044054555d2a33da6f5d53de7716e7bee --- roots.cpp | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/roots.cpp b/roots.cpp index 57977f36..c361bf7e 100644 --- a/roots.cpp +++ b/roots.cpp @@ -72,6 +72,9 @@ Volume* get_device_volumes() { return fstab->recs; } +// We need this declared for load_volume_table(). +Volume* get_entry_for_mount_point_detect_fs(const std::string&); + void load_volume_table() { fstab = fs_mgr_read_fstab_default(); if (!fstab) { @@ -87,24 +90,31 @@ void load_volume_table() { return; } - // Create a boring /etc/fstab so tools like Busybox work - FILE* file = fopen("/etc/fstab", "w"); - if (!file) { - LOG(ERROR) << "Unable to create /etc/fstab"; - } - + struct fstab* fake_fstab = static_cast(calloc(1, sizeof(struct fstab))); printf("recovery filesystem table\n"); printf("=========================\n"); for (int i = 0; i < fstab->num_entries; ++i) { const Volume* v = &fstab->recs[i]; printf(" %d %s %s %s %lld\n", i, v->mount_point, v->fs_type, v->blk_device, v->length); - if (file) { - write_fstab_entry(v, file); + if (fs_mgr_get_entry_for_mount_point(fake_fstab, v->mount_point) == NULL) { + const Volume* v_detectfs = get_entry_for_mount_point_detect_fs(v->mount_point); + if (!strcmp(v->fs_type, v_detectfs->fs_type)) { + fs_mgr_add_entry(fake_fstab, v->mount_point, v->fs_type, v->blk_device); + } } } printf("\n"); + + // Create a boring /etc/fstab so tools like Busybox work + FILE* file = fopen("/etc/fstab", "w"); if (file) { + for (int i = 0; i < fake_fstab->num_entries; ++i) { + write_fstab_entry(&fake_fstab->recs[i], file); + } fclose(file); + fs_mgr_free_fstab(fake_fstab); + } else { + LOG(ERROR) << "Unable to create /etc/fstab"; } } -- cgit v1.2.3