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
21 #include "VolumeBase.h"
23 #include <utils/Errors.h>
33 * Representation of detected physical media.
35 * Knows how to create volumes based on the partition tables found, and also
36 * how to repartition itself.
40 Disk(const std::string& eventPath, dev_t device, const std::string& nickname, int flags);
44 /* Flag that disk is adoptable */
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 */
51 /* Flag that disk is USB disk */
53 /* Flag that disk is EMMC internal */
55 /* Flag that disk is non-removable */
56 kNonRemovable = 1 << 5,
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; }
68 std::shared_ptr<VolumeBase> findVolume(const std::string& id);
70 void listVolumes(VolumeBase::Type type, std::list<std::string>& list);
72 virtual status_t create();
73 virtual status_t destroy();
75 virtual status_t readMetadata();
76 virtual status_t readPartitions();
78 status_t unmountAll();
80 virtual status_t partitionPublic();
81 virtual status_t partitionPrivate();
82 virtual status_t partitionMixed(int8_t ratio);
84 void notifyEvent(int msg);
85 void notifyEvent(int msg, const std::string& value);
88 /* ID that uniquely references this disk */
90 /* Original event path */
91 std::string mEventPath;
92 /* Device path under sysfs */
94 /* Device path under dev */
96 /* Kernel device representing disk */
98 /* Size of disk, in bytes */
100 /* User-visible label, such as manufacturer */
102 /* Current partitions on disk */
103 std::vector<std::shared_ptr<VolumeBase>> mVolumes;
104 /* Nickname for this disk */
105 std::string mNickname;
106 /* Flags applicable to this disk */
108 /* Flag indicating object is created */
110 /* Flag that we just partitioned and should format all volumes */
111 bool mJustPartitioned;
112 /* Flag that we need to skip first disk change events after partitioning*/
115 void createPublicVolume(dev_t device,
116 const std::string& fstype = "",
117 const std::string& mntopts = "");
118 void createPrivateVolume(dev_t device, const std::string& partGuid);
120 void destroyAllVolumes();
124 DISALLOW_COPY_AND_ASSIGN(Disk);
128 } // namespace android