blob: 26ac6f54b6384fcdcf5a0c4026cffde9859b7188 [file] [log] [blame]
Tom Marshall3e101752019-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>
Tom Marshall3e101752019-01-04 14:37:31 -080028
29#include <fcntl.h>
30#include <inttypes.h>
31#include <stdio.h>
32#include <stdlib.h>
33#include <sys/mount.h>
34#include <sys/stat.h>
35#include <sys/sysmacros.h>
36#include <sys/types.h>
37#include <vector>
38
39using android::base::ReadFileToString;
40using android::base::WriteStringToFile;
41using android::base::StringPrintf;
42
43namespace android {
44namespace volmgr {
45
46DiskPartition::DiskPartition(const std::string& eventPath, dev_t device, const std::string& nickname,
47 int flags, int partnum, const std::string& fstype /* = "" */,
48 const std::string& mntopts /* = "" */)
49 : Disk(eventPath, device, nickname, flags),
50 mPartNum(partnum),
51 mFsType(fstype),
52 mMntOpts(mntopts) {
53 // Empty
54}
55
56DiskPartition::~DiskPartition() {
57 // Empty
58}
59
60status_t DiskPartition::create() {
61 CHECK(!mCreated);
62 mCreated = true;
63 VolumeManager::Instance()->notifyEvent(ResponseCode::DiskCreated, StringPrintf("%d", mFlags));
64 dev_t partDevice = makedev(major(mDevice), minor(mDevice) + mPartNum);
65 createPublicVolume(partDevice, mFsType, mMntOpts);
66 return OK;
67}
68
69status_t DiskPartition::destroy() {
70 CHECK(mCreated);
71 destroyAllVolumes();
72 mCreated = false;
73 VolumeManager::Instance()->notifyEvent(ResponseCode::DiskDestroyed);
74 return OK;
75}
76
77} // namespace volmgr
78} // namespace android