Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit dc9268fc authored by Alessandro Astone's avatar Alessandro Astone Committed by Michael Bestas
Browse files

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
parent 0c3b2bd1
Loading
Loading
Loading
Loading
+17 −8
Original line number Diff line number Diff line
@@ -66,12 +66,6 @@ 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";
  }

  fstab.emplace_back(FstabEntry{
      .blk_device = "ramdisk",
      .mount_point = "/tmp",
@@ -79,20 +73,35 @@ void load_volume_table() {
      .length = 0,
  });

  Fstab fake_fstab;
  std::cout << "recovery filesystem table" << std::endl << "=========================" << std::endl;
  for (size_t i = 0; i < fstab.size(); ++i) {
    const auto& entry = fstab[i];
    std::cout << "  " << i << " " << entry.mount_point << " "
              << " " << entry.fs_type << " " << entry.blk_device << " " << entry.length
              << std::endl;
    if (file) {
      write_fstab_entry(entry, file);

    if (std::find_if(fake_fstab.begin(), fake_fstab.end(), [entry](const FstabEntry& e) {
          return entry.mount_point == e.mount_point;
        }) == fake_fstab.end()) {
      FstabEntry* entry_detectfs =
          android::fs_mgr::GetEntryForMountPointTryDetectFs(&fstab, entry.mount_point);
      if (entry_detectfs == &entry) {
        fake_fstab.emplace_back(entry);
      }
    }
  }
  std::cout << std::endl;

  // Create a boring /etc/fstab so tools like Busybox work
  FILE* file = fopen("/etc/fstab", "w");
  if (file) {
    for (auto& entry : fake_fstab) {
      write_fstab_entry(entry, file);
    }
    fclose(file);
  } else {
    LOG(ERROR) << "Unable to create /etc/fstab";
  }
}