blob: 96f46af140e7c5cd4b923a538f8bb063cee1d7c9 [file] [log] [blame]
San Mehatf1b736b2009-10-10 17:22:08 -07001/*
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 _DEVICEVOLUME_H
18#define _DEVICEVOLUME_H
19
20#include <utils/List.h>
21
22#include "Volume.h"
23
Octavian Purdila46c301c2014-05-05 15:13:12 +030024class PathInfo {
25public:
26 PathInfo(const char *pattern);
27 ~PathInfo();
28 bool match(const char *path);
29private:
30 bool warned;
31 char *pattern;
32 enum PatternType { prefix, wildcard };
33 PatternType patternType;
34};
35
36typedef android::List<PathInfo *> PathCollection;
San Mehatf1b736b2009-10-10 17:22:08 -070037
San Mehatae10b912009-10-12 14:57:05 -070038class DirectVolume : public Volume {
San Mehatdd9b8e92009-10-21 11:06:52 -070039public:
Hirofumi Andob4a8c9c2011-03-08 13:51:22 +090040 static const int MAX_PARTITIONS = 32;
San Mehatf1b736b2009-10-10 17:22:08 -070041protected:
Jeff Sharkeyba6ae8d2013-07-15 18:14:25 -070042 const char* mMountpoint;
43 const char* mFuseMountpoint;
44
San Mehatf1b736b2009-10-10 17:22:08 -070045 PathCollection *mPaths;
San Mehatdd9b8e92009-10-21 11:06:52 -070046 int mDiskMajor;
47 int mDiskMinor;
48 int mPartMinors[MAX_PARTITIONS];
Ken Sumrall0b8b5972011-08-31 16:14:23 -070049 int mOrigDiskMajor;
50 int mOrigDiskMinor;
51 int mOrigPartMinors[MAX_PARTITIONS];
San Mehatf1b736b2009-10-10 17:22:08 -070052 int mDiskNumParts;
Cylen Yaob31f33b2014-05-12 15:56:14 +080053 int mPendingPartCount;
Ken Sumrall29d8da82011-05-18 17:20:07 -070054 int mIsDecrypted;
San Mehatf1b736b2009-10-10 17:22:08 -070055
56public:
Jeff Sharkeyba6ae8d2013-07-15 18:14:25 -070057 DirectVolume(VolumeManager *vm, const fstab_rec* rec, int flags);
San Mehatae10b912009-10-12 14:57:05 -070058 virtual ~DirectVolume();
San Mehatf1b736b2009-10-10 17:22:08 -070059
60 int addPath(const char *path);
61
Jeff Sharkeyba6ae8d2013-07-15 18:14:25 -070062 const char *getMountpoint() { return mMountpoint; }
63 const char *getFuseMountpoint() { return mFuseMountpoint; }
64
San Mehatfd7f5872009-10-12 11:32:47 -070065 int handleBlockEvent(NetlinkEvent *evt);
San Mehata2677e42009-12-13 10:40:18 -080066 dev_t getDiskDevice();
Mike Lockwood2dfe2972010-09-17 18:50:51 -040067 dev_t getShareDevice();
San Mehata2677e42009-12-13 10:40:18 -080068 void handleVolumeShared();
69 void handleVolumeUnshared();
Ken Sumrall29d8da82011-05-18 17:20:07 -070070 int getVolInfo(struct volume_info *v);
San Mehata2677e42009-12-13 10:40:18 -080071
San Mehat49e2bce2009-10-12 16:29:01 -070072protected:
San Mehata2677e42009-12-13 10:40:18 -080073 int getDeviceNodes(dev_t *devs, int max);
Ken Sumrall29d8da82011-05-18 17:20:07 -070074 int updateDeviceInfo(char *new_path, int new_major, int new_minor);
Ken Sumrall0b8b5972011-08-31 16:14:23 -070075 virtual void revertDeviceInfo(void);
Ken Sumrall29d8da82011-05-18 17:20:07 -070076 int isDecrypted() { return mIsDecrypted; }
San Mehatfd7f5872009-10-12 11:32:47 -070077
78private:
79 void handleDiskAdded(const char *devpath, NetlinkEvent *evt);
80 void handleDiskRemoved(const char *devpath, NetlinkEvent *evt);
San Mehata2677e42009-12-13 10:40:18 -080081 void handleDiskChanged(const char *devpath, NetlinkEvent *evt);
San Mehatfd7f5872009-10-12 11:32:47 -070082 void handlePartitionAdded(const char *devpath, NetlinkEvent *evt);
83 void handlePartitionRemoved(const char *devpath, NetlinkEvent *evt);
San Mehata2677e42009-12-13 10:40:18 -080084 void handlePartitionChanged(const char *devpath, NetlinkEvent *evt);
85
86 int doMountVfat(const char *deviceNode, const char *mountPoint);
Robert Chiras961d20d2014-05-27 10:40:37 +030087 void doUnmount(int major, int minor);
San Mehat49e2bce2009-10-12 16:29:01 -070088
San Mehatf1b736b2009-10-10 17:22:08 -070089};
90
San Mehatae10b912009-10-12 14:57:05 -070091typedef android::List<DirectVolume *> DirectVolumeCollection;
San Mehatf1b736b2009-10-10 17:22:08 -070092
93#endif