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 _DEVICEVOLUME_H
18 #define _DEVICEVOLUME_H
19 
20 #include <utils/List.h>
21 
22 #include "Volume.h"
23 
24 class PathInfo {
25 public:
26 	PathInfo(const char *pattern);
27 	~PathInfo();
28 	bool match(const char *path);
29 private:
30 	bool warned;
31 	char *pattern;
32 	enum PatternType { prefix, wildcard };
33 	PatternType patternType;
34 };
35 
36 typedef android::List<PathInfo *> PathCollection;
37 
38 class DirectVolume : public Volume {
39 public:
40     static const int MAX_PARTITIONS = 32;
41 protected:
42     const char* mMountpoint;
43     const char* mFuseMountpoint;
44 
45     PathCollection *mPaths;
46     int            mDiskMajor;
47     int            mDiskMinor;
48     int            mPartMinors[MAX_PARTITIONS];
49     int            mOrigDiskMajor;
50     int            mOrigDiskMinor;
51     int            mOrigPartMinors[MAX_PARTITIONS];
52     int            mDiskNumParts;
53     int            mPendingPartCount;
54     int            mIsDecrypted;
55 
56 public:
57     DirectVolume(VolumeManager *vm, const fstab_rec* rec, int flags);
58     virtual ~DirectVolume();
59 
60     int addPath(const char *path);
61 
getMountpoint()62     const char *getMountpoint() { return mMountpoint; }
getFuseMountpoint()63     const char *getFuseMountpoint() { return mFuseMountpoint; }
64 
65     int handleBlockEvent(NetlinkEvent *evt);
66     dev_t getDiskDevice();
67     dev_t getShareDevice();
68     void handleVolumeShared();
69     void handleVolumeUnshared();
70     int getVolInfo(struct volume_info *v);
71 
72 protected:
73     int getDeviceNodes(dev_t *devs, int max);
74     int updateDeviceInfo(char *new_path, int new_major, int new_minor);
75     virtual void revertDeviceInfo(void);
isDecrypted()76     int isDecrypted() { return mIsDecrypted; }
77 
78 private:
79     void handleDiskAdded(const char *devpath, NetlinkEvent *evt);
80     void handleDiskRemoved(const char *devpath, NetlinkEvent *evt);
81     void handleDiskChanged(const char *devpath, NetlinkEvent *evt);
82     void handlePartitionAdded(const char *devpath, NetlinkEvent *evt);
83     void handlePartitionRemoved(const char *devpath, NetlinkEvent *evt);
84     void handlePartitionChanged(const char *devpath, NetlinkEvent *evt);
85 
86     int doMountVfat(const char *deviceNode, const char *mountPoint);
87 
88 };
89 
90 typedef android::List<DirectVolume *> DirectVolumeCollection;
91 
92 #endif
93