blob: 60e4fa9655cb5c6c822f16c55357182487778760 [file] [log] [blame]
Jeff Sharkeydeb24052015-03-02 21:01:40 -08001/*
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
22#include <utils/Errors.h>
23
24#include <vector>
25
26namespace android {
27namespace vold {
28
29class VolumeBase;
30
Jeff Sharkeydeb24052015-03-02 21:01:40 -080031/*
32 * Representation of detected physical media.
33 *
34 * Knows how to create volumes based on the partition tables found, and also
35 * how to repartition itself.
36 */
37class Disk {
38public:
Jeff Sharkey36801cc2015-03-13 16:09:20 -070039 Disk(const std::string& eventPath, dev_t device, const std::string& nickname, int flags);
Jeff Sharkeydeb24052015-03-02 21:01:40 -080040 virtual ~Disk();
41
Jeff Sharkey36801cc2015-03-13 16:09:20 -070042 enum Flags {
43 /* Flag that disk is adoptable */
44 kAdoptable = 1 << 0,
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 */
49 kSd = 1 << 2,
50 /* Flag that disk is USB disk */
51 kUsb = 1 << 3,
Jeff Sharkey5a6bfca2015-05-14 20:33:55 -070052 /* Flag that disk is EMMC internal */
53 kEmmc = 1 << 4,
Jeff Sharkey36801cc2015-03-13 16:09:20 -070054 };
55
Jeff Sharkeydeb24052015-03-02 21:01:40 -080056 const std::string& getId() { return mId; }
Jeff Sharkey36801cc2015-03-13 16:09:20 -070057 const std::string& getEventPath() { return mEventPath; }
Jeff Sharkeydeb24052015-03-02 21:01:40 -080058 const std::string& getSysPath() { return mSysPath; }
59 const std::string& getDevPath() { return mDevPath; }
60 dev_t getDevice() { return mDevice; }
61 uint64_t getSize() { return mSize; }
62 const std::string& getLabel() { return mLabel; }
Jeff Sharkey36801cc2015-03-13 16:09:20 -070063 int getFlags() { return mFlags; }
Jeff Sharkeydeb24052015-03-02 21:01:40 -080064
65 std::shared_ptr<VolumeBase> findVolume(const std::string& id);
66
Jeff Sharkey36801cc2015-03-13 16:09:20 -070067 status_t create();
68 status_t destroy();
69
Jeff Sharkeydeb24052015-03-02 21:01:40 -080070 status_t readMetadata();
71 status_t readPartitions();
72
Jeff Sharkey9c484982015-03-31 10:35:33 -070073 status_t unmountAll();
74
Jeff Sharkeydeb24052015-03-02 21:01:40 -080075 status_t partitionPublic();
76 status_t partitionPrivate();
77 status_t partitionMixed(int8_t ratio);
78
Jeff Sharkeyce6a9132015-04-08 21:07:21 -070079 void notifyEvent(int msg);
80 void notifyEvent(int msg, const std::string& value);
81
Jeff Sharkeydeb24052015-03-02 21:01:40 -080082private:
83 /* ID that uniquely references this disk */
84 std::string mId;
Jeff Sharkey36801cc2015-03-13 16:09:20 -070085 /* Original event path */
86 std::string mEventPath;
Jeff Sharkeydeb24052015-03-02 21:01:40 -080087 /* 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 */
Jeff Sharkey36801cc2015-03-13 16:09:20 -070098 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;
Jeff Sharkeyce6a9132015-04-08 21:07:21 -0700105 /* Flag that we just partitioned and should format all volumes */
106 bool mJustPartitioned;
Jeff Sharkey36801cc2015-03-13 16:09:20 -0700107
108 void createPublicVolume(dev_t device);
Jeff Sharkey9c484982015-03-31 10:35:33 -0700109 void createPrivateVolume(dev_t device, const std::string& partGuid);
Jeff Sharkey36801cc2015-03-13 16:09:20 -0700110
111 void destroyAllVolumes();
Jeff Sharkeydeb24052015-03-02 21:01:40 -0800112
113 int getMaxMinors();
114
115 DISALLOW_COPY_AND_ASSIGN(Disk);
116};
117
118} // namespace vold
119} // namespace android
120
121#endif