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