summaryrefslogtreecommitdiff
path: root/VolumeManager.h (plain)
blob: 59b8c69eabf0059e2b9bdc9bc44fd510cbb83dec
1/*
2 * Copyright (C) 2008 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_DROIDVOLD_VOLUME_MANAGER_H
18#define ANDROID_DROIDVOLD_VOLUME_MANAGER_H
19
20#include <pthread.h>
21#include <fnmatch.h>
22#include <stdlib.h>
23
24#include <list>
25#include <mutex>
26#include <string>
27#include <unordered_map>
28#include <unordered_set>
29
30#include <cutils/multiuser.h>
31#include <utils/List.h>
32#include <utils/Timers.h>
33#include <sysutils/NetlinkEvent.h>
34
35#include "Disk.h"
36#include "VolumeBase.h"
37#include "DroidVold.h"
38
39using namespace android;
40using ::vendor::amlogic::hardware::droidvold::V1_0::implementation::DroidVold;
41
42class VolumeManager {
43public:
44#ifdef HAS_VIRTUAL_CDROM
45 char *mLoopPath;
46#endif
47
48private:
49 static VolumeManager *sInstance;
50
51 DroidVold *mBroadcaster;
52
53 bool mDebug;
54
55public:
56 virtual ~VolumeManager();
57 // TODO: pipe all requests through VM to avoid exposing this lock
58 std::mutex& getLock() { return mLock; }
59
60 int start();
61 int stop();
62
63 void handleBlockEvent(NetlinkEvent *evt);
64
65 class DiskSource {
66 public:
67 DiskSource(const std::string& sysPattern, const std::string& nickname, int flags) :
68 mSysPattern(sysPattern), mNickname(nickname), mFlags(flags) {
69 }
70
71 bool matches(const std::string& sysPath) {
72 return !fnmatch(mSysPattern.c_str(), sysPath.c_str(), 0);
73 }
74
75 const std::string& getNickname() { return mNickname; }
76 int getFlags() { return mFlags; }
77
78 private:
79 std::string mSysPattern;
80 std::string mNickname;
81 int mFlags;
82 };
83
84 void addDiskSource(const std::shared_ptr<DiskSource>& diskSource);
85 std::shared_ptr<android::droidvold::VolumeBase> findVolume(const std::string& id);
86 void listVolumes(android::droidvold::VolumeBase::Type type, std::list<std::string>& list);
87
88 /* Reset all internal state, typically during framework boot */
89 int reset();
90 /* Prepare for device shutdown, safely unmounting all devices */
91 int shutdown();
92
93 /* Unmount all volumes, usually for encryption */
94 int unmountAll();
95
96 /* for iso file mount and umount */
97#ifdef HAS_VIRTUAL_CDROM
98 int loopsetfd(const char * path);
99 int loopclrfd();
100 int mountloop(const char * path);
101 int unmountloop(bool force);
102 void unmountLoopIfNeed(const char *label);
103#endif
104
105 int setDebug(bool enable);
106 bool getDebug() { return mDebug; }
107
108 void setBroadcaster(DroidVold *sl) { mBroadcaster = sl; }
109 DroidVold *getBroadcaster() { return mBroadcaster; }
110
111 static VolumeManager *Instance();
112 bool isMountpointMounted(const char *mp);
113 int mkdirs(char* path);
114 void coldboot(const char *path);
115 int getDiskFlag(const std::string &path);
116
117private:
118 VolumeManager();
119
120 std::mutex mLock;
121 std::list<std::shared_ptr<DiskSource>> mDiskSources;
122 std::list<std::shared_ptr<android::droidvold::Disk>> mDisks;
123};
124
125#endif
126