Merge "Add unmountTree to utils." am: a64572431e

am: f5b24f1015

Change-Id: I4e0a8b784b541013cf1028fbe1ed54dfd31d2782
gugelfrei
Sudheer Shanka 6 years ago committed by android-build-merger
commit e9c88c4c6c

@ -31,6 +31,8 @@
#include <dirent.h>
#include <fcntl.h>
#include <linux/fs.h>
#include <mntent.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/mount.h>
#include <sys/stat.h>
@ -38,6 +40,7 @@
#include <sys/sysmacros.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <list>
#include <mutex>
#ifndef UMOUNT_NOFOLLOW
@ -758,5 +761,32 @@ bool IsRunningInEmulator() {
return android::base::GetBoolProperty("ro.kernel.qemu", false);
}
status_t UnmountTree(const std::string& prefix) {
FILE* fp = setmntent("/proc/mounts", "r");
if (fp == NULL) {
PLOG(ERROR) << "Failed to open /proc/mounts";
return -errno;
}
// Some volumes can be stacked on each other, so force unmount in
// reverse order to give us the best chance of success.
std::list<std::string> toUnmount;
mntent* mentry;
while ((mentry = getmntent(fp)) != NULL) {
auto test = std::string(mentry->mnt_dir) + "/";
if (android::base::StartsWith(test, prefix)) {
toUnmount.push_front(test);
}
}
endmntent(fp);
for (const auto& path : toUnmount) {
if (umount2(path.c_str(), MNT_DETACH)) {
PLOG(ERROR) << "Failed to unmount " << path;
}
}
return OK;
}
} // namespace vold
} // namespace android

@ -130,6 +130,8 @@ bool Readlinkat(int dirfd, const std::string& path, std::string* result);
/* Checks if Android is running in QEMU */
bool IsRunningInEmulator();
status_t UnmountTree(const std::string& prefix);
} // namespace vold
} // namespace android

@ -411,30 +411,7 @@ int VolumeManager::setPrimary(const std::shared_ptr<android::vold::VolumeBase>&
}
static int unmount_tree(const std::string& prefix) {
FILE* fp = setmntent("/proc/mounts", "r");
if (fp == NULL) {
PLOG(ERROR) << "Failed to open /proc/mounts";
return -errno;
}
// Some volumes can be stacked on each other, so force unmount in
// reverse order to give us the best chance of success.
std::list<std::string> toUnmount;
mntent* mentry;
while ((mentry = getmntent(fp)) != NULL) {
auto test = std::string(mentry->mnt_dir) + "/";
if (android::base::StartsWith(test, prefix)) {
toUnmount.push_front(test);
}
}
endmntent(fp);
for (const auto& path : toUnmount) {
if (umount2(path.c_str(), MNT_DETACH)) {
PLOG(ERROR) << "Failed to unmount " << path;
}
}
return 0;
return android::vold::UnmountTree(prefix);
}
int VolumeManager::remountUid(uid_t uid, const std::string& mode) {

Loading…
Cancel
Save