summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTao Bao <tbao@google.com>2017-09-29 11:56:14 +0200
committerandroid-build-merger <android-build-merger@google.com>2017-09-29 11:56:14 +0200
commit5eb45473bda706b7b5f0fba5795f90a06ef64731 (patch)
tree37965777c7d3ec2b472485d85a9e4333557b6cea
parentMerge "Add a new option in recovery menu to test the background texts" am: 4c7608f3ca am: 8874d3c309 (diff)
parentMerge "roots: volume_for_path() parses and tries prefixes." am: 3a1587f655 (diff)
downloadandroid_bootable_recovery-5eb45473bda706b7b5f0fba5795f90a06ef64731.tar
android_bootable_recovery-5eb45473bda706b7b5f0fba5795f90a06ef64731.tar.gz
android_bootable_recovery-5eb45473bda706b7b5f0fba5795f90a06ef64731.tar.bz2
android_bootable_recovery-5eb45473bda706b7b5f0fba5795f90a06ef64731.tar.lz
android_bootable_recovery-5eb45473bda706b7b5f0fba5795f90a06ef64731.tar.xz
android_bootable_recovery-5eb45473bda706b7b5f0fba5795f90a06ef64731.tar.zst
android_bootable_recovery-5eb45473bda706b7b5f0fba5795f90a06ef64731.zip
-rw-r--r--roots.cpp21
1 files changed, 20 insertions, 1 deletions
diff --git a/roots.cpp b/roots.cpp
index fdcbfe844..835a1dda0 100644
--- a/roots.cpp
+++ b/roots.cpp
@@ -68,8 +68,27 @@ void load_volume_table() {
printf("\n");
}
+// Finds the volume specified by the given path. fs_mgr_get_entry_for_mount_point() does exact match
+// only, so it attempts the prefixes recursively (e.g. "/cache/recovery/last_log",
+// "/cache/recovery", "/cache", "/" for a given path of "/cache/recovery/last_log") and returns the
+// first match or nullptr.
Volume* volume_for_path(const char* path) {
- return fs_mgr_get_entry_for_mount_point(fstab, path);
+ if (path == nullptr || path[0] == '\0') return nullptr;
+ std::string str(path);
+ while (true) {
+ Volume* result = fs_mgr_get_entry_for_mount_point(fstab, str.c_str());
+ if (result != nullptr || str == "/") {
+ return result;
+ }
+ size_t slash = str.find_last_of('/');
+ if (slash == std::string::npos) return nullptr;
+ if (slash == 0) {
+ str = "/";
+ } else {
+ str = str.substr(0, slash);
+ }
+ }
+ return nullptr;
}
// Mount the volume specified by path at the given mount_point.