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 49 static const char *LOOPDIR; 50 51 protected: 52 char *mLabel; 53 VolumeManager *mVm; 54 bool mDebug; 55 int mPartIdx; 56 int mOrigPartIdx; 57 bool mRetryMount; 58 59 /* 60 * The major/minor tuple of the currently mounted filesystem. 61 */ 62 dev_t mCurrentlyMountedKdev; 63 64 public: 65 Volume(VolumeManager *vm, const fstab_rec* rec, int flags); 66 virtual ~Volume(); 67 68 int mountVol(); 69 int unmountVol(bool force, bool revert); 70 int formatVol(bool wipe); 71 72 const char *getLabel() { return mLabel; } 73 int getState() { return mState; } 74 int getFlags() { return mFlags; }; 75 76 /* Mountpoint of the raw volume */ 77 virtual const char *getMountpoint() = 0; 78 virtual const char *getFuseMountpoint() = 0; 79 80 virtual int handleBlockEvent(NetlinkEvent *evt); 81 virtual dev_t getDiskDevice(); 82 virtual dev_t getShareDevice(); 83 virtual void handleVolumeShared(); 84 virtual void handleVolumeUnshared(); 85 86 void setDebug(bool enable); 87 virtual int getVolInfo(struct volume_info *v) = 0; 88 89 protected: 90 void setState(int state); 91 92 virtual int getDeviceNodes(dev_t *devs, int max) = 0; 93 virtual int updateDeviceInfo(char *new_path, int new_major, int new_minor) = 0; 94 virtual void revertDeviceInfo(void) = 0; 95 virtual int isDecrypted(void) = 0; 96 97 int createDeviceNode(const char *path, int major, int minor); 98 99 private: 100 int initializeMbr(const char *deviceNode); 101 bool isMountpointMounted(const char *path); 102 int mountAsecExternal(); 103 int doUnmount(const char *path, bool force); 104 void protectFromAutorunStupidity(); 105 }; 106 107 typedef android::List<Volume *> VolumeCollection; 108 109 #endif 110