• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <vector>
21 #include <sys/types.h>
22 #include <nocopyable.h>
23 
24 namespace OHOS {
25 namespace StorageDaemon {
26 struct DirInfo {
27     const std::string path;
28     mode_t mode;
29     uid_t uid;
30     gid_t gid;
31 };
32 
33 constexpr uid_t OID_ROOT = 0;
34 constexpr uid_t OID_SYSTEM = 1000;
35 constexpr uid_t OID_USER_DATA_RW = 1008;
36 
37 class MountManager final {
38 public:
39     MountManager();
40     virtual ~MountManager() = default;
41     static std::shared_ptr<MountManager> GetInstance();
42     int32_t MountByUser(int32_t userId);
43     int32_t UmountByUser(int32_t userId);
44     int32_t PrepareHmdfsDirs(int32_t userId);
45     int32_t DestroyHmdfsDirs(int32_t userId);
46 
47 private:
48     bool SupportHmdfs();
49     int32_t CreateVirtualDirs(int32_t userId);
50     int32_t HmdfsMount(int32_t userId);
51     int32_t HmdfsMount(int32_t userId, std::string relativePath);
52     int32_t HmdfsTwiceMount(int32_t userId, std::string relativePath);
53     int32_t HmdfsUMount(int32_t userId);
54     int32_t HmdfsUMount(int32_t userId, std::string relativePath);
55     int32_t HmdfsTwiceUMount(int32_t userId, std::string relativePath);
56     int32_t LocalMount(int32_t userId);
57     int32_t LocalUMount(int32_t userId);
58 
59     DISALLOW_COPY_AND_MOVE(MountManager);
60 
61     static std::shared_ptr<MountManager> instance_;
62     const std::vector<DirInfo> hmdfsDirVec_;
63     const std::vector<DirInfo> virtualDir_;
64 };
65 } // STORAGE_DAEMON
66 } // OHOS
67 
68 #endif // OHOS_STORAGE_DAEMON_USER_MANAGER_H