VolumeManager.h revision 29d8da8cefa99e436c13295d4c9bad060ca18a6d
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 _VOLUMEMANAGER_H 18#define _VOLUMEMANAGER_H 19 20#include <pthread.h> 21 22#ifdef __cplusplus 23#include <utils/List.h> 24#include <sysutils/SocketListener.h> 25 26#include "Volume.h" 27 28/* The length of an MD5 hash when encoded into ASCII hex characters */ 29#define MD5_ASCII_LENGTH_PLUS_NULL ((MD5_DIGEST_LENGTH*2)+1) 30 31typedef enum { ASEC, OBB } container_type_t; 32 33class ContainerData { 34public: 35 ContainerData(char* _id, container_type_t _type) 36 : id(_id) 37 , type(_type) 38 {} 39 40 ~ContainerData() { 41 if (id != NULL) { 42 free(id); 43 id = NULL; 44 } 45 } 46 47 char *id; 48 container_type_t type; 49}; 50 51typedef android::List<ContainerData*> AsecIdCollection; 52 53class VolumeManager { 54private: 55 static VolumeManager *sInstance; 56 57private: 58 SocketListener *mBroadcaster; 59 60 VolumeCollection *mVolumes; 61 AsecIdCollection *mActiveContainers; 62 bool mUsbMassStorageEnabled; 63 bool mUsbConnected; 64 bool mDebug; 65 66 // for adjusting /proc/sys/vm/dirty_ratio when UMS is active 67 int mUmsSharingCount; 68 int mSavedDirtyRatio; 69 int mUmsDirtyRatio; 70 71public: 72 virtual ~VolumeManager(); 73 74 int start(); 75 int stop(); 76 77 void handleBlockEvent(NetlinkEvent *evt); 78 void handleSwitchEvent(NetlinkEvent *evt); 79 void handleUsbCompositeEvent(NetlinkEvent *evt); 80 81 int addVolume(Volume *v); 82 83 int listVolumes(SocketClient *cli); 84 int mountVolume(const char *label); 85 int unmountVolume(const char *label, bool force); 86 int shareVolume(const char *label, const char *method); 87 int unshareVolume(const char *label, const char *method); 88 int shareAvailable(const char *method, bool *avail); 89 int shareEnabled(const char *path, const char *method, bool *enabled); 90 int simulate(const char *cmd, const char *arg); 91 int formatVolume(const char *label); 92 93 /* ASEC */ 94 int createAsec(const char *id, unsigned numSectors, const char *fstype, 95 const char *key, int ownerUid); 96 int finalizeAsec(const char *id); 97 int destroyAsec(const char *id, bool force); 98 int mountAsec(const char *id, const char *key, int ownerUid); 99 int unmountAsec(const char *id, bool force); 100 int renameAsec(const char *id1, const char *id2); 101 int getAsecMountPath(const char *id, char *buffer, int maxlen); 102 103 /* Loopback images */ 104 int listMountedObbs(SocketClient* cli); 105 int mountObb(const char *fileName, const char *key, int ownerUid); 106 int unmountObb(const char *fileName, bool force); 107 int getObbMountPath(const char *id, char *buffer, int maxlen); 108 109 /* Shared between ASEC and Loopback images */ 110 int unmountLoopImage(const char *containerId, const char *loopId, 111 const char *fileName, const char *mountPoint, bool force); 112 113 void setDebug(bool enable); 114 115 // XXX: Post froyo this should be moved and cleaned up 116 int cleanupAsec(Volume *v, bool force); 117 118 void setBroadcaster(SocketListener *sl) { mBroadcaster = sl; } 119 SocketListener *getBroadcaster() { return mBroadcaster; } 120 121 static VolumeManager *Instance(); 122 123 static char *asecHash(const char *id, char *buffer, size_t len); 124 125 Volume *lookupVolume(const char *label); 126 int getNumDirectVolumes(void); 127 int getDirectVolumeList(struct volume_info *vol_list); 128 129private: 130 VolumeManager(); 131 void readInitialState(); 132 bool isMountpointMounted(const char *mp); 133 134 inline bool massStorageAvailable() const { return mUsbMassStorageEnabled && mUsbConnected; } 135 void notifyUmsAvailable(bool available); 136}; 137 138extern "C" { 139#endif /* __cplusplus */ 140 int vold_unmountVol(const char *label); 141 int vold_getNumDirectVolumes(void); 142 int vold_getDirectVolumeList(struct volume_info *v); 143#ifdef __cplusplus 144} 145#endif 146 147#endif 148