San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 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> |
Jeff Sharkey | ba6ae8d | 2013-07-15 18:14:25 -0700 | [diff] [blame] | 21 | #include <fs_mgr.h> |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 22 | |
San Mehat | fd7f587 | 2009-10-12 11:32:47 -0700 | [diff] [blame] | 23 | class NetlinkEvent; |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 24 | class VolumeManager; |
San Mehat | fd7f587 | 2009-10-12 11:32:47 -0700 | [diff] [blame] | 25 | |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 26 | class Volume { |
| 27 | private: |
| 28 | int mState; |
Jeff Sharkey | ba6ae8d | 2013-07-15 18:14:25 -0700 | [diff] [blame] | 29 | int mFlags; |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 30 | |
| 31 | public: |
| 32 | static const int State_Init = -1; |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 33 | static const int State_NoMedia = 0; |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 34 | static const int State_Idle = 1; |
| 35 | static const int State_Pending = 2; |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 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; |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 42 | |
Jeff Sharkey | ba6ae8d | 2013-07-15 18:14:25 -0700 | [diff] [blame] | 43 | static const char *MEDIA_DIR; |
| 44 | static const char *FUSE_DIR; |
Kenny Root | 344ca10 | 2012-04-03 17:23:01 -0700 | [diff] [blame] | 45 | static const char *SEC_ASECDIR_EXT; |
| 46 | static const char *SEC_ASECDIR_INT; |
San Mehat | 3bb6020 | 2010-02-19 18:14:36 -0800 | [diff] [blame] | 47 | static const char *ASECDIR; |
Kenny Root | fb7c4d5 | 2010-06-30 18:48:41 -0700 | [diff] [blame] | 48 | static const char *LOOPDIR; |
Jeff Sharkey | 0de365f | 2013-10-16 16:24:19 -0700 | [diff] [blame] | 49 | static const char *BLKID_PATH; |
Kenny Root | fb7c4d5 | 2010-06-30 18:48:41 -0700 | [diff] [blame] | 50 | |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 51 | protected: |
Jeff Sharkey | 0de365f | 2013-10-16 16:24:19 -0700 | [diff] [blame] | 52 | char* mLabel; |
| 53 | char* mUuid; |
| 54 | char* mUserLabel; |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 55 | VolumeManager *mVm; |
San Mehat | d9a4e35 | 2010-03-12 13:32:47 -0800 | [diff] [blame] | 56 | bool mDebug; |
Mike Lockwood | a4886f1 | 2010-09-21 13:56:35 -0400 | [diff] [blame] | 57 | int mPartIdx; |
Ken Sumrall | 0b8b597 | 2011-08-31 16:14:23 -0700 | [diff] [blame] | 58 | int mOrigPartIdx; |
Joseph Lehrer | 507d31b | 2011-04-11 15:02:50 -0700 | [diff] [blame] | 59 | bool mRetryMount; |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 60 | |
| 61 | /* |
| 62 | * The major/minor tuple of the currently mounted filesystem. |
| 63 | */ |
| 64 | dev_t mCurrentlyMountedKdev; |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 65 | |
| 66 | public: |
Jeff Sharkey | ba6ae8d | 2013-07-15 18:14:25 -0700 | [diff] [blame] | 67 | Volume(VolumeManager *vm, const fstab_rec* rec, int flags); |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 68 | virtual ~Volume(); |
| 69 | |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 70 | int mountVol(); |
Ken Sumrall | 0b8b597 | 2011-08-31 16:14:23 -0700 | [diff] [blame] | 71 | int unmountVol(bool force, bool revert); |
Ken Sumrall | 9caab76 | 2013-06-11 19:10:20 -0700 | [diff] [blame] | 72 | int formatVol(bool wipe); |
San Mehat | 49e2bce | 2009-10-12 16:29:01 -0700 | [diff] [blame] | 73 | |
Jeff Sharkey | 0de365f | 2013-10-16 16:24:19 -0700 | [diff] [blame] | 74 | const char* getLabel() { return mLabel; } |
| 75 | const char* getUuid() { return mUuid; } |
| 76 | const char* getUserLabel() { return mUserLabel; } |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 77 | int getState() { return mState; } |
Jeff Sharkey | ba6ae8d | 2013-07-15 18:14:25 -0700 | [diff] [blame] | 78 | int getFlags() { return mFlags; }; |
| 79 | |
| 80 | /* Mountpoint of the raw volume */ |
| 81 | virtual const char *getMountpoint() = 0; |
| 82 | virtual const char *getFuseMountpoint() = 0; |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 83 | |
San Mehat | fd7f587 | 2009-10-12 11:32:47 -0700 | [diff] [blame] | 84 | virtual int handleBlockEvent(NetlinkEvent *evt); |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 85 | virtual dev_t getDiskDevice(); |
Mike Lockwood | 2dfe297 | 2010-09-17 18:50:51 -0400 | [diff] [blame] | 86 | virtual dev_t getShareDevice(); |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 87 | virtual void handleVolumeShared(); |
| 88 | virtual void handleVolumeUnshared(); |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 89 | |
San Mehat | d9a4e35 | 2010-03-12 13:32:47 -0800 | [diff] [blame] | 90 | void setDebug(bool enable); |
Ken Sumrall | 29d8da8 | 2011-05-18 17:20:07 -0700 | [diff] [blame] | 91 | virtual int getVolInfo(struct volume_info *v) = 0; |
San Mehat | d9a4e35 | 2010-03-12 13:32:47 -0800 | [diff] [blame] | 92 | |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 93 | protected: |
Jeff Sharkey | 0de365f | 2013-10-16 16:24:19 -0700 | [diff] [blame] | 94 | void setUuid(const char* uuid); |
| 95 | void setUserLabel(const char* userLabel); |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 96 | void setState(int state); |
San Mehat | 49e2bce | 2009-10-12 16:29:01 -0700 | [diff] [blame] | 97 | |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 98 | virtual int getDeviceNodes(dev_t *devs, int max) = 0; |
Ken Sumrall | 29d8da8 | 2011-05-18 17:20:07 -0700 | [diff] [blame] | 99 | virtual int updateDeviceInfo(char *new_path, int new_major, int new_minor) = 0; |
Ken Sumrall | 0b8b597 | 2011-08-31 16:14:23 -0700 | [diff] [blame] | 100 | virtual void revertDeviceInfo(void) = 0; |
Ken Sumrall | 29d8da8 | 2011-05-18 17:20:07 -0700 | [diff] [blame] | 101 | virtual int isDecrypted(void) = 0; |
San Mehat | 49e2bce | 2009-10-12 16:29:01 -0700 | [diff] [blame] | 102 | |
San Mehat | dd9b8e9 | 2009-10-21 11:06:52 -0700 | [diff] [blame] | 103 | int createDeviceNode(const char *path, int major, int minor); |
| 104 | |
San Mehat | 49e2bce | 2009-10-12 16:29:01 -0700 | [diff] [blame] | 105 | private: |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 106 | int initializeMbr(const char *deviceNode); |
| 107 | bool isMountpointMounted(const char *path); |
Jeff Sharkey | ba6ae8d | 2013-07-15 18:14:25 -0700 | [diff] [blame] | 108 | int mountAsecExternal(); |
San Mehat | 3bb6020 | 2010-02-19 18:14:36 -0800 | [diff] [blame] | 109 | int doUnmount(const char *path, bool force); |
Jeff Sharkey | 0de365f | 2013-10-16 16:24:19 -0700 | [diff] [blame] | 110 | int extractMetadata(const char* devicePath); |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 111 | }; |
| 112 | |
| 113 | typedef android::List<Volume *> VolumeCollection; |
| 114 | |
| 115 | #endif |