OSDN Git Service

am 836e7860: am 8120c3d1: Merge "Adding e4crypt support"
[android-x86/system-vold.git] / Disk.h
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
31 // events:
32 // disk_created 127:4
33 // disk_meta 127:4 [size] [label]
34 // disk_destroyed 127:4
35
36 // commands:
37 // disk partition_public 127:4
38 // disk partition_private 127:4
39 // disk partition_mixed 127:4 50
40
41 /*
42  * Representation of detected physical media.
43  *
44  * Knows how to create volumes based on the partition tables found, and also
45  * how to repartition itself.
46  */
47 class Disk {
48 public:
49     Disk(const std::string& eventPath, dev_t device);
50     virtual ~Disk();
51
52     const std::string& getId() { return mId; }
53     const std::string& getSysPath() { return mSysPath; }
54     const std::string& getDevPath() { return mDevPath; }
55     dev_t getDevice() { return mDevice; }
56     uint64_t getSize() { return mSize; }
57     const std::string& getLabel() { return mLabel; }
58
59     std::shared_ptr<VolumeBase> findVolume(const std::string& id);
60
61     status_t readMetadata();
62     status_t readPartitions();
63
64     status_t partitionPublic();
65     status_t partitionPrivate();
66     status_t partitionMixed(int8_t ratio);
67
68 private:
69     /* ID that uniquely references this disk */
70     std::string mId;
71     /* Device path under sysfs */
72     std::string mSysPath;
73     /* Device path under dev */
74     std::string mDevPath;
75     /* Kernel device representing disk */
76     dev_t mDevice;
77     /* Size of disk, in bytes */
78     uint64_t mSize;
79     /* User-visible label, such as manufacturer */
80     std::string mLabel;
81     /* Current partitions on disk */
82     std::vector<std::shared_ptr<VolumeBase>> mParts;
83
84     int getMaxMinors();
85
86     DISALLOW_COPY_AND_ASSIGN(Disk);
87 };
88
89 }  // namespace vold
90 }  // namespace android
91
92 #endif