blob: 10b2f9570e2e41b5f04ef811e6ded66caba3605f [file] [log] [blame]
Tom Marshallaf693242015-11-04 15:44:44 -08001/*
2 * Copyright (C) 2015 Cyanogen, Inc.
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#include "DiskPartition.h"
18#include "PublicVolume.h"
19#include "PrivateVolume.h"
20#include "Utils.h"
21#include "VolumeBase.h"
22#include "VolumeManager.h"
23
24#include <android-base/file.h>
25#include <android-base/stringprintf.h>
26#include <android-base/logging.h>
27#include <diskconfig/diskconfig.h>
28
29#include <vector>
30#include <fcntl.h>
31#include <inttypes.h>
32#include <stdio.h>
33#include <stdlib.h>
34#include <sys/types.h>
35#include <sys/sysmacros.h>
36#include <sys/stat.h>
37#include <sys/mount.h>
38
39using android::base::ReadFileToString;
40using android::base::WriteStringToFile;
41using android::base::StringPrintf;
42
43namespace android {
44namespace vold {
45
46DiskPartition::DiskPartition(const std::string& eventPath, dev_t device,
Tom Marshalld18795d2015-11-05 11:20:54 -080047 const std::string& nickname, int flags, int partnum,
48 const std::string& fstype /* = "" */, const std::string& mntopts /* = "" */) :
Tom Marshallaf693242015-11-04 15:44:44 -080049 Disk(eventPath, device, nickname, flags),
Tom Marshalld18795d2015-11-05 11:20:54 -080050 mPartNum(partnum),
51 mFsType(fstype),
52 mMntOpts(mntopts) {
Tom Marshallaf693242015-11-04 15:44:44 -080053 // Empty
54}
55
56DiskPartition::~DiskPartition() {
57 // Empty
58}
59
60status_t DiskPartition::create() {
61 CHECK(!mCreated);
62 mCreated = true;
63 auto listener = VolumeManager::Instance()->getListener();
64 if (listener) listener->onDiskCreated(getId(), mFlags);
65 dev_t partDevice = makedev(major(mDevice), minor(mDevice) + mPartNum);
Tom Marshalld18795d2015-11-05 11:20:54 -080066 createPublicVolume(partDevice, mFsType, mMntOpts);
Tom Marshallaf693242015-11-04 15:44:44 -080067 return OK;
68}
69
70status_t DiskPartition::destroy() {
71 CHECK(mCreated);
72 destroyAllVolumes();
73 mCreated = false;
74 auto listener = VolumeManager::Instance()->getListener();
75 if (listener) listener->onDiskDestroyed(getId());
76 return OK;
77}
78
79status_t DiskPartition::partitionPublic() {
80 return -1;
81}
82
83status_t DiskPartition::partitionPrivate() {
84 return -1;
85}
86
87status_t DiskPartition::partitionMixed(int8_t ratio) {
88 return -1;
89}
90
91} // namespace vold
92} // namespace android
93