From ccd094cd4e7b24e1209b3ad4a64d1a890b76010c Mon Sep 17 00:00:00 2001 From: Lianjun Huang Date: Fri, 17 Feb 2023 20:22:37 +0800 Subject: [PATCH] Fix failure on mounting system_ext partition There can be more than one fstab entry of system partition. For example, the filesystem of one entry is ext4 and another is erofs. system /system ext4 ro wait,slotselect,avb=vbmeta_system,logical,first_stage_mount,avb_keys=/avb/q-gsi.avbpubkey:/avb/r-gsi.avbpubkey:/avb/s-gsi.avbpubkey system /system erofs ro wait,slotselect,avb=vbmeta_system,logical,first_stage_mount,avb_keys=/avb/q-gsi.avbpubkey:/avb/r-gsi.avbpubkey:/avb/s-gsi.avbpubkey If both filesystems of system and system_ext paritions are erofs, only the ext4 fstab entry will be returned by GetEntryForMountPoint, and system_ext cann't be mounted. So we need to return both of the fstab entries and try all of them. Signed-off-by: Lianjun Huang Change-Id: I407553d48b1749cd0554f057a6bfd38daa96fdcb Signed-off-by: Lianjun Huang --- init/selinux.cpp | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/init/selinux.cpp b/init/selinux.cpp index 4cc00feb5..062ed3915 100644 --- a/init/selinux.cpp +++ b/init/selinux.cpp @@ -897,29 +897,31 @@ void MountMissingSystemPartitions() { continue; } - auto system_entry = GetEntryForMountPoint(&fstab, "/system"); - if (!system_entry) { - LOG(ERROR) << "Could not find mount entry for /system"; - break; - } - if (!system_entry->fs_mgr_flags.logical) { - LOG(INFO) << "Skipping mount of " << name << ", system is not dynamic."; - break; - } + auto system_entries = GetEntriesForMountPoint(&fstab, "/system"); + for (auto& system_entry : system_entries) { + if (!system_entry) { + LOG(ERROR) << "Could not find mount entry for /system"; + break; + } + if (!system_entry->fs_mgr_flags.logical) { + LOG(INFO) << "Skipping mount of " << name << ", system is not dynamic."; + break; + } - auto entry = *system_entry; - auto partition_name = name + fs_mgr_get_slot_suffix(); - auto replace_name = "system"s + fs_mgr_get_slot_suffix(); + auto entry = *system_entry; + auto partition_name = name + fs_mgr_get_slot_suffix(); + auto replace_name = "system"s + fs_mgr_get_slot_suffix(); - entry.mount_point = "/"s + name; - entry.blk_device = + entry.mount_point = "/"s + name; + entry.blk_device = android::base::StringReplace(entry.blk_device, replace_name, partition_name, false); - if (!fs_mgr_update_logical_partition(&entry)) { - LOG(ERROR) << "Could not update logical partition"; - continue; - } + if (!fs_mgr_update_logical_partition(&entry)) { + LOG(ERROR) << "Could not update logical partition"; + continue; + } - extra_fstab.emplace_back(std::move(entry)); + extra_fstab.emplace_back(std::move(entry)); + } } SkipMountingPartitions(&extra_fstab, true /* verbose */);