• 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_DISK_MANAGER_H
17 #define OHOS_STORAGE_DAEMON_DISK_MANAGER_H
18 
19 #include <mutex>
20 #include <nocopyable.h>
21 
22 #include "disk/disk_config.h"
23 #include "disk/disk_info.h"
24 #include "netlink/netlink_data.h"
25 
26 namespace OHOS {
27 namespace StorageDaemon {
28 class DiskManager final {
29 public:
Instance(void)30     static DiskManager &Instance(void)
31     {
32         static DiskManager instance;
33         return instance;
34     }
35 
36     virtual ~DiskManager();
37     void CreateDisk(std::shared_ptr<DiskInfo> &diskInfo);
38     void DestroyDisk(dev_t device);
39     void ChangeDisk(dev_t device, NetlinkData *data);
40     std::shared_ptr<DiskInfo> GetDisk(dev_t device);
41     void HandleDiskEvent(NetlinkData *data);
42     int32_t HandlePartition(std::string diskId);
43     void AddDiskConfig(std::shared_ptr<DiskConfig> &diskConfig);
44     void ReplayUevent();
45     std::shared_ptr<DiskInfo> MatchConfig(NetlinkData *data);
46 
47 private:
48     DiskManager() = default;
49 
50     std::mutex lock_;
51     std::list<std::shared_ptr<DiskInfo>> disk_;
52     std::list<std::shared_ptr<DiskConfig>> diskConfig_;
53 
54     DISALLOW_COPY_AND_MOVE(DiskManager);
55 
56     const std::string sysBlockPath_ = "/sys/block";
57 };
58 } // STORAGE_DAEMON
59 } // OHOS
60 
61 #endif // OHOS_STORAGE_DAEMON_DISK_MANAGER_H
62