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

Commit b38966fb authored by David Anderson's avatar David Anderson Committed by Automerger Merge Worker
Browse files

Merge "Support multiple fstab configs for one mount point" am: 9784f5ae am: 5db145c2

Original change: https://android-review.googlesource.com/c/platform/system/core/+/1788172

Change-Id: If14be54ad5bdf9fbb80be4ef3e72458654295771
parents 66546ceb 5db145c2
Loading
Loading
Loading
Loading
+33 −14
Original line number Original line Diff line number Diff line
@@ -14,6 +14,7 @@
 * limitations under the License.
 * limitations under the License.
 */
 */


#include "android-base/file.h"
#include "fs_mgr/roots.h"
#include "fs_mgr/roots.h"


#include <sys/mount.h>
#include <sys/mount.h>
@@ -39,18 +40,26 @@ FstabEntry* GetEntryForPath(Fstab* fstab, const std::string& path) {
    while (true) {
    while (true) {
        auto entry = GetEntryForMountPoint(fstab, str);
        auto entry = GetEntryForMountPoint(fstab, str);
        if (entry != nullptr) return entry;
        if (entry != nullptr) return entry;
        if (str == "/") break;
        str = android::base::Dirname(str);
        auto slash = str.find_last_of('/');
        if (!str.compare(".") || !str.compare("/")) break;
        if (slash == std::string::npos) break;
        if (slash == 0) {
            str = "/";
        } else {
            str = str.substr(0, slash);
        }
    }
    }
    return nullptr;
    return nullptr;
}
}


std::vector<FstabEntry*> GetEntriesForPath(Fstab* fstab, const std::string& path) {
    std::vector<FstabEntry*> entries;
    if (path.empty()) return entries;

    std::string str(path);
    while (true) {
        entries = GetEntriesForMountPoint(fstab, str);
        if (!entries.empty()) return entries;
        str = android::base::Dirname(str);
        if (!str.compare(".") || !str.compare("/")) break;
    }
    return entries;
}

enum class MountState {
enum class MountState {
    ERROR = -1,
    ERROR = -1,
    NOT_MOUNTED = 0,
    NOT_MOUNTED = 0,
@@ -71,12 +80,7 @@ static MountState GetMountState(const std::string& mount_point) {
    return MountState::NOT_MOUNTED;
    return MountState::NOT_MOUNTED;
}
}


bool EnsurePathMounted(Fstab* fstab, const std::string& path, const std::string& mount_pt) {
bool TryPathMount(FstabEntry* rec, const std::string& mount_pt) {
    auto rec = GetEntryForPath(fstab, path);
    if (rec == nullptr) {
        LERROR << "unknown volume for path [" << path << "]";
        return false;
    }
    if (rec->fs_type == "ramdisk") {
    if (rec->fs_type == "ramdisk") {
        // The ramdisk is always mounted.
        // The ramdisk is always mounted.
        return true;
        return true;
@@ -136,6 +140,21 @@ bool EnsurePathMounted(Fstab* fstab, const std::string& path, const std::string&
    return true;
    return true;
}
}


bool EnsurePathMounted(Fstab* fstab, const std::string& path, const std::string& mount_point) {
    auto entries = GetEntriesForPath(fstab, path);
    if (entries.empty()) {
        LERROR << "unknown volume for path [" << path << "]";
        return false;
    }

    for (auto entry : entries) {
        if (TryPathMount(entry, mount_point)) return true;
    }

    LERROR << "Failed to mount for path [" << path << "]";
    return false;
}

bool EnsurePathUnmounted(Fstab* fstab, const std::string& path) {
bool EnsurePathUnmounted(Fstab* fstab, const std::string& path) {
    auto rec = GetEntryForPath(fstab, path);
    auto rec = GetEntryForPath(fstab, path);
    if (rec == nullptr) {
    if (rec == nullptr) {