status_t EmulatedVolume::doUnmount() { int userId = getMountUserId(); // Kill all processes using the filesystem before we unmount it. If we // unmount the filesystem first, most file system operations will return // ENOTCONN until the unmount completes. This is an exotic and unusual // error code and might cause broken behaviour in applications. if (mFuseMounted) { // For FUSE specifically, we have an emulated volume per user, so only kill // processes using files from this particular user. std::string user_path(StringPrintf("%s/%d", getPath().c_str(), getMountUserId())); LOG(INFO) << "jevon line 451 " << user_path; LOG(INFO) << "jevon line 452 " << getPath().c_str(); LOG(INFO) << "jevon line 453 " << getMountUserId(); KillProcessesUsingPath(user_path); } else { LOG(INFO) << "jevon line 456 mFuseMounted = false " << getPath(); KillProcessesUsingPath(getPath()); } if (mFuseMounted) { std::string label = getLabel(); LOG(INFO) << "jevon line 463 mFuseMounted = true " << getLabel(); // Ignoring unmount return status because we do want to try to unmount // the rest cleanly. unmountFuseBindMounts(); if (UnmountUserFuse(userId, getInternalPath(), label) != OK) { PLOG(INFO) << "UnmountUserFuse failed on emulated fuse volume"; PLOG(INFO) << "jevon line 470 UnmountUserFuse failed on emulated fuse volume"; return -errno; } mFuseMounted = false; } return unmountSdcardFs(); } 代码解析
时间: 2024-01-17 15:05:52 浏览: 111
EmulatedVolume::doUnmount()
函数是 Android 系统中 EmulatedVolume 类的一个成员函数,用于执行虚拟卷的卸载操作。
下面是函数中每一行代码的解释:
int userId = getMountUserId();
获取当前挂载虚拟卷的用户 ID。
if (mFuseMounted) {
std::string user_path(StringPrintf("%s/%d", getPath().c_str(), getMountUserId()));
LOG(INFO) << "jevon line 451 " << user_path;
LOG(INFO) << "jevon line 452 " << getPath().c_str();
LOG(INFO) << "jevon line 453 " << getMountUserId();
KillProcessesUsingPath(user_path);
} else {
LOG(INFO) << "jevon line 456 mFuseMounted = false " << getPath();
KillProcessesUsingPath(getPath());
}
如果虚拟卷使用 FUSE 文件系统,只杀死使用该用户的进程。否则,杀死所有使用虚拟卷的进程。
if (mFuseMounted) {
std::string label = getLabel();
LOG(INFO) << "jevon line 463 mFuseMounted = true " << getLabel();
unmountFuseBindMounts();
if (UnmountUserFuse(userId, getInternalPath(), label) != OK) {
PLOG(INFO) << "UnmountUserFuse failed on emulated fuse volume";
PLOG(INFO) << "jevon line 470 UnmountUserFuse failed on emulated fuse volume";
return -errno;
}
mFuseMounted = false;
}
如果虚拟卷使用 FUSE 文件系统,则卸载 FUSE 绑定点并卸载 FUSE 文件系统。如果卸载失败,则返回错误码。
return unmountSdcardFs();
卸载虚拟卷的文件系统。
综上所述,EmulatedVolume::doUnmount()
函数主要完成以下操作:
- 获取当前用户 ID;
- 杀死使用虚拟卷的进程;
- 卸载 FUSE 绑定点和 FUSE 文件系统(如果使用 FUSE 文件系统);
- 卸载虚拟卷的文件系统。
阅读全文
相关推荐



















