blob: bb979da060f63908a404aef7142955aa43d841e6 [file] [log] [blame]
Tom Marshall35681042015-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#include "ResponseCode.h"
24
25#include <android-base/file.h>
26#include <android-base/stringprintf.h>
27#include <android-base/logging.h>
28#include <diskconfig/diskconfig.h>
29
30#include <vector>
31#include <fcntl.h>
32#include <inttypes.h>
33#include <stdio.h>
34#include <stdlib.h>
35#include <sys/types.h>
36#include <sys/sysmacros.h>
37#include <sys/stat.h>
38#include <sys/mount.h>
39
40using android::base::ReadFileToString;
41using android::base::WriteStringToFile;
42using android::base::StringPrintf;
43
44namespace android {
45namespace vold {
46
47DiskPartition::DiskPartition(const std::string& eventPath, dev_t device,
Tom Marshalld4246122015-11-05 11:20:54 -080048 const std::string& nickname, int flags, int partnum,
49 const std::string& fstype /* = "" */, const std::string& mntopts /* = "" */) :
Tom Marshall35681042015-11-04 15:44:44 -080050 Disk(eventPath, device, nickname, flags),
Tom Marshalld4246122015-11-05 11:20:54 -080051 mPartNum(partnum),
52 mFsType(fstype),
53 mMntOpts(mntopts) {
Tom Marshall35681042015-11-04 15:44:44 -080054 // Empty
55}
56
57DiskPartition::~DiskPartition() {
58 // Empty
59}
60
61status_t DiskPartition::create() {
62 CHECK(!mCreated);
63 mCreated = true;
64 notifyEvent(ResponseCode::DiskCreated, StringPrintf("%d", mFlags));
65 dev_t partDevice = makedev(major(mDevice), minor(mDevice) + mPartNum);
Tom Marshalld4246122015-11-05 11:20:54 -080066 createPublicVolume(partDevice, mFsType, mMntOpts);
Tom Marshall35681042015-11-04 15:44:44 -080067 return OK;
68}
69
70status_t DiskPartition::destroy() {
71 CHECK(mCreated);
72 destroyAllVolumes();
73 mCreated = false;
74 notifyEvent(ResponseCode::DiskDestroyed);
75 return OK;
76}
77
78status_t DiskPartition::partitionPublic() {
79 return -1;
80}
81
82status_t DiskPartition::partitionPrivate() {
83 return -1;
84}
85
86status_t DiskPartition::partitionMixed(int8_t ratio) {
87 return -1;
88}
89
90} // namespace vold
91} // namespace android
92