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