Jeff Sharkey | deb2405 | 2015-03-02 21:01:40 -0800 | [diff] [blame] | 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" |
Jeff Sharkey | c86ab6f | 2015-06-26 14:02:09 -0700 | [diff] [blame] | 21 | #include "VolumeBase.h" |
Jeff Sharkey | deb2405 | 2015-03-02 21:01:40 -0800 | [diff] [blame] | 22 | |
| 23 | #include <utils/Errors.h> |
| 24 | |
| 25 | #include <vector> |
| 26 | |
| 27 | namespace android { |
| 28 | namespace vold { |
| 29 | |
| 30 | class VolumeBase; |
| 31 | |
Jeff Sharkey | deb2405 | 2015-03-02 21:01:40 -0800 | [diff] [blame] | 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: |
Jeff Sharkey | 36801cc | 2015-03-13 16:09:20 -0700 | [diff] [blame] | 40 | Disk(const std::string& eventPath, dev_t device, const std::string& nickname, int flags); |
Jeff Sharkey | deb2405 | 2015-03-02 21:01:40 -0800 | [diff] [blame] | 41 | virtual ~Disk(); |
| 42 | |
Jeff Sharkey | 36801cc | 2015-03-13 16:09:20 -0700 | [diff] [blame] | 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, |
Jeff Sharkey | 5a6bfca | 2015-05-14 20:33:55 -0700 | [diff] [blame] | 53 | /* Flag that disk is EMMC internal */ |
| 54 | kEmmc = 1 << 4, |
Jeff Sharkey | 36801cc | 2015-03-13 16:09:20 -0700 | [diff] [blame] | 55 | }; |
| 56 | |
Jeff Sharkey | deb2405 | 2015-03-02 21:01:40 -0800 | [diff] [blame] | 57 | const std::string& getId() { return mId; } |
Jeff Sharkey | 36801cc | 2015-03-13 16:09:20 -0700 | [diff] [blame] | 58 | const std::string& getEventPath() { return mEventPath; } |
Jeff Sharkey | deb2405 | 2015-03-02 21:01:40 -0800 | [diff] [blame] | 59 | const std::string& getSysPath() { return mSysPath; } |
| 60 | const std::string& getDevPath() { return mDevPath; } |
| 61 | dev_t getDevice() { return mDevice; } |
| 62 | uint64_t getSize() { return mSize; } |
| 63 | const std::string& getLabel() { return mLabel; } |
Jeff Sharkey | 36801cc | 2015-03-13 16:09:20 -0700 | [diff] [blame] | 64 | int getFlags() { return mFlags; } |
Jeff Sharkey | deb2405 | 2015-03-02 21:01:40 -0800 | [diff] [blame] | 65 | |
| 66 | std::shared_ptr<VolumeBase> findVolume(const std::string& id); |
| 67 | |
Jeff Sharkey | c86ab6f | 2015-06-26 14:02:09 -0700 | [diff] [blame] | 68 | void listVolumes(VolumeBase::Type type, std::list<std::string>& list); |
| 69 | |
Jeff Sharkey | 36801cc | 2015-03-13 16:09:20 -0700 | [diff] [blame] | 70 | status_t create(); |
| 71 | status_t destroy(); |
| 72 | |
Jeff Sharkey | deb2405 | 2015-03-02 21:01:40 -0800 | [diff] [blame] | 73 | status_t readMetadata(); |
| 74 | status_t readPartitions(); |
| 75 | |
Jeff Sharkey | 9c48498 | 2015-03-31 10:35:33 -0700 | [diff] [blame] | 76 | status_t unmountAll(); |
| 77 | |
Jeff Sharkey | deb2405 | 2015-03-02 21:01:40 -0800 | [diff] [blame] | 78 | status_t partitionPublic(); |
| 79 | status_t partitionPrivate(); |
| 80 | status_t partitionMixed(int8_t ratio); |
| 81 | |
Jeff Sharkey | ce6a913 | 2015-04-08 21:07:21 -0700 | [diff] [blame] | 82 | void notifyEvent(int msg); |
| 83 | void notifyEvent(int msg, const std::string& value); |
| 84 | |
Jeff Sharkey | deb2405 | 2015-03-02 21:01:40 -0800 | [diff] [blame] | 85 | private: |
| 86 | /* ID that uniquely references this disk */ |
| 87 | std::string mId; |
Jeff Sharkey | 36801cc | 2015-03-13 16:09:20 -0700 | [diff] [blame] | 88 | /* Original event path */ |
| 89 | std::string mEventPath; |
Jeff Sharkey | deb2405 | 2015-03-02 21:01:40 -0800 | [diff] [blame] | 90 | /* Device path under sysfs */ |
| 91 | std::string mSysPath; |
| 92 | /* Device path under dev */ |
| 93 | std::string mDevPath; |
| 94 | /* Kernel device representing disk */ |
| 95 | dev_t mDevice; |
| 96 | /* Size of disk, in bytes */ |
| 97 | uint64_t mSize; |
| 98 | /* User-visible label, such as manufacturer */ |
| 99 | std::string mLabel; |
| 100 | /* Current partitions on disk */ |
Jeff Sharkey | 36801cc | 2015-03-13 16:09:20 -0700 | [diff] [blame] | 101 | std::vector<std::shared_ptr<VolumeBase>> mVolumes; |
| 102 | /* Nickname for this disk */ |
| 103 | std::string mNickname; |
| 104 | /* Flags applicable to this disk */ |
| 105 | int mFlags; |
| 106 | /* Flag indicating object is created */ |
| 107 | bool mCreated; |
Jeff Sharkey | ce6a913 | 2015-04-08 21:07:21 -0700 | [diff] [blame] | 108 | /* Flag that we just partitioned and should format all volumes */ |
| 109 | bool mJustPartitioned; |
Jeff Sharkey | 36801cc | 2015-03-13 16:09:20 -0700 | [diff] [blame] | 110 | |
| 111 | void createPublicVolume(dev_t device); |
Jeff Sharkey | 9c48498 | 2015-03-31 10:35:33 -0700 | [diff] [blame] | 112 | void createPrivateVolume(dev_t device, const std::string& partGuid); |
Jeff Sharkey | 36801cc | 2015-03-13 16:09:20 -0700 | [diff] [blame] | 113 | |
| 114 | void destroyAllVolumes(); |
Jeff Sharkey | deb2405 | 2015-03-02 21:01:40 -0800 | [diff] [blame] | 115 | |
| 116 | int getMaxMinors(); |
| 117 | |
| 118 | DISALLOW_COPY_AND_ASSIGN(Disk); |
| 119 | }; |
| 120 | |
| 121 | } // namespace vold |
| 122 | } // namespace android |
| 123 | |
| 124 | #endif |