blob: a623a62a86754cf0e9256bc783b979bff14ec0a2
1 | /* |
2 | * Copyright (C) 2015 The Android Open Source Project |
3 | * |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | * you may not use this file except in compliance with the License. |
6 | * You may obtain a copy of the License at |
7 | * |
8 | * http://www.apache.org/licenses/LICENSE-2.0 |
9 | * |
10 | * Unless required by applicable law or agreed to in writing, software |
11 | * distributed under the License is distributed on an "AS IS" BASIS, |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. |
15 | */ |
16 | |
17 | #ifndef ANDROID_VOLD_DISK_H |
18 | #define ANDROID_VOLD_DISK_H |
19 | |
20 | #include "Utils.h" |
21 | #include "VolumeBase.h" |
22 | |
23 | #include <utils/Errors.h> |
24 | #include <sysutils/NetlinkEvent.h> |
25 | |
26 | #include <vector> |
27 | |
28 | namespace android { |
29 | namespace droidvold { |
30 | |
31 | class VolumeBase; |
32 | |
33 | /* |
34 | * Representation of detected physical media. |
35 | * |
36 | * Knows how to create volumes based on the partition tables found, and also |
37 | * how to repartition itself. |
38 | */ |
39 | class Disk { |
40 | public: |
41 | Disk(const std::string& eventPath, dev_t device, const std::string& nickname, |
42 | const std::string& eventName, int flags); |
43 | virtual ~Disk(); |
44 | |
45 | enum Flags { |
46 | /* Flag that disk is adoptable */ |
47 | kAdoptable = 1 << 0, |
48 | /* Flag that disk is considered primary when the user hasn't |
49 | * explicitly picked a primary storage location */ |
50 | kDefaultPrimary = 1 << 1, |
51 | /* Flag that disk is SD card */ |
52 | kSd = 1 << 2, |
53 | /* Flag that disk is USB disk */ |
54 | kUsb = 1 << 3, |
55 | /* Flag that disk is EMMC internal */ |
56 | kEmmc = 1 << 4, |
57 | }; |
58 | |
59 | const std::string& getId() { return mId; } |
60 | const std::string& getEventPath() { return mEventPath; } |
61 | const std::string& getSysPath() { return mSysPath; } |
62 | const std::string& getDevPath() { return mDevPath; } |
63 | dev_t getDevice() { return mDevice; } |
64 | uint64_t getSize() { return mSize; } |
65 | const std::string& getLabel() { return mLabel; } |
66 | int getFlags() { return mFlags; } |
67 | |
68 | std::shared_ptr<VolumeBase> findVolume(const std::string& id); |
69 | std::shared_ptr<VolumeBase> findVolumeByPath(const std::string& path); |
70 | |
71 | void listVolumes(VolumeBase::Type type, std::list<std::string>& list); |
72 | |
73 | status_t create(); |
74 | status_t destroy(); |
75 | |
76 | status_t readDiskMetadata(); |
77 | status_t readPartitions(); |
78 | |
79 | status_t unmountAll(); |
80 | |
81 | bool isSrdiskMounted(); |
82 | void notifyEvent(int msg); |
83 | void notifyEvent(int msg, const std::string& value); |
84 | void destroyAllVolumes(); |
85 | |
86 | void handleBlockEvent(NetlinkEvent *evt); |
87 | status_t reset(); |
88 | |
89 | private: |
90 | /* ID that uniquely references this disk */ |
91 | std::string mId; |
92 | /* Original event path */ |
93 | std::string mEventPath; |
94 | /* Device path under sysfs */ |
95 | std::string mSysPath; |
96 | /* Device path under dev */ |
97 | std::string mDevPath; |
98 | |
99 | std::string mDevName; |
100 | /* Kernel device representing disk */ |
101 | dev_t mDevice; |
102 | /* Size of disk, in bytes */ |
103 | uint64_t mSize; |
104 | /* User-visible label, such as manufacturer */ |
105 | std::string mLabel; |
106 | /* Current partitions on disk */ |
107 | std::vector<std::shared_ptr<VolumeBase>> mVolumes; |
108 | /* Nickname for this disk */ |
109 | std::string mNickname; |
110 | /* Flags applicable to this disk */ |
111 | int mFlags; |
112 | /* Flag indicating object is created */ |
113 | bool mCreated; |
114 | /* Flag that we just partitioned and should format all volumes */ |
115 | bool mJustPartitioned; |
116 | /* Flag indicating is srdisk or not */ |
117 | bool mSrdisk; |
118 | |
119 | std::vector<int> mPartNo; |
120 | |
121 | void createPublicVolume(const std::string& partDevName, |
122 | const bool isPhysical, int part); |
123 | void createPrivateVolume(dev_t device, const std::string& partGuid); |
124 | void handleJustPublicPhysicalDevice(const std::string& physicalDevName); |
125 | void getPhysicalDev(dev_t &device, const std:: string& sysPath, int part); |
126 | |
127 | int getMaxMinors(); |
128 | |
129 | DISALLOW_COPY_AND_ASSIGN(Disk); |
130 | }; |
131 | |
132 | } // namespace vold |
133 | } // namespace android |
134 | |
135 | #endif |
136 |