1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef OHOS_STORAGE_DAEMON_MOUNT_MANAGER_H 17 #define OHOS_STORAGE_DAEMON_MOUNT_MANAGER_H 18 19 #include <string> 20 #include <mutex> 21 #include <vector> 22 #include <sys/types.h> 23 #include <nocopyable.h> 24 25 namespace OHOS { 26 namespace StorageDaemon { 27 struct DirInfo { 28 const std::string path; 29 mode_t mode; 30 uid_t uid; 31 gid_t gid; 32 }; 33 34 constexpr uid_t OID_ROOT = 0; 35 constexpr uid_t OID_SYSTEM = 1000; 36 constexpr uid_t OID_FILE_MANAGER = 1006; 37 constexpr uid_t OID_USER_DATA_RW = 1008; 38 constexpr uid_t OID_DFS = 1009; 39 constexpr uid_t OID_BACKUP = 1089; 40 constexpr uid_t OID_DFS_SHARE = 3822; 41 constexpr uid_t OID_TEE = 6668; 42 constexpr uid_t OID_DEVICE_AUTH = 3333; 43 constexpr uid_t OID_HUKS = 3510; 44 constexpr uid_t OID_DDMS = 3012; 45 constexpr uid_t USER_ID_BASE = 200000; 46 47 class MountManager final { 48 public: 49 MountManager(); 50 virtual ~MountManager() = default; 51 static std::shared_ptr<MountManager> GetInstance(); 52 int32_t MountByUser(int32_t userId); 53 int32_t UmountByUser(int32_t userId); 54 int32_t PrepareHmdfsDirs(int32_t userId); 55 int32_t PrepareFileManagerDirs(int32_t userId); 56 int32_t DestroyHmdfsDirs(int32_t userId); 57 int32_t DestroyFileManagerDirs(int32_t userId); 58 int32_t DestroySystemServiceDirs(int32_t userId); 59 int32_t CloudMount(int32_t userId, const std::string& path); 60 int32_t CloudTwiceMount(int32_t userId); 61 int32_t MountCryptoPathAgain(uint32_t userId); 62 void SetCloudState(bool active); 63 64 private: 65 bool SupportHmdfs(); 66 int32_t CreateVirtualDirs(int32_t userId); 67 int32_t HmdfsMount(int32_t userId); 68 int32_t HmdfsMount(int32_t userId, std::string relativePath, bool mountCloudDisk = false); 69 int32_t HmdfsTwiceMount(int32_t userId, std::string relativePath); 70 int32_t HmdfsUMount(int32_t userId); 71 int32_t HmdfsUMount(int32_t userId, std::string relativePath); 72 int32_t SharefsMount(int32_t userId); 73 int32_t SharefsUMount(int32_t userId); 74 int32_t HmdfsTwiceUMount(int32_t userId, std::string relativePath); 75 int32_t LocalMount(int32_t userId); 76 int32_t LocalUMount(int32_t userId); 77 int32_t SetFafQuotaProId(int32_t userId); 78 int32_t CreateSystemServiceDirs(int32_t userId); 79 void MountCloudForUsers(void); 80 void UMountCloudForUsers(void); 81 void PrepareFileManagerDir(int32_t userId); 82 int32_t CloudUMount(int32_t userId); 83 84 DISALLOW_COPY_AND_MOVE(MountManager); 85 86 static std::shared_ptr<MountManager> instance_; 87 const std::vector<DirInfo> hmdfsDirVec_; 88 const std::vector<DirInfo> virtualDir_; 89 const std::vector<DirInfo> systemServiceDir_; 90 const std::vector<DirInfo> fileManagerDir_; 91 std::mutex mountMutex_; 92 std::vector<int32_t> fuseToMountUsers_; 93 std::vector<int32_t> fuseMountedUsers_; 94 bool cloudReady_{false}; 95 }; 96 } // STORAGE_DAEMON 97 } // OHOS 98 99 #endif // OHOS_STORAGE_DAEMON_USER_MANAGER_H 100