Jeff Sharkey | 9c48498 | 2015-03-31 10:35:33 -0700 | [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_PRIVATE_VOLUME_H |
| 18 | #define ANDROID_VOLD_PRIVATE_VOLUME_H |
| 19 | |
| 20 | #include "VolumeBase.h" |
| 21 | |
| 22 | #include <cutils/multiuser.h> |
| 23 | |
| 24 | namespace android { |
| 25 | namespace vold { |
| 26 | |
| 27 | /* |
| 28 | * Private storage provided by an encrypted partition. |
| 29 | * |
| 30 | * Given a raw block device, it knows how to wrap it in dm-crypt and |
| 31 | * format as ext4/f2fs. EmulatedVolume can be stacked above it. |
| 32 | * |
| 33 | * This volume is designed to behave much like the internal /data |
| 34 | * partition, both in layout and function. For example, apps and |
| 35 | * private app data can be safely stored on this volume because the |
| 36 | * keys are tightly tied to this device. |
| 37 | */ |
| 38 | class PrivateVolume : public VolumeBase { |
Paul Crowley | 14c8c07 | 2018-09-18 13:30:21 -0700 | [diff] [blame] | 39 | public: |
Paul Crowley | 3d98f5d | 2020-02-07 11:49:09 -0800 | [diff] [blame] | 40 | PrivateVolume(dev_t device, const KeyBuffer& keyRaw); |
Jeff Sharkey | 9c48498 | 2015-03-31 10:35:33 -0700 | [diff] [blame] | 41 | virtual ~PrivateVolume(); |
Greg Kaiser | 2bc201e | 2018-12-18 08:42:08 -0800 | [diff] [blame] | 42 | const std::string& getFsType() const { return mFsType; }; |
| 43 | const std::string& getRawDevPath() const { return mRawDevPath; }; |
| 44 | const std::string& getRawDmDevPath() const { return mDmDevPath; }; |
Zim | a438b24 | 2019-09-25 14:37:38 +0100 | [diff] [blame] | 45 | const std::string& getFsUuid() const { return mFsUuid; }; |
| 46 | dev_t getRawDevice() const { return mRawDevice; }; |
Jeff Sharkey | 9c48498 | 2015-03-31 10:35:33 -0700 | [diff] [blame] | 47 | |
Paul Crowley | 14c8c07 | 2018-09-18 13:30:21 -0700 | [diff] [blame] | 48 | protected: |
Jeff Sharkey | 9c48498 | 2015-03-31 10:35:33 -0700 | [diff] [blame] | 49 | status_t doCreate() override; |
| 50 | status_t doDestroy() override; |
| 51 | status_t doMount() override; |
Martijn Coenen | 5ec8658 | 2020-05-04 14:57:35 +0200 | [diff] [blame] | 52 | void doPostMount() override; |
Jeff Sharkey | 9c48498 | 2015-03-31 10:35:33 -0700 | [diff] [blame] | 53 | status_t doUnmount() override; |
Jeff Sharkey | d0640f6 | 2015-05-21 22:35:42 -0700 | [diff] [blame] | 54 | status_t doFormat(const std::string& fsType) override; |
Jeff Sharkey | 9c48498 | 2015-03-31 10:35:33 -0700 | [diff] [blame] | 55 | |
| 56 | status_t readMetadata(); |
| 57 | |
Paul Crowley | 14c8c07 | 2018-09-18 13:30:21 -0700 | [diff] [blame] | 58 | private: |
Jeff Sharkey | 9c48498 | 2015-03-31 10:35:33 -0700 | [diff] [blame] | 59 | /* Kernel device of raw, encrypted partition */ |
| 60 | dev_t mRawDevice; |
| 61 | /* Path to raw, encrypted block device */ |
| 62 | std::string mRawDevPath; |
| 63 | /* Path to decrypted block device */ |
| 64 | std::string mDmDevPath; |
| 65 | /* Path where decrypted device is mounted */ |
| 66 | std::string mPath; |
| 67 | |
| 68 | /* Encryption key as raw bytes */ |
Paul Crowley | 3d98f5d | 2020-02-07 11:49:09 -0800 | [diff] [blame] | 69 | KeyBuffer mKeyRaw; |
Jeff Sharkey | 9c48498 | 2015-03-31 10:35:33 -0700 | [diff] [blame] | 70 | |
| 71 | /* Filesystem type */ |
| 72 | std::string mFsType; |
| 73 | /* Filesystem UUID */ |
| 74 | std::string mFsUuid; |
| 75 | /* User-visible filesystem label */ |
| 76 | std::string mFsLabel; |
| 77 | |
| 78 | DISALLOW_COPY_AND_ASSIGN(PrivateVolume); |
| 79 | }; |
| 80 | |
| 81 | } // namespace vold |
| 82 | } // namespace android |
| 83 | |
| 84 | #endif |