• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 _VOLUME_H
18 #define _VOLUME_H
19 
20 #include <utils/List.h>
21 #include <fs_mgr.h>
22 
23 class NetlinkEvent;
24 class VolumeManager;
25 
26 class Volume {
27 private:
28     int mState;
29     int mFlags;
30 
31 public:
32     static const int State_Init       = -1;
33     static const int State_NoMedia    = 0;
34     static const int State_Idle       = 1;
35     static const int State_Pending    = 2;
36     static const int State_Checking   = 3;
37     static const int State_Mounted    = 4;
38     static const int State_Unmounting = 5;
39     static const int State_Formatting = 6;
40     static const int State_Shared     = 7;
41     static const int State_SharedMnt  = 8;
42 
43     static const char *MEDIA_DIR;
44     static const char *FUSE_DIR;
45     static const char *SEC_ASECDIR_EXT;
46     static const char *SEC_ASECDIR_INT;
47     static const char *ASECDIR;
48     static const char *LOOPDIR;
49     static const char *BLKID_PATH;
50 
51 protected:
52     char* mLabel;
53     char* mUuid;
54     char* mUserLabel;
55     VolumeManager *mVm;
56     bool mDebug;
57     int mPartIdx;
58     int mOrigPartIdx;
59     bool mRetryMount;
60 
61     /*
62      * The major/minor tuple of the currently mounted filesystem.
63      */
64     dev_t mCurrentlyMountedKdev;
65 
66 public:
67     Volume(VolumeManager *vm, const fstab_rec* rec, int flags);
68     virtual ~Volume();
69 
70     int mountVol();
71     int unmountVol(bool force, bool revert);
72     int formatVol(bool wipe);
73 
getLabel()74     const char* getLabel() { return mLabel; }
getUuid()75     const char* getUuid() { return mUuid; }
getUserLabel()76     const char* getUserLabel() { return mUserLabel; }
getState()77     int getState() { return mState; }
getFlags()78     int getFlags() { return mFlags; };
79 
80     /* Mountpoint of the raw volume */
81     virtual const char *getMountpoint() = 0;
82     virtual const char *getFuseMountpoint() = 0;
83 
84     virtual int handleBlockEvent(NetlinkEvent *evt);
85     virtual dev_t getDiskDevice();
86     virtual dev_t getShareDevice();
87     virtual void handleVolumeShared();
88     virtual void handleVolumeUnshared();
89 
90     void setDebug(bool enable);
91     virtual int getVolInfo(struct volume_info *v) = 0;
92 
93 protected:
94     void setUuid(const char* uuid);
95     void setUserLabel(const char* userLabel);
96     void setState(int state);
97 
98     virtual int getDeviceNodes(dev_t *devs, int max) = 0;
99     virtual int updateDeviceInfo(char *new_path, int new_major, int new_minor) = 0;
100     virtual void revertDeviceInfo(void) = 0;
101     virtual int isDecrypted(void) = 0;
102 
103     int createDeviceNode(const char *path, int major, int minor);
104 
105 private:
106     int initializeMbr(const char *deviceNode);
107     bool isMountpointMounted(const char *path);
108     int mountAsecExternal();
109     int doUnmount(const char *path, bool force);
110     int extractMetadata(const char* devicePath);
111 };
112 
113 typedef android::List<Volume *> VolumeCollection;
114 
115 #endif
116