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 42 class MountManager final { 43 public: 44 MountManager(); 45 virtual ~MountManager() = default; 46 static std::shared_ptr<MountManager> GetInstance(); 47 int32_t MountByUser(int32_t userId); 48 int32_t UmountByUser(int32_t userId); 49 int32_t PrepareHmdfsDirs(int32_t userId); 50 int32_t PrepareFileManagerDirs(int32_t userId); 51 int32_t DestroyHmdfsDirs(int32_t userId); 52 int32_t DestroyFileManagerDirs(int32_t userId); 53 int32_t CloudMount(int32_t userId); 54 void SetCloudState(bool active); 55 56 private: 57 bool SupportHmdfs(); 58 int32_t CreateVirtualDirs(int32_t userId); 59 int32_t HmdfsMount(int32_t userId); 60 int32_t HmdfsMount(int32_t userId, std::string relativePath); 61 int32_t HmdfsTwiceMount(int32_t userId, std::string relativePath); 62 int32_t HmdfsUMount(int32_t userId); 63 int32_t HmdfsUMount(int32_t userId, std::string relativePath); 64 int32_t SharefsMount(int32_t userId); 65 int32_t SharefsUMount(int32_t userId); 66 int32_t HmdfsTwiceUMount(int32_t userId, std::string relativePath); 67 int32_t LocalMount(int32_t userId); 68 int32_t LocalUMount(int32_t userId); 69 void MountCloudForUsers(void); 70 void UMountCloudForUsers(void); 71 void PrepareFileManagerDir(int32_t userId); 72 int32_t CloudUMount(int32_t userId); 73 74 DISALLOW_COPY_AND_MOVE(MountManager); 75 76 static std::shared_ptr<MountManager> instance_; 77 const std::vector<DirInfo> hmdfsDirVec_; 78 const std::vector<DirInfo> virtualDir_; 79 const std::vector<DirInfo> fileManagerDir_; 80 std::mutex mountMutex_; 81 std::vector<int32_t> fuseToMountUsers_; 82 std::vector<int32_t> fuseMountedUsers_; 83 bool cloudReady_{false}; 84 }; 85 } // STORAGE_DAEMON 86 } // OHOS 87 88 #endif // OHOS_STORAGE_DAEMON_USER_MANAGER_H 89