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: 30 static DiskManager* Instance(void); 31 32 virtual ~DiskManager(); 33 void CreateDisk(std::shared_ptr<DiskInfo> &diskInfo); 34 void DestroyDisk(dev_t device); 35 void ChangeDisk(dev_t device, NetlinkData *data); 36 std::shared_ptr<DiskInfo> GetDisk(dev_t device); 37 void HandleDiskEvent(NetlinkData *data); 38 int32_t HandlePartition(std::string diskId); 39 void AddDiskConfig(std::shared_ptr<DiskConfig> &diskConfig); 40 void ReplayUevent(); 41 std::shared_ptr<DiskInfo> MatchConfig(NetlinkData *data); 42 43 private: 44 DiskManager() = default; 45 46 std::mutex lock_; 47 std::list<std::shared_ptr<DiskInfo>> disk_; 48 std::list<std::shared_ptr<DiskConfig>> diskConfig_; 49 static DiskManager* instance_; 50 51 DISALLOW_COPY_AND_MOVE(DiskManager); 52 53 const std::string sysBlockPath_ = "/sys/block"; 54 }; 55 } // STORAGE_DAEMON 56 } // OHOS 57 58 #endif // OHOS_STORAGE_DAEMON_DISK_MANAGER_H 59