blob: 656172fa2f42657b4d025ccd2ff6711f878b2252 [file] [log] [blame]
Jeff Sharkey9c484982015-03-31 10:35:33 -07001/*
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
24namespace android {
25namespace 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 */
38class PrivateVolume : public VolumeBase {
Paul Crowley14c8c072018-09-18 13:30:21 -070039 public:
Jeff Sharkey9c484982015-03-31 10:35:33 -070040 PrivateVolume(dev_t device, const std::string& keyRaw);
41 virtual ~PrivateVolume();
Greg Kaiser2bc201e2018-12-18 08:42:08 -080042 const std::string& getFsType() const { return mFsType; };
43 const std::string& getRawDevPath() const { return mRawDevPath; };
44 const std::string& getRawDmDevPath() const { return mDmDevPath; };
Zima438b242019-09-25 14:37:38 +010045 const std::string& getFsUuid() const { return mFsUuid; };
46 dev_t getRawDevice() const { return mRawDevice; };
Jeff Sharkey9c484982015-03-31 10:35:33 -070047
Paul Crowley14c8c072018-09-18 13:30:21 -070048 protected:
Jeff Sharkey9c484982015-03-31 10:35:33 -070049 status_t doCreate() override;
50 status_t doDestroy() override;
51 status_t doMount() override;
52 status_t doUnmount() override;
Jeff Sharkeyd0640f62015-05-21 22:35:42 -070053 status_t doFormat(const std::string& fsType) override;
Jeff Sharkey9c484982015-03-31 10:35:33 -070054
55 status_t readMetadata();
56
Paul Crowley14c8c072018-09-18 13:30:21 -070057 private:
Jeff Sharkey9c484982015-03-31 10:35:33 -070058 /* Kernel device of raw, encrypted partition */
59 dev_t mRawDevice;
60 /* Path to raw, encrypted block device */
61 std::string mRawDevPath;
62 /* Path to decrypted block device */
63 std::string mDmDevPath;
64 /* Path where decrypted device is mounted */
65 std::string mPath;
66
67 /* Encryption key as raw bytes */
68 std::string mKeyRaw;
69
70 /* Filesystem type */
71 std::string mFsType;
72 /* Filesystem UUID */
73 std::string mFsUuid;
74 /* User-visible filesystem label */
75 std::string mFsLabel;
76
77 DISALLOW_COPY_AND_ASSIGN(PrivateVolume);
78};
79
80} // namespace vold
81} // namespace android
82
83#endif