blob: a365ec67464177a9866cd72f4054ee479d76865d [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"
Jeff Sharkeyc86ab6f2015-06-26 14:02:09 -070021#include "VolumeBase.h"
Jeff Sharkeydeb24052015-03-02 21:01:40 -080022
23#include <utils/Errors.h>
24
25#include <vector>
26
27namespace android {
28namespace vold {
29
30class VolumeBase;
31
Jeff Sharkeydeb24052015-03-02 21:01:40 -080032/*
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 */
38class Disk {
39public:
Jeff Sharkey36801cc2015-03-13 16:09:20 -070040 Disk(const std::string& eventPath, dev_t device, const std::string& nickname, int flags);
Jeff Sharkeydeb24052015-03-02 21:01:40 -080041 virtual ~Disk();
42
Jeff Sharkey36801cc2015-03-13 16:09:20 -070043 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,
Jeff Sharkey5a6bfca2015-05-14 20:33:55 -070053 /* Flag that disk is EMMC internal */
54 kEmmc = 1 << 4,
Tom Marshallaf693242015-11-04 15:44:44 -080055 /* Flag that disk is non-removable */
56 kNonRemovable = 1 << 5,
Jeff Sharkey36801cc2015-03-13 16:09:20 -070057 };
58
Jeff Sharkeydeb24052015-03-02 21:01:40 -080059 const std::string& getId() { return mId; }
Jeff Sharkey36801cc2015-03-13 16:09:20 -070060 const std::string& getEventPath() { return mEventPath; }
Jeff Sharkeydeb24052015-03-02 21:01:40 -080061 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; }
Jeff Sharkey36801cc2015-03-13 16:09:20 -070066 int getFlags() { return mFlags; }
Jeff Sharkeydeb24052015-03-02 21:01:40 -080067
68 std::shared_ptr<VolumeBase> findVolume(const std::string& id);
69
Jeff Sharkeyc86ab6f2015-06-26 14:02:09 -070070 void listVolumes(VolumeBase::Type type, std::list<std::string>& list);
71
Tom Marshallaf693242015-11-04 15:44:44 -080072 virtual status_t create();
73 virtual status_t destroy();
Jeff Sharkey36801cc2015-03-13 16:09:20 -070074
Tom Marshallaf693242015-11-04 15:44:44 -080075 virtual status_t readMetadata();
76 virtual status_t readPartitions();
Jeff Sharkeydeb24052015-03-02 21:01:40 -080077
Jeff Sharkey9c484982015-03-31 10:35:33 -070078 status_t unmountAll();
79
Tom Marshallaf693242015-11-04 15:44:44 -080080 virtual status_t partitionPublic();
81 virtual status_t partitionPrivate();
82 virtual status_t partitionMixed(int8_t ratio);
Jeff Sharkeydeb24052015-03-02 21:01:40 -080083
Tom Marshallaf693242015-11-04 15:44:44 -080084protected:
Jeff Sharkeydeb24052015-03-02 21:01:40 -080085 /* ID that uniquely references this disk */
86 std::string mId;
Jeff Sharkey36801cc2015-03-13 16:09:20 -070087 /* Original event path */
88 std::string mEventPath;
Jeff Sharkeydeb24052015-03-02 21:01:40 -080089 /* Device path under sysfs */
90 std::string mSysPath;
91 /* Device path under dev */
92 std::string mDevPath;
93 /* Kernel device representing disk */
94 dev_t mDevice;
95 /* Size of disk, in bytes */
96 uint64_t mSize;
97 /* User-visible label, such as manufacturer */
98 std::string mLabel;
99 /* Current partitions on disk */
Jeff Sharkey36801cc2015-03-13 16:09:20 -0700100 std::vector<std::shared_ptr<VolumeBase>> mVolumes;
101 /* Nickname for this disk */
102 std::string mNickname;
103 /* Flags applicable to this disk */
104 int mFlags;
105 /* Flag indicating object is created */
106 bool mCreated;
Jeff Sharkeyce6a9132015-04-08 21:07:21 -0700107 /* Flag that we just partitioned and should format all volumes */
108 bool mJustPartitioned;
Scott Mertzfadb5452016-03-31 13:09:56 -0700109 /* Flag that we need to skip first disk change events after partitioning*/
110 bool mSkipChange;
Jeff Sharkey36801cc2015-03-13 16:09:20 -0700111
Tom Marshalld18795d2015-11-05 11:20:54 -0800112 void createPublicVolume(dev_t device,
113 const std::string& fstype = "",
114 const std::string& mntopts = "");
Jeff Sharkey9c484982015-03-31 10:35:33 -0700115 void createPrivateVolume(dev_t device, const std::string& partGuid);
Jeff Sharkey36801cc2015-03-13 16:09:20 -0700116
117 void destroyAllVolumes();
Jeff Sharkeydeb24052015-03-02 21:01:40 -0800118
119 int getMaxMinors();
120
121 DISALLOW_COPY_AND_ASSIGN(Disk);
122};
123
124} // namespace vold
125} // namespace android
126
127#endif