OSDN Git Service

vold3: check supported filesystem modules
[android-x86/system-vold.git] / Disk.h
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
25 #include <vector>
26
27 namespace android {
28 namespace vold {
29
30 class VolumeBase;
31
32 /*
33  * Representation of detected physical media.
34  *
35  * Knows how to create volumes based on the partition tables found, and also
36  * how to repartition itself.
37  */
38 class Disk {
39 public:
40     Disk(const std::string& eventPath, dev_t device, const std::string& nickname, int flags);
41     virtual ~Disk();
42
43     enum {
44         kMajorBlockLoop = 7,
45         kMajorBlockScsiA = 8,
46         kMajorBlockCdrom = 11,
47         kMajorBlockScsiB = 65,
48         kMajorBlockScsiC = 66,
49         kMajorBlockScsiD = 67,
50         kMajorBlockScsiE = 68,
51         kMajorBlockScsiF = 69,
52         kMajorBlockScsiG = 70,
53         kMajorBlockScsiH = 71,
54         kMajorBlockScsiI = 128,
55         kMajorBlockScsiJ = 129,
56         kMajorBlockScsiK = 130,
57         kMajorBlockScsiL = 131,
58         kMajorBlockScsiM = 132,
59         kMajorBlockScsiN = 133,
60         kMajorBlockScsiO = 134,
61         kMajorBlockScsiP = 135,
62         kMajorBlockMmc = 179,
63         kMajorBlockExperimentalMin = 240,
64         kMajorBlockExperimentalMax = 254,
65     };
66
67     enum Flags {
68         /* Flag that disk is adoptable */
69         kAdoptable = 1 << 0,
70         /* Flag that disk is considered primary when the user hasn't
71          * explicitly picked a primary storage location */
72         kDefaultPrimary = 1 << 1,
73         /* Flag that disk is SD card */
74         kSd = 1 << 2,
75         /* Flag that disk is USB disk */
76         kUsb = 1 << 3,
77         /* Flag that disk is EMMC internal */
78         kEmmc = 1 << 4,
79         /* Flag that disk is non-removable */
80         kNonRemovable = 1 << 5,
81         /* Flag that disk is CDROM */
82         kCdrom = 1 << 6,
83     };
84
85     const std::string& getId() { return mId; }
86     const std::string& getEventPath() { return mEventPath; }
87     const std::string& getSysPath() { return mSysPath; }
88     const std::string& getDevPath() { return mDevPath; }
89     dev_t getDevice() { return mDevice; }
90     uint64_t getSize() { return mSize; }
91     const std::string& getLabel() { return mLabel; }
92     int getFlags() { return mFlags; }
93
94     std::shared_ptr<VolumeBase> findVolume(const std::string& id);
95
96     void listVolumes(VolumeBase::Type type, std::list<std::string>& list);
97
98     virtual status_t create();
99     virtual status_t destroy();
100
101     virtual status_t readMetadata();
102     virtual status_t readPartitions();
103
104     status_t unmountAll();
105
106     virtual status_t partitionPublic();
107     virtual status_t partitionPrivate();
108     virtual status_t partitionMixed(int8_t ratio);
109
110     void notifyEvent(int msg);
111     void notifyEvent(int msg, const std::string& value);
112
113     static bool isVirtioBlkDevice(unsigned int major);
114
115 protected:
116     /* ID that uniquely references this disk */
117     std::string mId;
118     /* Original event path */
119     std::string mEventPath;
120     /* Device path under sysfs */
121     std::string mSysPath;
122     /* Device path under dev */
123     std::string mDevPath;
124     /* Kernel device representing disk */
125     dev_t mDevice;
126     /* Size of disk, in bytes */
127     uint64_t mSize;
128     /* User-visible label, such as manufacturer */
129     std::string mLabel;
130     /* Current partitions on disk */
131     std::vector<std::shared_ptr<VolumeBase>> mVolumes;
132     /* Nickname for this disk */
133     std::string mNickname;
134     /* Flags applicable to this disk */
135     int mFlags;
136     /* Flag indicating object is created */
137     bool mCreated;
138     /* Flag that we just partitioned and should format all volumes */
139     bool mJustPartitioned;
140
141     void createPublicVolume(dev_t device,
142                     const std::string& fstype = "",
143                     const std::string& mntopts = "");
144     void createPrivateVolume(dev_t device, const std::string& partGuid);
145
146     void destroyAllVolumes();
147
148     int getMaxMinors();
149
150     DISALLOW_COPY_AND_ASSIGN(Disk);
151 };
152
153 }  // namespace vold
154 }  // namespace android
155
156 #endif