2 * Copyright (C) 2015 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef ANDROID_VOLD_DISK_H
18 #define ANDROID_VOLD_DISK_H
22 #include <utils/Errors.h>
32 * Representation of detected physical media.
34 * Knows how to create volumes based on the partition tables found, and also
35 * how to repartition itself.
39 Disk(const std::string& eventPath, dev_t device, const std::string& nickname, int flags);
43 /* Flag that disk is adoptable */
45 /* Flag that disk is considered primary when the user hasn't
46 * explicitly picked a primary storage location */
47 kDefaultPrimary = 1 << 1,
48 /* Flag that disk is SD card */
50 /* Flag that disk is USB disk */
54 const std::string& getId() { return mId; }
55 const std::string& getEventPath() { return mEventPath; }
56 const std::string& getSysPath() { return mSysPath; }
57 const std::string& getDevPath() { return mDevPath; }
58 dev_t getDevice() { return mDevice; }
59 uint64_t getSize() { return mSize; }
60 const std::string& getLabel() { return mLabel; }
61 int getFlags() { return mFlags; }
63 std::shared_ptr<VolumeBase> findVolume(const std::string& id);
68 status_t readMetadata();
69 status_t readPartitions();
71 status_t partitionPublic();
72 status_t partitionPrivate();
73 status_t partitionMixed(int8_t ratio);
76 /* ID that uniquely references this disk */
78 /* Original event path */
79 std::string mEventPath;
80 /* Device path under sysfs */
82 /* Device path under dev */
84 /* Kernel device representing disk */
86 /* Size of disk, in bytes */
88 /* User-visible label, such as manufacturer */
90 /* Current partitions on disk */
91 std::vector<std::shared_ptr<VolumeBase>> mVolumes;
92 /* Nickname for this disk */
93 std::string mNickname;
94 /* Flags applicable to this disk */
96 /* Flag indicating object is created */
99 void createPublicVolume(dev_t device);
100 void createPrivateVolume(dev_t device);
102 void destroyAllVolumes();
106 DISALLOW_COPY_AND_ASSIGN(Disk);
110 } // namespace android