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