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_INFO_H 17 #define OHOS_STORAGE_DAEMON_DISK_INFO_H 18 19 #include <list> 20 #include <string> 21 22 #include <sys/types.h> 23 24 namespace OHOS { 25 namespace StorageDaemon { 26 class DiskInfo { 27 public: 28 enum DeviceFlag { 29 SD_FLAG = 1, 30 USB_FLAG = 2, 31 }; 32 enum class Table { 33 UNKNOWN, 34 MBR, 35 GPT, 36 }; 37 38 DiskInfo(std::string &sysPath_, std::string &devPath_, dev_t device, int flag); 39 virtual ~DiskInfo(); 40 int Create(); 41 int Destroy(); 42 void ReadMetadata(); 43 int ReadPartition(); 44 int CreateVolume(dev_t dev); 45 int Partition(); 46 dev_t GetDevice() const; 47 std::string GetId() const; 48 std::string GetDevPath() const; 49 uint64_t GetDevDSize() const; 50 std::string GetSysPath() const; 51 std::string GetDevVendor() const; 52 int GetDevFlag() const; 53 54 private: 55 std::string id_; 56 uint64_t size_ {}; 57 /* device vendor infomation */ 58 std::string vendor_; 59 std::string sysPath_; 60 int status; 61 std::string eventPath_; 62 std::string devPath_; 63 dev_t device_ {}; 64 unsigned int flags_ {}; 65 std::list<std::string> volumeId_; 66 int32_t ReadDiskLines(std::vector<std::string> lines, int32_t maxVols); 67 bool CreateMBRVolume(int32_t type, dev_t dev); 68 int32_t CreateUnknownTabVol(); 69 void ProcessPartition(std::vector<std::string>::iterator &it, const std::vector<std::string>::iterator &end, 70 Table table, int32_t maxVols, bool &foundPart); 71 int32_t GetMaxMinor(int32_t major); 72 }; 73 } // STORAGE_DAEMON 74 } // OHOS 75 76 #endif // OHOS_STORAGE_DAEMON_DISK_INFO_H