mirror of
https://gitee.com/openharmony/filemanagement_storage_service
synced 2024-11-23 06:59:59 +00:00
【master】【storage_service】解决跨应用访问数据失败问题测试
Signed-off-by: zhangchenyang <zhangchenyang30@huawei.com>
This commit is contained in:
parent
ea1006d59d
commit
d18a2a1fd1
@ -74,10 +74,12 @@ public:
|
||||
static std::vector<DirInfo> InitVirtualDir();
|
||||
static std::vector<DirInfo> InitSystemServiceDir();
|
||||
static std::vector<DirInfo> InitFileManagerDir();
|
||||
static std::vector<DirInfo> InitAppdataDir();
|
||||
int32_t MountByUser(int32_t userId);
|
||||
int32_t UmountByUser(int32_t userId);
|
||||
int32_t PrepareHmdfsDirs(int32_t userId);
|
||||
int32_t PrepareFileManagerDirs(int32_t userId);
|
||||
int32_t PrepareAppdataDir(int32_t userId);
|
||||
int32_t DestroyHmdfsDirs(int32_t userId);
|
||||
int32_t DestroyFileManagerDirs(int32_t userId);
|
||||
int32_t DestroySystemServiceDirs(int32_t userId);
|
||||
@ -90,7 +92,6 @@ public:
|
||||
const std::string &networkId, const std::string &deviceId);
|
||||
int32_t UMountAllPath(int32_t userId, std::list<std::string> &mountFailList);
|
||||
int32_t UMountByList(std::list<std::string> &list, std::list<std::string> &mountFailList);
|
||||
int32_t DeleteSceneDir(int32_t userId);
|
||||
void SetCloudState(bool active);
|
||||
int32_t RestoreconSystemServiceDirs(int32_t userId);
|
||||
int32_t FindMountPointsToMap(std::map<std::string, std::list<std::string>> &mountMap, int32_t userId);
|
||||
@ -116,6 +117,7 @@ private:
|
||||
int32_t HmdfsTwiceMount(int32_t userId, const std::string &relativePath);
|
||||
int32_t HmdfsUMount(int32_t userId, std::string relativePath);
|
||||
int32_t SharefsMount(int32_t userId);
|
||||
int32_t HmSharefsMount(int32_t userId, std::string &srcPath, std::string &dstPath);
|
||||
int32_t LocalMount(int32_t userId);
|
||||
int32_t LocalUMount(int32_t userId);
|
||||
int32_t SetFafQuotaProId(int32_t userId);
|
||||
@ -125,6 +127,15 @@ private:
|
||||
void PrepareFileManagerDir(int32_t userId);
|
||||
int32_t CloudUMount(int32_t userId);
|
||||
bool CheckPathValid(const std::string &bundleNameStr, uint32_t userId);
|
||||
int32_t MountAppdataAndSharefs(int32_t userId);
|
||||
int32_t MountAppdata(const std::string &userId);
|
||||
bool DirExist(const std::string &dir);
|
||||
void GetAllUserId(std::vector<int32_t> &userIds);
|
||||
int32_t PrepareAppdataDirByUserId(int32_t userId);
|
||||
int32_t MountSharefsAndNoSharefs(int32_t userId);
|
||||
int32_t SharedMount(const std::string &path);
|
||||
int32_t BindAndRecMount(std::string &srcPath, std::string &dstPath, bool isUseSlave = true);
|
||||
int32_t UmountMntUserTmpfs(int32_t userId);
|
||||
|
||||
DISALLOW_COPY_AND_MOVE(MountManager);
|
||||
|
||||
@ -133,6 +144,7 @@ private:
|
||||
const std::vector<DirInfo> virtualDir_;
|
||||
const std::vector<DirInfo> systemServiceDir_;
|
||||
const std::vector<DirInfo> fileManagerDir_;
|
||||
const std::vector<DirInfo> appdataDir_;
|
||||
std::mutex mountMutex_;
|
||||
std::vector<int32_t> fuseToMountUsers_;
|
||||
std::vector<int32_t> fuseMountedUsers_;
|
||||
|
@ -38,6 +38,7 @@ struct MountArgument final {
|
||||
std::string GetShareSrc() const;
|
||||
std::string GetShareDst() const;
|
||||
std::string GetUserIdPara() const;
|
||||
std::string GetHmUserIdPara() const;
|
||||
std::string GetCommFullPath() const;
|
||||
std::string GetCloudFullPath() const;
|
||||
std::string GetCachePath() const;
|
||||
@ -49,6 +50,17 @@ struct MountArgument final {
|
||||
std::string GetLocalDocsPath() const;
|
||||
std::string GetMountPointPrefix() const;
|
||||
std::string GetSandboxPath() const;
|
||||
std::string GetMntUserPath() const;
|
||||
std::string GetMediaDocsPath() const;
|
||||
std::string GetNoSharefsDocPath() const;
|
||||
std::string GetNoSharefsDocCurPath() const;
|
||||
std::string GetSharefsDocPath() const;
|
||||
std::string GetSharefsDocCurPath() const;
|
||||
std::string GetCurOtherPath() const;
|
||||
std::string GetCurOtherAppdataPath() const;
|
||||
std::string GetCurFileMgrPath() const;
|
||||
std::string GetCurFileMgrAppdataPath() const;
|
||||
std::string GetNoSharefsAppdataPath() const;
|
||||
unsigned long GetFlags() const;
|
||||
};
|
||||
|
||||
|
@ -332,8 +332,9 @@ int32_t StorageDaemon::PrepareUserDirs(int32_t userId, uint32_t flags)
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
return UserManager::GetInstance()->PrepareUserDirs(userId, flags);
|
||||
int32_t prepareRet = UserManager::GetInstance()->PrepareUserDirs(userId, flags);
|
||||
MountManager::GetInstance()->PrepareAppdataDir(userId);
|
||||
return prepareRet;
|
||||
}
|
||||
|
||||
int32_t StorageDaemon::DestroyUserDirs(int32_t userId, uint32_t flags)
|
||||
@ -463,7 +464,7 @@ int32_t StorageDaemon::InitGlobalUserKeys(void)
|
||||
AuditLog storageAuditLog = { false, "FAILED TO PrepareUserDirs", "ADD", "PrepareUserDirs", 1, "FAIL" };
|
||||
HiAudit::GetInstance().Write(storageAuditLog);
|
||||
}
|
||||
|
||||
MountManager::GetInstance()->PrepareAppdataDir(GLOBAL_USER_ID);
|
||||
std::thread thread([this]() { SetDeleteFlag4KeyFiles(); });
|
||||
thread.detach();
|
||||
return result;
|
||||
|
@ -55,21 +55,19 @@ using namespace OHOS::FileManagement::CloudFile;
|
||||
using namespace OHOS::StorageService;
|
||||
constexpr int32_t UMOUNT_RETRY_TIMES = 3;
|
||||
constexpr int32_t ONE_KB = 1024;
|
||||
constexpr int32_t DEFAULT_USERID = 100;
|
||||
std::shared_ptr<MountManager> MountManager::instance_ = nullptr;
|
||||
|
||||
const string SANDBOX_ROOT_PATH = "/mnt/sandbox/";
|
||||
const string CURRENT_USER_ID_FLAG = "<currentUserId>";
|
||||
const string PACKAGE_NAME_FLAG = "<bundleName>";
|
||||
const string SCENE_BOARD_BUNDLE_NAME = "com.ohos.sceneboard";
|
||||
const string STORAGE_USERS_PATH = "/storage/Users";
|
||||
const string PUBLIC_DIR_SANDBOX_PATH = "/storage/Users/currentUser";
|
||||
const string PUBLIC_DIR_SRC_PATH = "/storage/media/<currentUserId>/local/files/Docs";
|
||||
const string MOUNT_POINT_INFO = "/proc/mounts";
|
||||
const string MOUNT_POINT_TYPE_HMDFS = "hmdfs";
|
||||
const string MOUNT_POINT_TYPE_HMFS = "hmfs";
|
||||
const string MOUNT_POINT_TYPE_SHAREFS = "sharefs";
|
||||
const string EL2_BASE = "/data/storage/el2/base/";
|
||||
const string MOUNT_SUFFIX = "_locked";
|
||||
const string APP_EL1_PATH = "/data/app/el1";
|
||||
const set<string> SANDBOX_EXCLUDE_PATH = {
|
||||
"chipset",
|
||||
"system",
|
||||
@ -103,6 +101,21 @@ const vector<string> CRYPTO_SRC_PATH = {
|
||||
"/data/app/el5/<currentUserId>/base/<bundleName>/",
|
||||
"/data/app/el5/<currentUserId>/database/<bundleName>/"
|
||||
};
|
||||
|
||||
const vector<string> APPDATA_DST_PATH = {
|
||||
"/mnt/user/<currentUserId>/nosharefs/appdata/el1/base/",
|
||||
"/mnt/user/<currentUserId>/nosharefs/appdata/el2/base/",
|
||||
"/mnt/user/<currentUserId>/nosharefs/appdata/el2/cloud/",
|
||||
"/mnt/user/<currentUserId>/nosharefs/appdata/el2/distributedfiles/"
|
||||
};
|
||||
|
||||
const vector<string> APPDATA_SRC_PATH = {
|
||||
"/data/app/el1/<currentUserId>/base/",
|
||||
"/data/app/el2/<currentUserId>/base/",
|
||||
"/mnt/hmdfs/<currentUserId>/cloud/data/",
|
||||
"/mnt/hmdfs/<currentUserId>/account/merge_view/data/"
|
||||
};
|
||||
|
||||
const std::string HMDFS_SYS_CAP = "const.distributed_file_property.enabled";
|
||||
const int32_t HMDFS_VAL_LEN = 6;
|
||||
const int32_t HMDFS_TRUE_LEN = 5;
|
||||
@ -111,7 +124,7 @@ static constexpr int MODE_0711 = 0711;
|
||||
static constexpr int MODE_0771 = 0771;
|
||||
static constexpr int MODE_02771 = 02771;
|
||||
MountManager::MountManager() : hmdfsDirVec_(InitHmdfsDirVec()), virtualDir_(InitVirtualDir()),
|
||||
systemServiceDir_(InitSystemServiceDir()), fileManagerDir_(InitFileManagerDir())
|
||||
systemServiceDir_(InitSystemServiceDir()), fileManagerDir_(InitFileManagerDir()), appdataDir_(InitAppdataDir())
|
||||
{
|
||||
}
|
||||
|
||||
@ -197,6 +210,28 @@ std::vector<DirInfo> MountManager::InitFileManagerDir()
|
||||
{"/data/service/el2/%d/hmdfs/account/files/.Recent", MODE_02771, OID_FILE_MANAGER, OID_FILE_MANAGER}};
|
||||
}
|
||||
|
||||
std::vector<DirInfo> MountManager::InitAppdataDir()
|
||||
{
|
||||
return {{"/mnt/user", MODE_0711, OID_ROOT, OID_ROOT},
|
||||
{"/mnt/user/%d", MODE_0711, OID_ROOT, OID_ROOT},
|
||||
{"/mnt/user/%d/nosharefs", MODE_0711, OID_ROOT, OID_ROOT},
|
||||
{"/mnt/user/%d/nosharefs/docs", MODE_0711, OID_ROOT, OID_ROOT},
|
||||
{"/mnt/user/%d/nosharefs/docs/currentUser", MODE_0711, OID_ROOT, OID_ROOT},
|
||||
{"/mnt/user/%d/nosharefs/appdata", MODE_0711, OID_ROOT, OID_ROOT},
|
||||
{"/mnt/user/%d/nosharefs/appdata/el1", MODE_0711, OID_ROOT, OID_ROOT},
|
||||
{"/mnt/user/%d/nosharefs/appdata/el1/base", MODE_0711, OID_ROOT, OID_ROOT},
|
||||
{"/mnt/user/%d/nosharefs/appdata/el2", MODE_0711, OID_ROOT, OID_ROOT},
|
||||
{"/mnt/user/%d/nosharefs/appdata/el2/base", MODE_0711, OID_ROOT, OID_ROOT},
|
||||
{"/mnt/user/%d/nosharefs/appdata/el2/cloud", MODE_0711, OID_ROOT, OID_ROOT},
|
||||
{"/mnt/user/%d/nosharefs/appdata/el2/distributedfiles", MODE_0711, OID_ROOT, OID_ROOT},
|
||||
{"/mnt/user/%d/sharefs", MODE_0711, OID_ROOT, OID_ROOT},
|
||||
{"/mnt/user/%d/sharefs/docs", MODE_0711, OID_ROOT, OID_ROOT},
|
||||
{"/mnt/user/%d/sharefs/docs/currentUser", MODE_0711, OID_ROOT, OID_ROOT},
|
||||
{"/mnt/user/%d/currentUser", MODE_0711, OID_ROOT, OID_ROOT},
|
||||
{"/mnt/user/%d/currentUser/filemgr", MODE_0711, OID_ROOT, OID_ROOT},
|
||||
{"/mnt/user/%d/currentUser/other", MODE_0711, OID_ROOT, OID_ROOT}};
|
||||
}
|
||||
|
||||
int32_t MountManager::HmdfsTwiceMount(int32_t userId, const std::string &relativePath)
|
||||
{
|
||||
int32_t ret = HmdfsMount(userId, relativePath);
|
||||
@ -251,6 +286,30 @@ int32_t MountManager::SharefsMount(int32_t userId)
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
int32_t MountManager::HmSharefsMount(int32_t userId, std::string &srcPath, std::string &dstPath)
|
||||
{
|
||||
if (IsDir(srcPath)) {
|
||||
LOGE("srcPath not exist, %{public}s", srcPath.c_str());
|
||||
return ENOENT;
|
||||
}
|
||||
if (IsDir(dstPath)) {
|
||||
LOGE("srcPath not exist, %{public}s", dstPath.c_str());
|
||||
return ENOENT;
|
||||
}
|
||||
if (IsPathMounted(dstPath)) {
|
||||
LOGI("path has mounted, %{public}s", dstPath.c_str());
|
||||
return E_OK;
|
||||
}
|
||||
Utils::MountArgument sharefsMntArgs(Utils::MountArgumentDescriptors::Alpha(userId, ""));
|
||||
int ret = Mount(srcPath, dstPath, "sharefs", sharefsMntArgs.GetFlags(),
|
||||
sharefsMntArgs.GetHmUserIdPara().c_str());
|
||||
if (ret != 0) {
|
||||
LOGE("failed to mount hmSharefs, err %{public}d", errno);
|
||||
return E_MOUNT;
|
||||
}
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
int32_t MountManager::HmdfsMount(int32_t userId, std::string relativePath, bool mountCloudDisk)
|
||||
{
|
||||
Utils::MountArgument hmdfsMntArgs(Utils::MountArgumentDescriptors::Alpha(userId, relativePath));
|
||||
@ -636,10 +695,6 @@ int32_t MountManager::MountCryptoPathAgain(uint32_t userId)
|
||||
}
|
||||
vector<string> dstPaths = CRYPTO_SANDBOX_PATH;
|
||||
vector<string> srcPaths = CRYPTO_SRC_PATH;
|
||||
if (bundleNameStr == SCENE_BOARD_BUNDLE_NAME) {
|
||||
dstPaths.push_back(PUBLIC_DIR_SANDBOX_PATH);
|
||||
srcPaths.push_back(PUBLIC_DIR_SRC_PATH);
|
||||
}
|
||||
MountSandboxPath(srcPaths, dstPaths, bundleNameStr, to_string(userId));
|
||||
}
|
||||
LOGI("mount crypto path success, userId is %{public}d", userId);
|
||||
@ -699,6 +754,7 @@ void MountManager::MountPointToList(std::list<std::string> &hmdfsList, std::list
|
||||
Utils::MountArgument hmdfsMntArgs(Utils::MountArgumentDescriptors::Alpha(userId, ""));
|
||||
const string &hmdfsPrefix = hmdfsMntArgs.GetMountPointPrefix();
|
||||
const string &hmfsPrefix = hmdfsMntArgs.GetSandboxPath();
|
||||
const string &mntUserPrefix = hmdfsMntArgs.GetMntUserPath();
|
||||
const string &sharefsPrefix = hmdfsMntArgs.GetShareSrc();
|
||||
const string &cloudPrefix = hmdfsMntArgs.GetFullCloud();
|
||||
std::stringstream ss(line);
|
||||
@ -721,11 +777,16 @@ void MountManager::MountPointToList(std::list<std::string> &hmdfsList, std::list
|
||||
if (dst.length() >= hmfsPrefix.length() && dst.substr(0, hmfsPrefix.length()) == hmfsPrefix) {
|
||||
hmfsList.push_front(dst);
|
||||
}
|
||||
if (dst.length() >= mntUserPrefix.length() && dst.substr(0, mntUserPrefix.length()) == mntUserPrefix) {
|
||||
hmfsList.push_front(dst);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (type == MOUNT_POINT_TYPE_SHAREFS) {
|
||||
if (src.length() >= sharefsPrefix.length() &&
|
||||
src.substr(0, sharefsPrefix.length()) == sharefsPrefix) {
|
||||
if (src.length() >= sharefsPrefix.length() && src.substr(0, sharefsPrefix.length()) == sharefsPrefix) {
|
||||
sharefsList.push_front(dst);
|
||||
}
|
||||
if (src.length() >= mntUserPrefix.length() && src.substr(0, mntUserPrefix.length()) == mntUserPrefix) {
|
||||
sharefsList.push_front(dst);
|
||||
}
|
||||
return;
|
||||
@ -772,14 +833,6 @@ int32_t MountManager::UMountAllPath(int32_t userId, std::list<std::string> &moun
|
||||
result = res;
|
||||
}
|
||||
|
||||
list = mountMap[MOUNT_POINT_TYPE_HMDFS];
|
||||
total = static_cast<int>(list.size());
|
||||
LOGI("unmount hmdfs path start, total %{public}d.", total);
|
||||
res = UMountByList(list, mountFailList);
|
||||
if (res != E_OK) {
|
||||
result = res;
|
||||
}
|
||||
LOGI("result is %{public}d.", result);
|
||||
list = mountMap[MOUNT_POINT_TYPE_HMFS];
|
||||
total = static_cast<int>(list.size());
|
||||
LOGI("unmount hmfs path start, total %{public}d.", total);
|
||||
@ -787,16 +840,25 @@ int32_t MountManager::UMountAllPath(int32_t userId, std::list<std::string> &moun
|
||||
if (res != E_OK) {
|
||||
result = res;
|
||||
}
|
||||
UmountMntUserTmpfs(userId);
|
||||
|
||||
list = mountMap[MOUNT_POINT_TYPE_HMDFS];
|
||||
total = static_cast<int>(list.size());
|
||||
LOGI("unmount hmdfs path start, total %{public}d.", total);
|
||||
res = UMountByList(list, mountFailList);
|
||||
if (res != E_OK) {
|
||||
result = res;
|
||||
}
|
||||
|
||||
if (result != E_OK) {
|
||||
for (const auto &item: mountFailList) {
|
||||
res = UMount2(item.c_str(), MNT_DETACH);
|
||||
if (res != E_OK) {
|
||||
if (res != E_OK && errno == EBUSY) {
|
||||
LOGE("failed to unmount with detach, path %{public}s, errno %{public}d.", item.c_str(), errno);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
DeleteSceneDir(userId);
|
||||
LOGI("UMountAllPath success");
|
||||
return E_OK;
|
||||
}
|
||||
@ -820,21 +882,6 @@ int32_t MountManager::UMountByList(std::list<std::string> &list, std::list<std::
|
||||
return result;
|
||||
}
|
||||
|
||||
int32_t MountManager::DeleteSceneDir(int32_t userId)
|
||||
{
|
||||
std::string path = SANDBOX_ROOT_PATH + to_string(userId) + "/" + SCENE_BOARD_BUNDLE_NAME + PUBLIC_DIR_SANDBOX_PATH;
|
||||
if (rmdir(path.c_str())) {
|
||||
LOGE("failed to rm dir %{public}s, errno %{public}d", path.c_str(), errno);
|
||||
return false;
|
||||
}
|
||||
path = SANDBOX_ROOT_PATH + to_string(userId) + "/" + SCENE_BOARD_BUNDLE_NAME + STORAGE_USERS_PATH;
|
||||
if (rmdir(path.c_str())) {
|
||||
LOGE("failed to rm dir %{public}s, errno %{public}d", path.c_str(), errno);
|
||||
return false;
|
||||
}
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
void MountManager::MountCloudForUsers(void)
|
||||
{
|
||||
for (auto it = fuseToMountUsers_.begin(); it != fuseToMountUsers_.end();) {
|
||||
@ -1001,8 +1048,8 @@ int32_t MountManager::MountByUser(int32_t userId)
|
||||
if (ret != E_OK) {
|
||||
LOGE("sharefs mount error");
|
||||
}
|
||||
// MountAppdataAndSharefs(userId);
|
||||
SetFafQuotaProId(userId);
|
||||
|
||||
if (CreateSystemServiceDirs(userId) != E_OK) {
|
||||
LOGE("create system service dir error");
|
||||
return E_PREPARE_DIR;
|
||||
@ -1293,5 +1340,199 @@ bool MountManager::CloudDirFlag(const std::string &path)
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int32_t MountManager::SharedMount(const std::string &path)
|
||||
{
|
||||
// if (path.empty() || !IsDir(path)) {
|
||||
// LOGE("path invalid, %{public}s", path.c_str());
|
||||
// return ENOENT;
|
||||
// }
|
||||
// errno = 0;
|
||||
// int32_t ret = Mount(path, path, nullptr, MS_BIND | MS_REC, nullptr);
|
||||
// if (ret != 0) {
|
||||
// LOGE("SharedMount failed, path is %{public}s, errno is %{public}d.", path.c_str(), errno);
|
||||
// return ret;
|
||||
// }
|
||||
// ret = Mount(nullptr, path, nullptr, MS_SHARED, nullptr);
|
||||
// if (ret != 0) {
|
||||
// LOGE("SharedMount shared failed, path is %{public}s, errno is %{public}d.", path.c_str(), errno);
|
||||
// return ret;
|
||||
// }
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
int32_t MountManager::BindAndRecMount(std::string &srcPath, std::string &dstPath, bool isUseSlave)
|
||||
{
|
||||
if (srcPath.empty() || !IsDir(srcPath)) {
|
||||
LOGE("path invalid, %{public}s", srcPath.c_str());
|
||||
return ENOENT;
|
||||
}
|
||||
if (dstPath.empty() || !IsDir(dstPath)) {
|
||||
LOGE("path invalid, %{public}s", dstPath.c_str());
|
||||
return ENOENT;
|
||||
}
|
||||
if (IsPathMounted(dstPath)) {
|
||||
LOGE("path has mounted, %{public}s", dstPath.c_str());
|
||||
return E_OK;
|
||||
}
|
||||
int32_t ret = Mount(srcPath, dstPath, nullptr, MS_BIND | MS_REC, nullptr);
|
||||
if (ret != 0) {
|
||||
LOGE("bind and rec mount failed, srcPath is %{public}s, dstPath is %{public}s, errno is %{public}d.",
|
||||
srcPath.c_str(), dstPath.c_str(), errno);
|
||||
return ret;
|
||||
}
|
||||
if (isUseSlave) {
|
||||
ret = Mount(nullptr, dstPath, nullptr, MS_SLAVE, nullptr);
|
||||
if (ret != 0) {
|
||||
LOGE("mount to slave failed, path is %{public}s, errno is %{public}d.", dstPath.c_str(), errno);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
void MountManager::GetAllUserId(std::vector<int32_t> &userIds)
|
||||
{
|
||||
const std::string &path = APP_EL1_PATH;
|
||||
if (!DirExist(path)) {
|
||||
return;
|
||||
}
|
||||
for (const auto &entry : filesystem::directory_iterator(path)) {
|
||||
if (!entry.is_directory()) {
|
||||
continue;
|
||||
}
|
||||
std::string subPath = entry.path().filename().string();
|
||||
if (!StringIsNumber(subPath)) {
|
||||
continue;
|
||||
}
|
||||
int32_t userId = stoi(subPath);
|
||||
if (userId < DEFAULT_USERID) {
|
||||
continue;
|
||||
}
|
||||
userIds.push_back(userId);
|
||||
}
|
||||
}
|
||||
|
||||
bool MountManager::DirExist(const std::string &dir)
|
||||
{
|
||||
filesystem::path filePath(dir);
|
||||
std::error_code errCode;
|
||||
if (!exists(filePath, errCode)) {
|
||||
LOGE("dir not exists, %{public}s", dir.c_str());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
int32_t MountManager::MountAppdata(const std::string &userId)
|
||||
{
|
||||
std::vector<std::string> appdataSrc = APPDATA_SRC_PATH;
|
||||
std::vector<std::string> appdataDst = APPDATA_DST_PATH;
|
||||
int count = static_cast<int>(appdataSrc.size());
|
||||
for (int i = 1; i < count; ++i) {
|
||||
std::string src = appdataSrc[i];
|
||||
std::string dst = appdataDst[i];
|
||||
ParseSandboxPath(src, userId, "");
|
||||
ParseSandboxPath(dst, userId, "");
|
||||
BindAndRecMount(src, dst);
|
||||
}
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
int32_t MountManager::MountSharefsAndNoSharefs(int32_t userId)
|
||||
{
|
||||
Utils::MountArgument mountArgument(Utils::MountArgumentDescriptors::Alpha(userId, ""));
|
||||
std::string path = mountArgument.GetNoSharefsDocPath();
|
||||
SharedMount(path);
|
||||
path = mountArgument.GetSharefsDocPath();
|
||||
SharedMount(path);
|
||||
|
||||
std::string src = APPDATA_SRC_PATH[0];
|
||||
std::string dst = APPDATA_DST_PATH[0];
|
||||
ParseSandboxPath(src, to_string(userId), "");
|
||||
ParseSandboxPath(dst, to_string(userId), "");
|
||||
BindAndRecMount(src, dst);
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
int32_t MountManager::PrepareAppdataDirByUserId(int32_t userId)
|
||||
{
|
||||
for (const DirInfo &dir: appdataDir_) {
|
||||
if (!PrepareDir(StringPrintf(dir.path.c_str(), userId), dir.mode, dir.uid, dir.gid)) {
|
||||
return E_PREPARE_DIR;
|
||||
}
|
||||
}
|
||||
MountSharefsAndNoSharefs(userId);
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
int32_t MountManager::MountAppdataAndSharefs(int32_t userId)
|
||||
{
|
||||
LOGI("mount appdata start");
|
||||
MountAppdata(to_string(userId));
|
||||
|
||||
LOGI("mount currentUser/other");
|
||||
Utils::MountArgument mountArgument(Utils::MountArgumentDescriptors::Alpha(userId, ""));
|
||||
std::string mediaDocPath = mountArgument.GetMediaDocsPath();
|
||||
std::string curOtherPath = mountArgument.GetCurOtherPath();
|
||||
BindAndRecMount(mediaDocPath, curOtherPath);
|
||||
|
||||
LOGI("mount currentUser/other/appdata");
|
||||
std::string noSharefsAppdataPath = mountArgument.GetNoSharefsAppdataPath();
|
||||
std::string curOtherAppdataPath = mountArgument.GetCurOtherAppdataPath();
|
||||
MkDir(curOtherAppdataPath, MODE_0711);
|
||||
BindAndRecMount(noSharefsAppdataPath, curOtherAppdataPath);
|
||||
|
||||
LOGI("mount currentUser/filemgr");
|
||||
std::string curFileMgrPath = mountArgument.GetCurFileMgrPath();
|
||||
BindAndRecMount(mediaDocPath, curFileMgrPath);
|
||||
|
||||
LOGI("mount currentUser/filemgr/appdata");
|
||||
std::string curFileMgrAppdataPath = mountArgument.GetCurFileMgrAppdataPath();
|
||||
MkDir(curFileMgrAppdataPath, MODE_0711);
|
||||
HmSharefsMount(userId, noSharefsAppdataPath, curFileMgrAppdataPath);
|
||||
|
||||
LOGI("mount sharefs/docs/currentUser");
|
||||
std::string sharefsDocCurPath = mountArgument.GetSharefsDocCurPath();
|
||||
BindAndRecMount(curOtherPath, sharefsDocCurPath);
|
||||
|
||||
LOGI("mount nosharefs/docs/currentUser");
|
||||
std::string noSharefsDocCurPath = mountArgument.GetNoSharefsDocCurPath();
|
||||
BindAndRecMount(curFileMgrPath, noSharefsDocCurPath);
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
int32_t MountManager::PrepareAppdataDir(int32_t userId)
|
||||
{
|
||||
if (userId == 0) {
|
||||
std::vector<int32_t> userIds;
|
||||
GetAllUserId(userIds);
|
||||
if (userIds.empty()) {
|
||||
return E_OK;
|
||||
}
|
||||
for (const int32_t &item: userIds) {
|
||||
PrepareAppdataDirByUserId(item);
|
||||
}
|
||||
} else {
|
||||
PrepareAppdataDirByUserId(userId);
|
||||
}
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
int32_t MountManager::UmountMntUserTmpfs(int32_t userId)
|
||||
{
|
||||
Utils::MountArgument mountArgument(Utils::MountArgumentDescriptors::Alpha(userId, ""));
|
||||
std::string path = mountArgument.GetSharefsDocCurPath() + "/appdata";
|
||||
int32_t res = UMount2(path, MNT_DETACH);
|
||||
if (res != E_OK) {
|
||||
LOGE("failed to umount with detach, path %{public}s, errno {public}d.", path.c_str(), errno);
|
||||
}
|
||||
path = mountArgument.GetCurOtherAppdataPath();
|
||||
res = UMount2(path, MNT_DETACH);
|
||||
if (res != E_OK) {
|
||||
LOGE("failed to umount with detach, path %{public}s, errno {public}d.", path.c_str(), errno);
|
||||
}
|
||||
return E_OK;
|
||||
}
|
||||
} // namespace StorageDaemon
|
||||
} // namespace OHOS
|
||||
|
@ -34,6 +34,17 @@ namespace {
|
||||
static const std::string TMPFS_MNT_DATA = "/mnt/data/";
|
||||
static const std::string HMDFS_DEVICE_VIEW_LOCAL_DOCS_PATH = "/device_view/local" + RELATIVE_DOCS_PATH;
|
||||
static const std::string SANDBOX_PATH = "/mnt/sandbox/";
|
||||
static const std::string MNT_USER_PATH = "/mnt/user/";
|
||||
static const std::string NOSHAREFS_DOC_PATH = "/nosharefs/docs";
|
||||
static const std::string SHAREFS_DOC_PATH = "/sharefs/docs";
|
||||
static const std::string NOSHAREFS_DOC_CUR_PATH = "/nosharefs/docs/currentUser";
|
||||
static const std::string SHAREFS_DOC_CUR_PATH = "/sharefs/docs/currentUser";
|
||||
static const std::string LOCAL_FILE_DOCS_PATH = "/local/files/Docs";
|
||||
static const std::string CUR_OTHER_PATH = "/currentUser/other";
|
||||
static const std::string CUR_OTHER_APPDATA_PATH = "/currentUser/other/appdata";
|
||||
static const std::string CUR_FILEMGR_PATH = "/currentUser/filemgr";
|
||||
static const std::string CUR_FILEMGR_APPDATA_PATH = "/currentUser/filemgr/appdata";
|
||||
static const std::string NOSHAREFS_APPDATA_PATH = "/nosharefs/appdata";
|
||||
} // namespace
|
||||
|
||||
string MountArgument::GetFullSrc() const
|
||||
@ -84,6 +95,13 @@ string MountArgument::GetUserIdPara() const
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
string MountArgument::GetHmUserIdPara() const
|
||||
{
|
||||
stringstream ss;
|
||||
ss << "override_support_delete,user_id=" << userId_;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
string MountArgument::GetShareDst() const
|
||||
{
|
||||
stringstream ss;
|
||||
@ -196,6 +214,83 @@ string MountArgument::OptionsToString() const
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
string MountArgument::GetMediaDocsPath() const
|
||||
{
|
||||
stringstream ss;
|
||||
ss << COMM_DATA_POINT << userId_ << LOCAL_FILE_DOCS_PATH;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
string MountArgument::GetNoSharefsAppdataPath() const
|
||||
{
|
||||
stringstream ss;
|
||||
ss << MNT_USER_PATH << userId_ << NOSHAREFS_APPDATA_PATH;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
string MountArgument::GetNoSharefsDocPath() const
|
||||
{
|
||||
stringstream ss;
|
||||
ss << MNT_USER_PATH << userId_ << NOSHAREFS_DOC_PATH;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
string MountArgument::GetNoSharefsDocCurPath() const
|
||||
{
|
||||
stringstream ss;
|
||||
ss << MNT_USER_PATH << userId_ << NOSHAREFS_DOC_CUR_PATH;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
string MountArgument::GetSharefsDocPath() const
|
||||
{
|
||||
stringstream ss;
|
||||
ss << MNT_USER_PATH << userId_ << SHAREFS_DOC_PATH;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
string MountArgument::GetSharefsDocCurPath() const
|
||||
{
|
||||
stringstream ss;
|
||||
ss << MNT_USER_PATH << userId_ << SHAREFS_DOC_CUR_PATH;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
string MountArgument::GetCurOtherAppdataPath() const
|
||||
{
|
||||
stringstream ss;
|
||||
ss << MNT_USER_PATH << userId_ << CUR_OTHER_APPDATA_PATH;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
string MountArgument::GetMntUserPath() const
|
||||
{
|
||||
stringstream ss;
|
||||
ss << MNT_USER_PATH << userId_;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
string MountArgument::GetCurOtherPath() const
|
||||
{
|
||||
stringstream ss;
|
||||
ss << MNT_USER_PATH << userId_ << CUR_OTHER_PATH;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
string MountArgument::GetCurFileMgrPath() const
|
||||
{
|
||||
stringstream ss;
|
||||
ss << MNT_USER_PATH << userId_ << CUR_FILEMGR_PATH;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
string MountArgument::GetCurFileMgrAppdataPath() const
|
||||
{
|
||||
stringstream ss;
|
||||
ss << MNT_USER_PATH << userId_ << CUR_FILEMGR_APPDATA_PATH;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
unsigned long MountArgument::GetFlags() const
|
||||
{
|
||||
return MS_NODEV;
|
||||
|
Loading…
Reference in New Issue
Block a user