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

Commit 25d86f56 authored by Bowgo Tsai's avatar Bowgo Tsai
Browse files

allow adb to remount symlink mount points

Currently `adb remount` won't remount symlink mount points.
In Android Generic System Image, there is a symlink
/product -> /system/product for devices with and without a physical
/product partition to work, respectively:

  - Mount product partition under /system/product via
    'mount /product' OR

  - Keep using /product -> /system/product symlink,
    when no product partition

Currently find_proc_mount() is seeking "/product" under /proc/mounts.
But the actual mount path is "/system/product" when GSI is used
on a device with product partition.

Bug: 111539442
Test: adb remount && touch /product/abc on both GSI and non-GSI

Change-Id: I8f15a67109d0a3f4ee18596ef7eb4280c5631b11
Merged-In: I8f15a67109d0a3f4ee18596ef7eb4280c5631b11
(cherry picked from commit 41649b87)
parent 41676471
Loading
Loading
Loading
Loading
+10 −1
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@

#include <string>

#include <android-base/file.h>
#include <android-base/properties.h>

#include "adb.h"
@@ -36,6 +37,8 @@
#include "adb_utils.h"
#include "fs_mgr.h"

using android::base::Realpath;

// Returns the device used to mount a directory in /proc/mounts.
static std::string find_proc_mount(const char* dir) {
    std::unique_ptr<FILE, int(*)(FILE*)> fp(setmntent("/proc/mounts", "r"), endmntent);
@@ -43,9 +46,15 @@ static std::string find_proc_mount(const char* dir) {
        return "";
    }

    // dir might be a symlink, e.g., /product -> /system/product in GSI.
    std::string canonical_path;
    if (!Realpath(dir, &canonical_path)) {
        PLOG(ERROR) << "Realpath failed: " << dir;
    }

    mntent* e;
    while ((e = getmntent(fp.get())) != nullptr) {
        if (strcmp(dir, e->mnt_dir) == 0) {
        if (canonical_path == e->mnt_dir) {
            return e->mnt_fsname;
        }
    }