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