Tom Marshall | bead261 | 2019-01-04 14:37:31 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 The Android Open Source Project |
| 3 | * Copyright (C) 2019 The LineageOS Project |
| 4 | * |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | #ifndef ANDROID_VOLMGR_DISK_H |
| 19 | #define ANDROID_VOLMGR_DISK_H |
| 20 | |
| 21 | #include "Utils.h" |
| 22 | #include "VolumeBase.h" |
| 23 | |
| 24 | #include <utils/Errors.h> |
| 25 | |
| 26 | #include <vector> |
| 27 | |
| 28 | #include <volume_manager/VolumeManager.h> |
| 29 | |
| 30 | namespace android { |
| 31 | namespace volmgr { |
| 32 | |
| 33 | class VolumeBase; |
| 34 | |
| 35 | /* |
| 36 | * Representation of detected physical media. |
| 37 | * |
| 38 | * Knows how to create volumes based on the partition tables found, and also |
| 39 | * how to repartition itself. |
| 40 | */ |
| 41 | class Disk { |
| 42 | public: |
| 43 | Disk(const std::string& eventPath, dev_t device, const std::string& nickname, int flags); |
| 44 | virtual ~Disk(); |
| 45 | |
| 46 | enum Flags { |
| 47 | /* Flag that disk is adoptable */ |
| 48 | kAdoptable = 1 << 0, |
| 49 | /* Flag that disk is considered primary when the user hasn't |
| 50 | * explicitly picked a primary storage location */ |
| 51 | kDefaultPrimary = 1 << 1, |
| 52 | /* Flag that disk is SD card */ |
| 53 | kSd = 1 << 2, |
| 54 | /* Flag that disk is USB disk */ |
| 55 | kUsb = 1 << 3, |
| 56 | /* Flag that disk is EMMC internal */ |
| 57 | kEmmc = 1 << 4, |
| 58 | /* Flag that disk is non-removable */ |
| 59 | kNonRemovable = 1 << 5, |
| 60 | }; |
| 61 | |
| 62 | const std::string& getId() { return mId; } |
| 63 | const std::string& getEventPath() { return mEventPath; } |
| 64 | const std::string& getSysPath() { return mSysPath; } |
| 65 | const std::string& getDevPath() { return mDevPath; } |
| 66 | dev_t getDevice() { return mDevice; } |
| 67 | uint64_t getSize() { return mSize; } |
| 68 | const std::string& getLabel() { return mLabel; } |
| 69 | int getFlags() { return mFlags; } |
| 70 | |
| 71 | void getVolumeInfo(std::vector<VolumeInfo>& info); |
| 72 | |
| 73 | std::shared_ptr<VolumeBase> findVolume(const std::string& id); |
| 74 | |
| 75 | void listVolumes(VolumeBase::Type type, std::list<std::string>& list); |
| 76 | |
| 77 | virtual status_t create(); |
| 78 | virtual status_t destroy(); |
| 79 | |
| 80 | virtual status_t readMetadata(); |
| 81 | virtual status_t readPartitions(); |
| 82 | |
| 83 | status_t unmountAll(); |
| 84 | |
| 85 | protected: |
| 86 | /* ID that uniquely references this disk */ |
| 87 | std::string mId; |
| 88 | /* Original event path */ |
| 89 | std::string mEventPath; |
| 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 */ |
| 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; |
| 108 | /* Flag that we need to skip first disk change events after partitioning*/ |
| 109 | bool mSkipChange; |
| 110 | |
| 111 | void createPublicVolume(dev_t device, const std::string& fstype = "", |
| 112 | const std::string& mntopts = ""); |
| 113 | |
| 114 | void destroyAllVolumes(); |
| 115 | |
| 116 | int getMaxMinors(); |
| 117 | |
| 118 | DISALLOW_COPY_AND_ASSIGN(Disk); |
| 119 | }; |
| 120 | |
| 121 | } // namespace volmgr |
| 122 | } // namespace android |
| 123 | |
| 124 | #endif |