• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 Flags {
44         /* Flag that disk is adoptable */
45         kAdoptable = 1 << 0,
46         /* Flag that disk is considered primary when the user hasn't
47          * explicitly picked a primary storage location */
48         kDefaultPrimary = 1 << 1,
49         /* Flag that disk is SD card */
50         kSd = 1 << 2,
51         /* Flag that disk is USB disk */
52         kUsb = 1 << 3,
53         /* Flag that disk is EMMC internal */
54         kEmmc = 1 << 4,
55     };
56 
getId()57     const std::string& getId() const { return mId; }
getEventPath()58     const std::string& getEventPath() const { return mEventPath; }
getSysPath()59     const std::string& getSysPath() const { return mSysPath; }
getDevPath()60     const std::string& getDevPath() const { return mDevPath; }
getDevice()61     dev_t getDevice() const { return mDevice; }
getSize()62     uint64_t getSize() const { return mSize; }
getLabel()63     const std::string& getLabel() const { return mLabel; }
getFlags()64     int getFlags() const { return mFlags; }
65 
66     std::shared_ptr<VolumeBase> findVolume(const std::string& id);
67 
68     void listVolumes(VolumeBase::Type type, std::list<std::string>& list) const;
69 
70     status_t create();
71     status_t destroy();
72 
73     status_t readMetadata();
74     status_t readPartitions();
75 
76     status_t unmountAll();
77 
78     status_t partitionPublic();
79     status_t partitionPrivate();
80     status_t partitionMixed(int8_t ratio);
81 
82   private:
83     /* ID that uniquely references this disk */
84     std::string mId;
85     /* Original event path */
86     std::string mEventPath;
87     /* Device path under sysfs */
88     std::string mSysPath;
89     /* Device path under dev */
90     std::string mDevPath;
91     /* Kernel device representing disk */
92     dev_t mDevice;
93     /* Size of disk, in bytes */
94     uint64_t mSize;
95     /* User-visible label, such as manufacturer */
96     std::string mLabel;
97     /* Current partitions on disk */
98     std::vector<std::shared_ptr<VolumeBase>> mVolumes;
99     /* Nickname for this disk */
100     std::string mNickname;
101     /* Flags applicable to this disk */
102     int mFlags;
103     /* Flag indicating object is created */
104     bool mCreated;
105     /* Flag that we just partitioned and should format all volumes */
106     bool mJustPartitioned;
107 
108     void createPublicVolume(dev_t device);
109     void createPrivateVolume(dev_t device, const std::string& partGuid);
110 
111     void destroyAllVolumes();
112 
113     int getMaxMinors();
114 
115     DISALLOW_COPY_AND_ASSIGN(Disk);
116 };
117 
118 }  // namespace vold
119 }  // namespace android
120 
121 #endif
122