blob: 6f5cd01750c2317008ea75dc8306be1c9a801e87 [file] [log] [blame]
Tom Marshall292bd232019-01-04 14:37:31 -08001/*
2 * Copyright (C) 2015 Cyanogen, Inc.
3 * Copyright (C) 2019 The LineageOS Project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#include "DiskPartition.h"
19#include "PublicVolume.h"
20#include <volume_manager/ResponseCode.h>
21#include <volume_manager/VolumeManager.h>
22#include "Utils.h"
23#include "VolumeBase.h"
24
25#include <android-base/file.h>
26#include <android-base/logging.h>
27#include <android-base/stringprintf.h>
28#include <diskconfig/diskconfig.h>
29
30#include <fcntl.h>
31#include <inttypes.h>
32#include <stdio.h>
33#include <stdlib.h>
34#include <sys/mount.h>
35#include <sys/stat.h>
36#include <sys/sysmacros.h>
37#include <sys/types.h>
38#include <vector>
39
40using android::base::ReadFileToString;
41using android::base::WriteStringToFile;
42using android::base::StringPrintf;
43
44namespace android {
45namespace volmgr {
46
47DiskPartition::DiskPartition(const std::string& eventPath, dev_t device, const std::string& nickname,
48 int flags, int partnum, const std::string& fstype /* = "" */,
49 const std::string& mntopts /* = "" */)
50 : Disk(eventPath, device, nickname, flags),
51 mPartNum(partnum),
52 mFsType(fstype),
53 mMntOpts(mntopts) {
54 // Empty
55}
56
57DiskPartition::~DiskPartition() {
58 // Empty
59}
60
61status_t DiskPartition::create() {
62 CHECK(!mCreated);
63 mCreated = true;
64 VolumeManager::Instance()->notifyEvent(ResponseCode::DiskCreated, StringPrintf("%d", mFlags));
65 dev_t partDevice = makedev(major(mDevice), minor(mDevice) + mPartNum);
66 createPublicVolume(partDevice, mFsType, mMntOpts);
67 return OK;
68}
69
70status_t DiskPartition::destroy() {
71 CHECK(mCreated);
72 destroyAllVolumes();
73 mCreated = false;
74 VolumeManager::Instance()->notifyEvent(ResponseCode::DiskDestroyed);
75 return OK;
76}
77
78} // namespace volmgr
79} // namespace android