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 | #include <stdio.h> |
San Mehat | fd7f587 | 2009-10-12 11:32:47 -0700 | [diff] [blame] | 18 | #include <stdlib.h> |
| 19 | #include <string.h> |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 20 | #include <errno.h> |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 21 | #include <fcntl.h> |
San Mehat | a19b250 | 2010-01-06 10:33:53 -0800 | [diff] [blame] | 22 | #include <sys/stat.h> |
| 23 | #include <sys/types.h> |
| 24 | #include <sys/mount.h> |
| 25 | |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 26 | #include <linux/kdev_t.h> |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 27 | |
| 28 | #define LOG_TAG "Vold" |
| 29 | |
Kenny Root | 7b18a7b | 2010-03-15 13:13:41 -0700 | [diff] [blame] | 30 | #include <openssl/md5.h> |
| 31 | |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 32 | #include <cutils/log.h> |
| 33 | |
San Mehat | fd7f587 | 2009-10-12 11:32:47 -0700 | [diff] [blame] | 34 | #include <sysutils/NetlinkEvent.h> |
| 35 | |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 36 | #include "VolumeManager.h" |
San Mehat | ae10b91 | 2009-10-12 14:57:05 -0700 | [diff] [blame] | 37 | #include "DirectVolume.h" |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 38 | #include "ResponseCode.h" |
San Mehat | a19b250 | 2010-01-06 10:33:53 -0800 | [diff] [blame] | 39 | #include "Loop.h" |
| 40 | #include "Fat.h" |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 41 | #include "Devmapper.h" |
San Mehat | 586536c | 2010-02-16 17:12:00 -0800 | [diff] [blame] | 42 | #include "Process.h" |
San Mehat | fcf24fe | 2010-03-03 12:37:32 -0800 | [diff] [blame] | 43 | #include "Asec.h" |
San Mehat | 2396993 | 2010-01-09 07:08:06 -0800 | [diff] [blame] | 44 | |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 45 | VolumeManager *VolumeManager::sInstance = NULL; |
| 46 | |
| 47 | VolumeManager *VolumeManager::Instance() { |
| 48 | if (!sInstance) |
| 49 | sInstance = new VolumeManager(); |
| 50 | return sInstance; |
| 51 | } |
| 52 | |
| 53 | VolumeManager::VolumeManager() { |
San Mehat | d9a4e35 | 2010-03-12 13:32:47 -0800 | [diff] [blame] | 54 | mDebug = false; |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 55 | mVolumes = new VolumeCollection(); |
San Mehat | 8870516 | 2010-01-15 09:26:28 -0800 | [diff] [blame] | 56 | mActiveContainers = new AsecIdCollection(); |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 57 | mBroadcaster = NULL; |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 58 | mUsbMassStorageConnected = false; |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | VolumeManager::~VolumeManager() { |
San Mehat | 8870516 | 2010-01-15 09:26:28 -0800 | [diff] [blame] | 62 | delete mVolumes; |
| 63 | delete mActiveContainers; |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 64 | } |
| 65 | |
Kenny Root | 7b18a7b | 2010-03-15 13:13:41 -0700 | [diff] [blame] | 66 | char *VolumeManager::asecHash(const char *id, char *buffer, size_t len) { |
Kenny Root | acc9e7d | 2010-06-18 19:06:50 -0700 | [diff] [blame^] | 67 | static const char* digits = "0123456789abcdef"; |
| 68 | |
Kenny Root | 7b18a7b | 2010-03-15 13:13:41 -0700 | [diff] [blame] | 69 | unsigned char sig[MD5_DIGEST_LENGTH]; |
| 70 | |
Kenny Root | acc9e7d | 2010-06-18 19:06:50 -0700 | [diff] [blame^] | 71 | if (buffer == NULL) { |
| 72 | SLOGE("Destination buffer is NULL"); |
| 73 | errno = ESPIPE; |
| 74 | return NULL; |
| 75 | } else if (id == NULL) { |
| 76 | SLOGE("Source buffer is NULL"); |
| 77 | errno = ESPIPE; |
| 78 | return NULL; |
| 79 | } else if (len < MD5_ASCII_LENGTH_PLUS_NULL) { |
| 80 | SLOGE("Target hash buffer size < %d bytes (%d)", |
| 81 | MD5_ASCII_LENGTH_PLUS_NULL, len); |
San Mehat | d9a4e35 | 2010-03-12 13:32:47 -0800 | [diff] [blame] | 82 | errno = ESPIPE; |
| 83 | return NULL; |
| 84 | } |
Kenny Root | 7b18a7b | 2010-03-15 13:13:41 -0700 | [diff] [blame] | 85 | |
| 86 | MD5(reinterpret_cast<const unsigned char*>(id), strlen(id), sig); |
San Mehat | d9a4e35 | 2010-03-12 13:32:47 -0800 | [diff] [blame] | 87 | |
Kenny Root | acc9e7d | 2010-06-18 19:06:50 -0700 | [diff] [blame^] | 88 | char *p = buffer; |
Kenny Root | 7b18a7b | 2010-03-15 13:13:41 -0700 | [diff] [blame] | 89 | for (int i = 0; i < MD5_DIGEST_LENGTH; i++) { |
Kenny Root | acc9e7d | 2010-06-18 19:06:50 -0700 | [diff] [blame^] | 90 | *p++ = digits[sig[i] >> 4]; |
| 91 | *p++ = digits[sig[i] & 0x0F]; |
San Mehat | d9a4e35 | 2010-03-12 13:32:47 -0800 | [diff] [blame] | 92 | } |
Kenny Root | acc9e7d | 2010-06-18 19:06:50 -0700 | [diff] [blame^] | 93 | *p = '\0'; |
San Mehat | d9a4e35 | 2010-03-12 13:32:47 -0800 | [diff] [blame] | 94 | |
| 95 | return buffer; |
| 96 | } |
| 97 | |
| 98 | void VolumeManager::setDebug(bool enable) { |
| 99 | mDebug = enable; |
| 100 | VolumeCollection::iterator it; |
| 101 | for (it = mVolumes->begin(); it != mVolumes->end(); ++it) { |
| 102 | (*it)->setDebug(enable); |
| 103 | } |
| 104 | } |
| 105 | |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 106 | int VolumeManager::start() { |
| 107 | return 0; |
| 108 | } |
| 109 | |
| 110 | int VolumeManager::stop() { |
| 111 | return 0; |
| 112 | } |
| 113 | |
| 114 | int VolumeManager::addVolume(Volume *v) { |
| 115 | mVolumes->push_back(v); |
| 116 | return 0; |
| 117 | } |
| 118 | |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 119 | void VolumeManager::notifyUmsConnected(bool connected) { |
| 120 | char msg[255]; |
| 121 | |
| 122 | if (connected) { |
| 123 | mUsbMassStorageConnected = true; |
| 124 | } else { |
| 125 | mUsbMassStorageConnected = false; |
| 126 | } |
| 127 | snprintf(msg, sizeof(msg), "Share method ums now %s", |
| 128 | (connected ? "available" : "unavailable")); |
| 129 | |
| 130 | getBroadcaster()->sendBroadcast(ResponseCode::ShareAvailabilityChange, |
| 131 | msg, false); |
| 132 | } |
| 133 | |
| 134 | void VolumeManager::handleSwitchEvent(NetlinkEvent *evt) { |
San Mehat | 0cde53c | 2009-12-22 08:32:33 -0800 | [diff] [blame] | 135 | const char *devpath = evt->findParam("DEVPATH"); |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 136 | const char *name = evt->findParam("SWITCH_NAME"); |
| 137 | const char *state = evt->findParam("SWITCH_STATE"); |
| 138 | |
San Mehat | 0cde53c | 2009-12-22 08:32:33 -0800 | [diff] [blame] | 139 | if (!name || !state) { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 140 | SLOGW("Switch %s event missing name/state info", devpath); |
San Mehat | 0cde53c | 2009-12-22 08:32:33 -0800 | [diff] [blame] | 141 | return; |
| 142 | } |
| 143 | |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 144 | if (!strcmp(name, "usb_mass_storage")) { |
| 145 | |
| 146 | if (!strcmp(state, "online")) { |
| 147 | notifyUmsConnected(true); |
| 148 | } else { |
| 149 | notifyUmsConnected(false); |
| 150 | } |
| 151 | } else { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 152 | SLOGW("Ignoring unknown switch '%s'", name); |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 153 | } |
| 154 | } |
| 155 | |
San Mehat | fd7f587 | 2009-10-12 11:32:47 -0700 | [diff] [blame] | 156 | void VolumeManager::handleBlockEvent(NetlinkEvent *evt) { |
| 157 | const char *devpath = evt->findParam("DEVPATH"); |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 158 | |
San Mehat | fd7f587 | 2009-10-12 11:32:47 -0700 | [diff] [blame] | 159 | /* Lookup a volume to handle this device */ |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 160 | VolumeCollection::iterator it; |
| 161 | bool hit = false; |
| 162 | for (it = mVolumes->begin(); it != mVolumes->end(); ++it) { |
San Mehat | fd7f587 | 2009-10-12 11:32:47 -0700 | [diff] [blame] | 163 | if (!(*it)->handleBlockEvent(evt)) { |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 164 | #ifdef NETLINK_DEBUG |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 165 | SLOGD("Device '%s' event handled by volume %s\n", devpath, (*it)->getLabel()); |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 166 | #endif |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 167 | hit = true; |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 168 | break; |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | if (!hit) { |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 173 | #ifdef NETLINK_DEBUG |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 174 | SLOGW("No volumes handled block event for '%s'", devpath); |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 175 | #endif |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 176 | } |
| 177 | } |
| 178 | |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 179 | int VolumeManager::listVolumes(SocketClient *cli) { |
| 180 | VolumeCollection::iterator i; |
| 181 | |
| 182 | for (i = mVolumes->begin(); i != mVolumes->end(); ++i) { |
| 183 | char *buffer; |
| 184 | asprintf(&buffer, "%s %s %d", |
| 185 | (*i)->getLabel(), (*i)->getMountpoint(), |
| 186 | (*i)->getState()); |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 187 | cli->sendMsg(ResponseCode::VolumeListResult, buffer, false); |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 188 | free(buffer); |
| 189 | } |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 190 | cli->sendMsg(ResponseCode::CommandOkay, "Volumes listed.", false); |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 191 | return 0; |
| 192 | } |
San Mehat | 49e2bce | 2009-10-12 16:29:01 -0700 | [diff] [blame] | 193 | |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 194 | int VolumeManager::formatVolume(const char *label) { |
| 195 | Volume *v = lookupVolume(label); |
| 196 | |
| 197 | if (!v) { |
| 198 | errno = ENOENT; |
| 199 | return -1; |
| 200 | } |
| 201 | |
| 202 | return v->formatVol(); |
| 203 | } |
| 204 | |
San Mehat | a19b250 | 2010-01-06 10:33:53 -0800 | [diff] [blame] | 205 | int VolumeManager::getAsecMountPath(const char *id, char *buffer, int maxlen) { |
San Mehat | 88ac2c0 | 2010-03-23 11:15:58 -0700 | [diff] [blame] | 206 | char asecFileName[255]; |
| 207 | snprintf(asecFileName, sizeof(asecFileName), "%s/%s.asec", Volume::SEC_ASECDIR, id); |
| 208 | |
| 209 | memset(buffer, 0, maxlen); |
| 210 | if (access(asecFileName, F_OK)) { |
| 211 | errno = ENOENT; |
| 212 | return -1; |
| 213 | } |
San Mehat | a19b250 | 2010-01-06 10:33:53 -0800 | [diff] [blame] | 214 | |
San Mehat | 3bb6020 | 2010-02-19 18:14:36 -0800 | [diff] [blame] | 215 | snprintf(buffer, maxlen, "%s/%s", Volume::ASECDIR, id); |
San Mehat | a19b250 | 2010-01-06 10:33:53 -0800 | [diff] [blame] | 216 | return 0; |
| 217 | } |
| 218 | |
San Mehat | 8b8f71b | 2010-01-11 09:17:25 -0800 | [diff] [blame] | 219 | int VolumeManager::createAsec(const char *id, unsigned int numSectors, |
San Mehat | a19b250 | 2010-01-06 10:33:53 -0800 | [diff] [blame] | 220 | const char *fstype, const char *key, int ownerUid) { |
San Mehat | fcf24fe | 2010-03-03 12:37:32 -0800 | [diff] [blame] | 221 | struct asec_superblock sb; |
| 222 | memset(&sb, 0, sizeof(sb)); |
| 223 | |
| 224 | sb.magic = ASEC_SB_MAGIC; |
| 225 | sb.ver = ASEC_SB_VER; |
San Mehat | a19b250 | 2010-01-06 10:33:53 -0800 | [diff] [blame] | 226 | |
San Mehat | d31e380 | 2010-02-18 08:37:45 -0800 | [diff] [blame] | 227 | if (numSectors < ((1024*1024)/512)) { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 228 | SLOGE("Invalid container size specified (%d sectors)", numSectors); |
San Mehat | d31e380 | 2010-02-18 08:37:45 -0800 | [diff] [blame] | 229 | errno = EINVAL; |
| 230 | return -1; |
| 231 | } |
| 232 | |
San Mehat | a19b250 | 2010-01-06 10:33:53 -0800 | [diff] [blame] | 233 | if (lookupVolume(id)) { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 234 | SLOGE("ASEC id '%s' currently exists", id); |
San Mehat | a19b250 | 2010-01-06 10:33:53 -0800 | [diff] [blame] | 235 | errno = EADDRINUSE; |
| 236 | return -1; |
| 237 | } |
| 238 | |
| 239 | char asecFileName[255]; |
San Mehat | 3bb6020 | 2010-02-19 18:14:36 -0800 | [diff] [blame] | 240 | snprintf(asecFileName, sizeof(asecFileName), "%s/%s.asec", Volume::SEC_ASECDIR, id); |
San Mehat | a19b250 | 2010-01-06 10:33:53 -0800 | [diff] [blame] | 241 | |
| 242 | if (!access(asecFileName, F_OK)) { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 243 | SLOGE("ASEC file '%s' currently exists - destroy it first! (%s)", |
San Mehat | a19b250 | 2010-01-06 10:33:53 -0800 | [diff] [blame] | 244 | asecFileName, strerror(errno)); |
| 245 | errno = EADDRINUSE; |
| 246 | return -1; |
| 247 | } |
| 248 | |
San Mehat | fcf24fe | 2010-03-03 12:37:32 -0800 | [diff] [blame] | 249 | /* |
| 250 | * Add some headroom |
| 251 | */ |
| 252 | unsigned fatSize = (((numSectors * 4) / 512) + 1) * 2; |
| 253 | unsigned numImgSectors = numSectors + fatSize + 2; |
| 254 | |
| 255 | if (numImgSectors % 63) { |
| 256 | numImgSectors += (63 - (numImgSectors % 63)); |
| 257 | } |
| 258 | |
| 259 | // Add +1 for our superblock which is at the end |
| 260 | if (Loop::createImageFile(asecFileName, numImgSectors + 1)) { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 261 | SLOGE("ASEC image file creation failed (%s)", strerror(errno)); |
San Mehat | a19b250 | 2010-01-06 10:33:53 -0800 | [diff] [blame] | 262 | return -1; |
| 263 | } |
| 264 | |
San Mehat | d9a4e35 | 2010-03-12 13:32:47 -0800 | [diff] [blame] | 265 | char idHash[33]; |
| 266 | if (!asecHash(id, idHash, sizeof(idHash))) { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 267 | SLOGE("Hash of '%s' failed (%s)", id, strerror(errno)); |
San Mehat | d9a4e35 | 2010-03-12 13:32:47 -0800 | [diff] [blame] | 268 | unlink(asecFileName); |
| 269 | return -1; |
| 270 | } |
| 271 | |
San Mehat | a19b250 | 2010-01-06 10:33:53 -0800 | [diff] [blame] | 272 | char loopDevice[255]; |
San Mehat | d9a4e35 | 2010-03-12 13:32:47 -0800 | [diff] [blame] | 273 | if (Loop::create(idHash, asecFileName, loopDevice, sizeof(loopDevice))) { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 274 | SLOGE("ASEC loop device creation failed (%s)", strerror(errno)); |
San Mehat | a19b250 | 2010-01-06 10:33:53 -0800 | [diff] [blame] | 275 | unlink(asecFileName); |
| 276 | return -1; |
| 277 | } |
| 278 | |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 279 | char dmDevice[255]; |
| 280 | bool cleanupDm = false; |
San Mehat | a19b250 | 2010-01-06 10:33:53 -0800 | [diff] [blame] | 281 | |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 282 | if (strcmp(key, "none")) { |
San Mehat | fcf24fe | 2010-03-03 12:37:32 -0800 | [diff] [blame] | 283 | // XXX: This is all we support for now |
| 284 | sb.c_cipher = ASEC_SB_C_CIPHER_TWOFISH; |
San Mehat | d9a4e35 | 2010-03-12 13:32:47 -0800 | [diff] [blame] | 285 | if (Devmapper::create(idHash, loopDevice, key, numImgSectors, dmDevice, |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 286 | sizeof(dmDevice))) { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 287 | SLOGE("ASEC device mapping failed (%s)", strerror(errno)); |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 288 | Loop::destroyByDevice(loopDevice); |
| 289 | unlink(asecFileName); |
| 290 | return -1; |
| 291 | } |
| 292 | cleanupDm = true; |
| 293 | } else { |
San Mehat | fcf24fe | 2010-03-03 12:37:32 -0800 | [diff] [blame] | 294 | sb.c_cipher = ASEC_SB_C_CIPHER_NONE; |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 295 | strcpy(dmDevice, loopDevice); |
| 296 | } |
| 297 | |
San Mehat | fcf24fe | 2010-03-03 12:37:32 -0800 | [diff] [blame] | 298 | /* |
| 299 | * Drop down the superblock at the end of the file |
| 300 | */ |
| 301 | |
| 302 | int sbfd = open(loopDevice, O_RDWR); |
| 303 | if (sbfd < 0) { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 304 | SLOGE("Failed to open new DM device for superblock write (%s)", strerror(errno)); |
San Mehat | fcf24fe | 2010-03-03 12:37:32 -0800 | [diff] [blame] | 305 | if (cleanupDm) { |
San Mehat | d9a4e35 | 2010-03-12 13:32:47 -0800 | [diff] [blame] | 306 | Devmapper::destroy(idHash); |
San Mehat | fcf24fe | 2010-03-03 12:37:32 -0800 | [diff] [blame] | 307 | } |
| 308 | Loop::destroyByDevice(loopDevice); |
| 309 | unlink(asecFileName); |
| 310 | return -1; |
| 311 | } |
| 312 | |
| 313 | if (lseek(sbfd, (numImgSectors * 512), SEEK_SET) < 0) { |
| 314 | close(sbfd); |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 315 | SLOGE("Failed to lseek for superblock (%s)", strerror(errno)); |
San Mehat | fcf24fe | 2010-03-03 12:37:32 -0800 | [diff] [blame] | 316 | if (cleanupDm) { |
San Mehat | d9a4e35 | 2010-03-12 13:32:47 -0800 | [diff] [blame] | 317 | Devmapper::destroy(idHash); |
San Mehat | fcf24fe | 2010-03-03 12:37:32 -0800 | [diff] [blame] | 318 | } |
| 319 | Loop::destroyByDevice(loopDevice); |
| 320 | unlink(asecFileName); |
| 321 | return -1; |
| 322 | } |
| 323 | |
| 324 | if (write(sbfd, &sb, sizeof(sb)) != sizeof(sb)) { |
| 325 | close(sbfd); |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 326 | SLOGE("Failed to write superblock (%s)", strerror(errno)); |
San Mehat | fcf24fe | 2010-03-03 12:37:32 -0800 | [diff] [blame] | 327 | if (cleanupDm) { |
San Mehat | d9a4e35 | 2010-03-12 13:32:47 -0800 | [diff] [blame] | 328 | Devmapper::destroy(idHash); |
San Mehat | fcf24fe | 2010-03-03 12:37:32 -0800 | [diff] [blame] | 329 | } |
| 330 | Loop::destroyByDevice(loopDevice); |
| 331 | unlink(asecFileName); |
| 332 | return -1; |
| 333 | } |
| 334 | close(sbfd); |
| 335 | |
San Mehat | a1091cb | 2010-02-28 20:17:20 -0800 | [diff] [blame] | 336 | if (strcmp(fstype, "none")) { |
| 337 | if (strcmp(fstype, "fat")) { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 338 | SLOGW("Unknown fstype '%s' specified for container", fstype); |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 339 | } |
San Mehat | a19b250 | 2010-01-06 10:33:53 -0800 | [diff] [blame] | 340 | |
San Mehat | fcf24fe | 2010-03-03 12:37:32 -0800 | [diff] [blame] | 341 | if (Fat::format(dmDevice, numImgSectors)) { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 342 | SLOGE("ASEC FAT format failed (%s)", strerror(errno)); |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 343 | if (cleanupDm) { |
San Mehat | d9a4e35 | 2010-03-12 13:32:47 -0800 | [diff] [blame] | 344 | Devmapper::destroy(idHash); |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 345 | } |
San Mehat | eb13a90 | 2010-01-07 12:12:50 -0800 | [diff] [blame] | 346 | Loop::destroyByDevice(loopDevice); |
| 347 | unlink(asecFileName); |
| 348 | return -1; |
| 349 | } |
San Mehat | a1091cb | 2010-02-28 20:17:20 -0800 | [diff] [blame] | 350 | char mountPoint[255]; |
San Mehat | a19b250 | 2010-01-06 10:33:53 -0800 | [diff] [blame] | 351 | |
San Mehat | a1091cb | 2010-02-28 20:17:20 -0800 | [diff] [blame] | 352 | snprintf(mountPoint, sizeof(mountPoint), "%s/%s", Volume::ASECDIR, id); |
| 353 | if (mkdir(mountPoint, 0777)) { |
| 354 | if (errno != EEXIST) { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 355 | SLOGE("Mountpoint creation failed (%s)", strerror(errno)); |
San Mehat | a1091cb | 2010-02-28 20:17:20 -0800 | [diff] [blame] | 356 | if (cleanupDm) { |
San Mehat | d9a4e35 | 2010-03-12 13:32:47 -0800 | [diff] [blame] | 357 | Devmapper::destroy(idHash); |
San Mehat | a1091cb | 2010-02-28 20:17:20 -0800 | [diff] [blame] | 358 | } |
| 359 | Loop::destroyByDevice(loopDevice); |
| 360 | unlink(asecFileName); |
| 361 | return -1; |
| 362 | } |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 363 | } |
San Mehat | a1091cb | 2010-02-28 20:17:20 -0800 | [diff] [blame] | 364 | |
| 365 | if (Fat::doMount(dmDevice, mountPoint, false, false, ownerUid, |
| 366 | 0, 0000, false)) { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 367 | SLOGE("ASEC FAT mount failed (%s)", strerror(errno)); |
San Mehat | a1091cb | 2010-02-28 20:17:20 -0800 | [diff] [blame] | 368 | if (cleanupDm) { |
San Mehat | d9a4e35 | 2010-03-12 13:32:47 -0800 | [diff] [blame] | 369 | Devmapper::destroy(idHash); |
San Mehat | a1091cb | 2010-02-28 20:17:20 -0800 | [diff] [blame] | 370 | } |
| 371 | Loop::destroyByDevice(loopDevice); |
| 372 | unlink(asecFileName); |
| 373 | return -1; |
| 374 | } |
| 375 | } else { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 376 | SLOGI("Created raw secure container %s (no filesystem)", id); |
San Mehat | a19b250 | 2010-01-06 10:33:53 -0800 | [diff] [blame] | 377 | } |
San Mehat | 8870516 | 2010-01-15 09:26:28 -0800 | [diff] [blame] | 378 | |
| 379 | mActiveContainers->push_back(strdup(id)); |
San Mehat | a19b250 | 2010-01-06 10:33:53 -0800 | [diff] [blame] | 380 | return 0; |
| 381 | } |
| 382 | |
| 383 | int VolumeManager::finalizeAsec(const char *id) { |
| 384 | char asecFileName[255]; |
| 385 | char loopDevice[255]; |
| 386 | char mountPoint[255]; |
| 387 | |
San Mehat | 3bb6020 | 2010-02-19 18:14:36 -0800 | [diff] [blame] | 388 | snprintf(asecFileName, sizeof(asecFileName), "%s/%s.asec", Volume::SEC_ASECDIR, id); |
San Mehat | a19b250 | 2010-01-06 10:33:53 -0800 | [diff] [blame] | 389 | |
San Mehat | d9a4e35 | 2010-03-12 13:32:47 -0800 | [diff] [blame] | 390 | char idHash[33]; |
| 391 | if (!asecHash(id, idHash, sizeof(idHash))) { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 392 | SLOGE("Hash of '%s' failed (%s)", id, strerror(errno)); |
San Mehat | d9a4e35 | 2010-03-12 13:32:47 -0800 | [diff] [blame] | 393 | return -1; |
| 394 | } |
| 395 | |
| 396 | if (Loop::lookupActive(idHash, loopDevice, sizeof(loopDevice))) { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 397 | SLOGE("Unable to finalize %s (%s)", id, strerror(errno)); |
San Mehat | a19b250 | 2010-01-06 10:33:53 -0800 | [diff] [blame] | 398 | return -1; |
| 399 | } |
| 400 | |
San Mehat | 3bb6020 | 2010-02-19 18:14:36 -0800 | [diff] [blame] | 401 | snprintf(mountPoint, sizeof(mountPoint), "%s/%s", Volume::ASECDIR, id); |
San Mehat | fff0b47 | 2010-01-06 19:19:46 -0800 | [diff] [blame] | 402 | // XXX: |
| 403 | if (Fat::doMount(loopDevice, mountPoint, true, true, 0, 0, 0227, false)) { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 404 | SLOGE("ASEC finalize mount failed (%s)", strerror(errno)); |
San Mehat | a19b250 | 2010-01-06 10:33:53 -0800 | [diff] [blame] | 405 | return -1; |
| 406 | } |
| 407 | |
San Mehat | d9a4e35 | 2010-03-12 13:32:47 -0800 | [diff] [blame] | 408 | if (mDebug) { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 409 | SLOGD("ASEC %s finalized", id); |
San Mehat | d9a4e35 | 2010-03-12 13:32:47 -0800 | [diff] [blame] | 410 | } |
San Mehat | a19b250 | 2010-01-06 10:33:53 -0800 | [diff] [blame] | 411 | return 0; |
| 412 | } |
| 413 | |
San Mehat | 048b080 | 2010-01-23 08:17:06 -0800 | [diff] [blame] | 414 | int VolumeManager::renameAsec(const char *id1, const char *id2) { |
| 415 | char *asecFilename1; |
| 416 | char *asecFilename2; |
| 417 | char mountPoint[255]; |
| 418 | |
San Mehat | 3bb6020 | 2010-02-19 18:14:36 -0800 | [diff] [blame] | 419 | asprintf(&asecFilename1, "%s/%s.asec", Volume::SEC_ASECDIR, id1); |
| 420 | asprintf(&asecFilename2, "%s/%s.asec", Volume::SEC_ASECDIR, id2); |
San Mehat | 048b080 | 2010-01-23 08:17:06 -0800 | [diff] [blame] | 421 | |
San Mehat | 3bb6020 | 2010-02-19 18:14:36 -0800 | [diff] [blame] | 422 | snprintf(mountPoint, sizeof(mountPoint), "%s/%s", Volume::ASECDIR, id1); |
San Mehat | 048b080 | 2010-01-23 08:17:06 -0800 | [diff] [blame] | 423 | if (isMountpointMounted(mountPoint)) { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 424 | SLOGW("Rename attempt when src mounted"); |
San Mehat | 048b080 | 2010-01-23 08:17:06 -0800 | [diff] [blame] | 425 | errno = EBUSY; |
| 426 | goto out_err; |
| 427 | } |
| 428 | |
San Mehat | 96956ed | 2010-02-24 08:42:51 -0800 | [diff] [blame] | 429 | snprintf(mountPoint, sizeof(mountPoint), "%s/%s", Volume::ASECDIR, id2); |
| 430 | if (isMountpointMounted(mountPoint)) { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 431 | SLOGW("Rename attempt when dst mounted"); |
San Mehat | 96956ed | 2010-02-24 08:42:51 -0800 | [diff] [blame] | 432 | errno = EBUSY; |
| 433 | goto out_err; |
| 434 | } |
| 435 | |
San Mehat | 048b080 | 2010-01-23 08:17:06 -0800 | [diff] [blame] | 436 | if (!access(asecFilename2, F_OK)) { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 437 | SLOGE("Rename attempt when dst exists"); |
San Mehat | 048b080 | 2010-01-23 08:17:06 -0800 | [diff] [blame] | 438 | errno = EADDRINUSE; |
| 439 | goto out_err; |
| 440 | } |
| 441 | |
| 442 | if (rename(asecFilename1, asecFilename2)) { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 443 | SLOGE("Rename of '%s' to '%s' failed (%s)", asecFilename1, asecFilename2, strerror(errno)); |
San Mehat | 048b080 | 2010-01-23 08:17:06 -0800 | [diff] [blame] | 444 | goto out_err; |
| 445 | } |
| 446 | |
| 447 | free(asecFilename1); |
| 448 | free(asecFilename2); |
| 449 | return 0; |
| 450 | |
| 451 | out_err: |
| 452 | free(asecFilename1); |
| 453 | free(asecFilename2); |
| 454 | return -1; |
| 455 | } |
| 456 | |
San Mehat | 4ba8948 | 2010-02-18 09:00:18 -0800 | [diff] [blame] | 457 | #define ASEC_UNMOUNT_RETRIES 5 |
| 458 | int VolumeManager::unmountAsec(const char *id, bool force) { |
San Mehat | a19b250 | 2010-01-06 10:33:53 -0800 | [diff] [blame] | 459 | char asecFileName[255]; |
| 460 | char mountPoint[255]; |
| 461 | |
San Mehat | 3bb6020 | 2010-02-19 18:14:36 -0800 | [diff] [blame] | 462 | snprintf(asecFileName, sizeof(asecFileName), "%s/%s.asec", Volume::SEC_ASECDIR, id); |
| 463 | snprintf(mountPoint, sizeof(mountPoint), "%s/%s", Volume::ASECDIR, id); |
San Mehat | a19b250 | 2010-01-06 10:33:53 -0800 | [diff] [blame] | 464 | |
San Mehat | d9a4e35 | 2010-03-12 13:32:47 -0800 | [diff] [blame] | 465 | char idHash[33]; |
| 466 | if (!asecHash(id, idHash, sizeof(idHash))) { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 467 | SLOGE("Hash of '%s' failed (%s)", id, strerror(errno)); |
San Mehat | d9a4e35 | 2010-03-12 13:32:47 -0800 | [diff] [blame] | 468 | return -1; |
| 469 | } |
| 470 | |
San Mehat | 0586d54 | 2010-01-12 15:38:59 -0800 | [diff] [blame] | 471 | if (!isMountpointMounted(mountPoint)) { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 472 | SLOGE("Unmount request for ASEC %s when not mounted", id); |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 473 | errno = EINVAL; |
| 474 | return -1; |
| 475 | } |
San Mehat | 2396993 | 2010-01-09 07:08:06 -0800 | [diff] [blame] | 476 | |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 477 | int i, rc; |
San Mehat | 8c940ef | 2010-02-13 14:19:53 -0800 | [diff] [blame] | 478 | for (i = 1; i <= ASEC_UNMOUNT_RETRIES; i++) { |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 479 | rc = umount(mountPoint); |
| 480 | if (!rc) { |
| 481 | break; |
San Mehat | a19b250 | 2010-01-06 10:33:53 -0800 | [diff] [blame] | 482 | } |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 483 | if (rc && (errno == EINVAL || errno == ENOENT)) { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 484 | SLOGI("Secure container %s unmounted OK", id); |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 485 | rc = 0; |
| 486 | break; |
San Mehat | a19b250 | 2010-01-06 10:33:53 -0800 | [diff] [blame] | 487 | } |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 488 | SLOGW("ASEC %s unmount attempt %d failed (%s)", |
San Mehat | 8c940ef | 2010-02-13 14:19:53 -0800 | [diff] [blame] | 489 | id, i, strerror(errno)); |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 490 | |
San Mehat | 4ba8948 | 2010-02-18 09:00:18 -0800 | [diff] [blame] | 491 | int action = 0; // default is to just complain |
| 492 | |
| 493 | if (force) { |
| 494 | if (i > (ASEC_UNMOUNT_RETRIES - 2)) |
| 495 | action = 2; // SIGKILL |
| 496 | else if (i > (ASEC_UNMOUNT_RETRIES - 3)) |
| 497 | action = 1; // SIGHUP |
| 498 | } |
San Mehat | 8c940ef | 2010-02-13 14:19:53 -0800 | [diff] [blame] | 499 | |
San Mehat | 586536c | 2010-02-16 17:12:00 -0800 | [diff] [blame] | 500 | Process::killProcessesWithOpenFiles(mountPoint, action); |
San Mehat | 8c940ef | 2010-02-13 14:19:53 -0800 | [diff] [blame] | 501 | usleep(1000 * 1000); |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 502 | } |
| 503 | |
| 504 | if (rc) { |
San Mehat | 4ba8948 | 2010-02-18 09:00:18 -0800 | [diff] [blame] | 505 | errno = EBUSY; |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 506 | SLOGE("Failed to unmount container %s (%s)", id, strerror(errno)); |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 507 | return -1; |
| 508 | } |
| 509 | |
San Mehat | 12f4b89 | 2010-02-24 11:43:22 -0800 | [diff] [blame] | 510 | int retries = 10; |
| 511 | |
| 512 | while(retries--) { |
| 513 | if (!rmdir(mountPoint)) { |
| 514 | break; |
| 515 | } |
| 516 | |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 517 | SLOGW("Failed to rmdir %s (%s)", mountPoint, strerror(errno)); |
San Mehat | 12f4b89 | 2010-02-24 11:43:22 -0800 | [diff] [blame] | 518 | usleep(1000 * 1000); |
| 519 | } |
| 520 | |
| 521 | if (!retries) { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 522 | SLOGE("Timed out trying to rmdir %s (%s)", mountPoint, strerror(errno)); |
San Mehat | f5c6198 | 2010-02-03 11:04:46 -0800 | [diff] [blame] | 523 | } |
San Mehat | 8870516 | 2010-01-15 09:26:28 -0800 | [diff] [blame] | 524 | |
San Mehat | d9a4e35 | 2010-03-12 13:32:47 -0800 | [diff] [blame] | 525 | if (Devmapper::destroy(idHash) && errno != ENXIO) { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 526 | SLOGE("Failed to destroy devmapper instance (%s)", strerror(errno)); |
San Mehat | a19b250 | 2010-01-06 10:33:53 -0800 | [diff] [blame] | 527 | } |
| 528 | |
| 529 | char loopDevice[255]; |
San Mehat | d9a4e35 | 2010-03-12 13:32:47 -0800 | [diff] [blame] | 530 | if (!Loop::lookupActive(idHash, loopDevice, sizeof(loopDevice))) { |
San Mehat | a19b250 | 2010-01-06 10:33:53 -0800 | [diff] [blame] | 531 | Loop::destroyByDevice(loopDevice); |
San Mehat | d9a4e35 | 2010-03-12 13:32:47 -0800 | [diff] [blame] | 532 | } else { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 533 | SLOGW("Failed to find loop device for {%s} (%s)", asecFileName, strerror(errno)); |
San Mehat | a19b250 | 2010-01-06 10:33:53 -0800 | [diff] [blame] | 534 | } |
San Mehat | 8870516 | 2010-01-15 09:26:28 -0800 | [diff] [blame] | 535 | |
| 536 | AsecIdCollection::iterator it; |
| 537 | for (it = mActiveContainers->begin(); it != mActiveContainers->end(); ++it) { |
| 538 | if (!strcmp(*it, id)) { |
| 539 | free(*it); |
| 540 | mActiveContainers->erase(it); |
| 541 | break; |
| 542 | } |
| 543 | } |
| 544 | if (it == mActiveContainers->end()) { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 545 | SLOGW("mActiveContainers is inconsistent!"); |
San Mehat | 8870516 | 2010-01-15 09:26:28 -0800 | [diff] [blame] | 546 | } |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 547 | return 0; |
| 548 | } |
| 549 | |
San Mehat | 4ba8948 | 2010-02-18 09:00:18 -0800 | [diff] [blame] | 550 | int VolumeManager::destroyAsec(const char *id, bool force) { |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 551 | char asecFileName[255]; |
| 552 | char mountPoint[255]; |
| 553 | |
San Mehat | 3bb6020 | 2010-02-19 18:14:36 -0800 | [diff] [blame] | 554 | snprintf(asecFileName, sizeof(asecFileName), "%s/%s.asec", Volume::SEC_ASECDIR, id); |
San Mehat | 55013f7 | 2010-02-24 12:12:34 -0800 | [diff] [blame] | 555 | snprintf(mountPoint, sizeof(mountPoint), "%s/%s", Volume::ASECDIR, id); |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 556 | |
San Mehat | 0586d54 | 2010-01-12 15:38:59 -0800 | [diff] [blame] | 557 | if (isMountpointMounted(mountPoint)) { |
San Mehat | d9a4e35 | 2010-03-12 13:32:47 -0800 | [diff] [blame] | 558 | if (mDebug) { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 559 | SLOGD("Unmounting container before destroy"); |
San Mehat | d9a4e35 | 2010-03-12 13:32:47 -0800 | [diff] [blame] | 560 | } |
San Mehat | 4ba8948 | 2010-02-18 09:00:18 -0800 | [diff] [blame] | 561 | if (unmountAsec(id, force)) { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 562 | SLOGE("Failed to unmount asec %s for destroy (%s)", id, strerror(errno)); |
San Mehat | 0586d54 | 2010-01-12 15:38:59 -0800 | [diff] [blame] | 563 | return -1; |
| 564 | } |
| 565 | } |
San Mehat | a19b250 | 2010-01-06 10:33:53 -0800 | [diff] [blame] | 566 | |
San Mehat | 0586d54 | 2010-01-12 15:38:59 -0800 | [diff] [blame] | 567 | if (unlink(asecFileName)) { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 568 | SLOGE("Failed to unlink asec '%s' (%s)", asecFileName, strerror(errno)); |
San Mehat | 0586d54 | 2010-01-12 15:38:59 -0800 | [diff] [blame] | 569 | return -1; |
| 570 | } |
San Mehat | a19b250 | 2010-01-06 10:33:53 -0800 | [diff] [blame] | 571 | |
San Mehat | d9a4e35 | 2010-03-12 13:32:47 -0800 | [diff] [blame] | 572 | if (mDebug) { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 573 | SLOGD("ASEC %s destroyed", id); |
San Mehat | d9a4e35 | 2010-03-12 13:32:47 -0800 | [diff] [blame] | 574 | } |
San Mehat | a19b250 | 2010-01-06 10:33:53 -0800 | [diff] [blame] | 575 | return 0; |
| 576 | } |
| 577 | |
| 578 | int VolumeManager::mountAsec(const char *id, const char *key, int ownerUid) { |
| 579 | char asecFileName[255]; |
| 580 | char mountPoint[255]; |
| 581 | |
San Mehat | 3bb6020 | 2010-02-19 18:14:36 -0800 | [diff] [blame] | 582 | snprintf(asecFileName, sizeof(asecFileName), "%s/%s.asec", Volume::SEC_ASECDIR, id); |
| 583 | snprintf(mountPoint, sizeof(mountPoint), "%s/%s", Volume::ASECDIR, id); |
San Mehat | a19b250 | 2010-01-06 10:33:53 -0800 | [diff] [blame] | 584 | |
| 585 | if (isMountpointMounted(mountPoint)) { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 586 | SLOGE("ASEC %s already mounted", id); |
San Mehat | a19b250 | 2010-01-06 10:33:53 -0800 | [diff] [blame] | 587 | errno = EBUSY; |
| 588 | return -1; |
| 589 | } |
| 590 | |
San Mehat | d9a4e35 | 2010-03-12 13:32:47 -0800 | [diff] [blame] | 591 | char idHash[33]; |
| 592 | if (!asecHash(id, idHash, sizeof(idHash))) { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 593 | SLOGE("Hash of '%s' failed (%s)", id, strerror(errno)); |
San Mehat | d9a4e35 | 2010-03-12 13:32:47 -0800 | [diff] [blame] | 594 | return -1; |
| 595 | } |
Kenny Root | 7b18a7b | 2010-03-15 13:13:41 -0700 | [diff] [blame] | 596 | |
San Mehat | a19b250 | 2010-01-06 10:33:53 -0800 | [diff] [blame] | 597 | char loopDevice[255]; |
San Mehat | d9a4e35 | 2010-03-12 13:32:47 -0800 | [diff] [blame] | 598 | if (Loop::lookupActive(idHash, loopDevice, sizeof(loopDevice))) { |
| 599 | if (Loop::create(idHash, asecFileName, loopDevice, sizeof(loopDevice))) { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 600 | SLOGE("ASEC loop device creation failed (%s)", strerror(errno)); |
San Mehat | a19b250 | 2010-01-06 10:33:53 -0800 | [diff] [blame] | 601 | return -1; |
| 602 | } |
San Mehat | d9a4e35 | 2010-03-12 13:32:47 -0800 | [diff] [blame] | 603 | if (mDebug) { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 604 | SLOGD("New loop device created at %s", loopDevice); |
San Mehat | d9a4e35 | 2010-03-12 13:32:47 -0800 | [diff] [blame] | 605 | } |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 606 | } else { |
San Mehat | d9a4e35 | 2010-03-12 13:32:47 -0800 | [diff] [blame] | 607 | if (mDebug) { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 608 | SLOGD("Found active loopback for %s at %s", asecFileName, loopDevice); |
San Mehat | d9a4e35 | 2010-03-12 13:32:47 -0800 | [diff] [blame] | 609 | } |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 610 | } |
| 611 | |
| 612 | char dmDevice[255]; |
| 613 | bool cleanupDm = false; |
San Mehat | fcf24fe | 2010-03-03 12:37:32 -0800 | [diff] [blame] | 614 | int fd; |
| 615 | unsigned int nr_sec = 0; |
| 616 | |
| 617 | if ((fd = open(loopDevice, O_RDWR)) < 0) { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 618 | SLOGE("Failed to open loopdevice (%s)", strerror(errno)); |
San Mehat | fcf24fe | 2010-03-03 12:37:32 -0800 | [diff] [blame] | 619 | Loop::destroyByDevice(loopDevice); |
| 620 | return -1; |
| 621 | } |
| 622 | |
| 623 | if (ioctl(fd, BLKGETSIZE, &nr_sec)) { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 624 | SLOGE("Failed to get loop size (%s)", strerror(errno)); |
San Mehat | fcf24fe | 2010-03-03 12:37:32 -0800 | [diff] [blame] | 625 | Loop::destroyByDevice(loopDevice); |
| 626 | close(fd); |
| 627 | return -1; |
| 628 | } |
| 629 | |
| 630 | /* |
| 631 | * Validate superblock |
| 632 | */ |
| 633 | struct asec_superblock sb; |
| 634 | memset(&sb, 0, sizeof(sb)); |
| 635 | if (lseek(fd, ((nr_sec-1) * 512), SEEK_SET) < 0) { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 636 | SLOGE("lseek failed (%s)", strerror(errno)); |
San Mehat | fcf24fe | 2010-03-03 12:37:32 -0800 | [diff] [blame] | 637 | close(fd); |
| 638 | Loop::destroyByDevice(loopDevice); |
| 639 | return -1; |
| 640 | } |
| 641 | if (read(fd, &sb, sizeof(sb)) != sizeof(sb)) { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 642 | SLOGE("superblock read failed (%s)", strerror(errno)); |
San Mehat | fcf24fe | 2010-03-03 12:37:32 -0800 | [diff] [blame] | 643 | close(fd); |
| 644 | Loop::destroyByDevice(loopDevice); |
| 645 | return -1; |
| 646 | } |
| 647 | |
| 648 | close(fd); |
| 649 | |
San Mehat | d9a4e35 | 2010-03-12 13:32:47 -0800 | [diff] [blame] | 650 | if (mDebug) { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 651 | SLOGD("Container sb magic/ver (%.8x/%.2x)", sb.magic, sb.ver); |
San Mehat | d9a4e35 | 2010-03-12 13:32:47 -0800 | [diff] [blame] | 652 | } |
San Mehat | fcf24fe | 2010-03-03 12:37:32 -0800 | [diff] [blame] | 653 | if (sb.magic != ASEC_SB_MAGIC || sb.ver != ASEC_SB_VER) { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 654 | SLOGE("Bad container magic/version (%.8x/%.2x)", sb.magic, sb.ver); |
San Mehat | fcf24fe | 2010-03-03 12:37:32 -0800 | [diff] [blame] | 655 | Loop::destroyByDevice(loopDevice); |
| 656 | errno = EMEDIUMTYPE; |
| 657 | return -1; |
| 658 | } |
| 659 | nr_sec--; // We don't want the devmapping to extend onto our superblock |
| 660 | |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 661 | if (strcmp(key, "none")) { |
San Mehat | d9a4e35 | 2010-03-12 13:32:47 -0800 | [diff] [blame] | 662 | if (Devmapper::lookupActive(idHash, dmDevice, sizeof(dmDevice))) { |
| 663 | if (Devmapper::create(idHash, loopDevice, key, nr_sec, |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 664 | dmDevice, sizeof(dmDevice))) { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 665 | SLOGE("ASEC device mapping failed (%s)", strerror(errno)); |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 666 | Loop::destroyByDevice(loopDevice); |
| 667 | return -1; |
| 668 | } |
San Mehat | d9a4e35 | 2010-03-12 13:32:47 -0800 | [diff] [blame] | 669 | if (mDebug) { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 670 | SLOGD("New devmapper instance created at %s", dmDevice); |
San Mehat | d9a4e35 | 2010-03-12 13:32:47 -0800 | [diff] [blame] | 671 | } |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 672 | } else { |
San Mehat | d9a4e35 | 2010-03-12 13:32:47 -0800 | [diff] [blame] | 673 | if (mDebug) { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 674 | SLOGD("Found active devmapper for %s at %s", asecFileName, dmDevice); |
San Mehat | d9a4e35 | 2010-03-12 13:32:47 -0800 | [diff] [blame] | 675 | } |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 676 | } |
| 677 | cleanupDm = true; |
| 678 | } else { |
| 679 | strcpy(dmDevice, loopDevice); |
San Mehat | a19b250 | 2010-01-06 10:33:53 -0800 | [diff] [blame] | 680 | } |
| 681 | |
| 682 | if (mkdir(mountPoint, 0777)) { |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 683 | if (errno != EEXIST) { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 684 | SLOGE("Mountpoint creation failed (%s)", strerror(errno)); |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 685 | if (cleanupDm) { |
San Mehat | d9a4e35 | 2010-03-12 13:32:47 -0800 | [diff] [blame] | 686 | Devmapper::destroy(idHash); |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 687 | } |
| 688 | Loop::destroyByDevice(loopDevice); |
| 689 | return -1; |
| 690 | } |
San Mehat | a19b250 | 2010-01-06 10:33:53 -0800 | [diff] [blame] | 691 | } |
| 692 | |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 693 | if (Fat::doMount(dmDevice, mountPoint, true, false, ownerUid, 0, |
San Mehat | cff5ec3 | 2010-01-08 12:31:44 -0800 | [diff] [blame] | 694 | 0222, false)) { |
| 695 | // 0227, false)) { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 696 | SLOGE("ASEC mount failed (%s)", strerror(errno)); |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 697 | if (cleanupDm) { |
San Mehat | d9a4e35 | 2010-03-12 13:32:47 -0800 | [diff] [blame] | 698 | Devmapper::destroy(idHash); |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 699 | } |
| 700 | Loop::destroyByDevice(loopDevice); |
San Mehat | a19b250 | 2010-01-06 10:33:53 -0800 | [diff] [blame] | 701 | return -1; |
| 702 | } |
| 703 | |
San Mehat | 8870516 | 2010-01-15 09:26:28 -0800 | [diff] [blame] | 704 | mActiveContainers->push_back(strdup(id)); |
San Mehat | d9a4e35 | 2010-03-12 13:32:47 -0800 | [diff] [blame] | 705 | if (mDebug) { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 706 | SLOGD("ASEC %s mounted", id); |
San Mehat | d9a4e35 | 2010-03-12 13:32:47 -0800 | [diff] [blame] | 707 | } |
San Mehat | a19b250 | 2010-01-06 10:33:53 -0800 | [diff] [blame] | 708 | return 0; |
| 709 | } |
| 710 | |
San Mehat | 49e2bce | 2009-10-12 16:29:01 -0700 | [diff] [blame] | 711 | int VolumeManager::mountVolume(const char *label) { |
| 712 | Volume *v = lookupVolume(label); |
| 713 | |
| 714 | if (!v) { |
| 715 | errno = ENOENT; |
| 716 | return -1; |
| 717 | } |
| 718 | |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 719 | return v->mountVol(); |
| 720 | } |
| 721 | |
| 722 | int VolumeManager::shareAvailable(const char *method, bool *avail) { |
| 723 | |
| 724 | if (strcmp(method, "ums")) { |
| 725 | errno = ENOSYS; |
| 726 | return -1; |
| 727 | } |
| 728 | |
| 729 | if (mUsbMassStorageConnected) |
| 730 | *avail = true; |
| 731 | else |
| 732 | *avail = false; |
| 733 | return 0; |
| 734 | } |
| 735 | |
San Mehat | eba65e9 | 2010-01-29 05:15:16 -0800 | [diff] [blame] | 736 | int VolumeManager::shareEnabled(const char *label, const char *method, bool *enabled) { |
| 737 | Volume *v = lookupVolume(label); |
| 738 | |
| 739 | if (!v) { |
| 740 | errno = ENOENT; |
| 741 | return -1; |
| 742 | } |
| 743 | |
| 744 | if (strcmp(method, "ums")) { |
| 745 | errno = ENOSYS; |
| 746 | return -1; |
| 747 | } |
| 748 | |
| 749 | if (v->getState() != Volume::State_Shared) { |
San Mehat | eba65e9 | 2010-01-29 05:15:16 -0800 | [diff] [blame] | 750 | *enabled = false; |
San Mehat | b9aed74 | 2010-02-04 15:07:01 -0800 | [diff] [blame] | 751 | } else { |
| 752 | *enabled = true; |
San Mehat | eba65e9 | 2010-01-29 05:15:16 -0800 | [diff] [blame] | 753 | } |
| 754 | return 0; |
| 755 | } |
| 756 | |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 757 | int VolumeManager::simulate(const char *cmd, const char *arg) { |
| 758 | |
| 759 | if (!strcmp(cmd, "ums")) { |
| 760 | if (!strcmp(arg, "connect")) { |
| 761 | notifyUmsConnected(true); |
| 762 | } else if (!strcmp(arg, "disconnect")) { |
| 763 | notifyUmsConnected(false); |
| 764 | } else { |
| 765 | errno = EINVAL; |
| 766 | return -1; |
| 767 | } |
| 768 | } else { |
| 769 | errno = EINVAL; |
| 770 | return -1; |
| 771 | } |
| 772 | return 0; |
| 773 | } |
| 774 | |
| 775 | int VolumeManager::shareVolume(const char *label, const char *method) { |
| 776 | Volume *v = lookupVolume(label); |
| 777 | |
| 778 | if (!v) { |
| 779 | errno = ENOENT; |
| 780 | return -1; |
| 781 | } |
| 782 | |
| 783 | /* |
| 784 | * Eventually, we'll want to support additional share back-ends, |
| 785 | * some of which may work while the media is mounted. For now, |
| 786 | * we just support UMS |
| 787 | */ |
| 788 | if (strcmp(method, "ums")) { |
| 789 | errno = ENOSYS; |
| 790 | return -1; |
| 791 | } |
| 792 | |
| 793 | if (v->getState() == Volume::State_NoMedia) { |
| 794 | errno = ENODEV; |
| 795 | return -1; |
| 796 | } |
| 797 | |
San Mehat | 49e2bce | 2009-10-12 16:29:01 -0700 | [diff] [blame] | 798 | if (v->getState() != Volume::State_Idle) { |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 799 | // You need to unmount manually befoe sharing |
San Mehat | 49e2bce | 2009-10-12 16:29:01 -0700 | [diff] [blame] | 800 | errno = EBUSY; |
| 801 | return -1; |
| 802 | } |
| 803 | |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 804 | dev_t d = v->getDiskDevice(); |
| 805 | if ((MAJOR(d) == 0) && (MINOR(d) == 0)) { |
| 806 | // This volume does not support raw disk access |
| 807 | errno = EINVAL; |
| 808 | return -1; |
| 809 | } |
| 810 | |
| 811 | int fd; |
| 812 | char nodepath[255]; |
| 813 | snprintf(nodepath, |
| 814 | sizeof(nodepath), "/dev/block/vold/%d:%d", |
| 815 | MAJOR(d), MINOR(d)); |
| 816 | |
San Mehat | 0cde53c | 2009-12-22 08:32:33 -0800 | [diff] [blame] | 817 | if ((fd = open("/sys/devices/platform/usb_mass_storage/lun0/file", |
| 818 | O_WRONLY)) < 0) { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 819 | SLOGE("Unable to open ums lunfile (%s)", strerror(errno)); |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 820 | return -1; |
| 821 | } |
| 822 | |
| 823 | if (write(fd, nodepath, strlen(nodepath)) < 0) { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 824 | SLOGE("Unable to write to ums lunfile (%s)", strerror(errno)); |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 825 | close(fd); |
| 826 | return -1; |
| 827 | } |
| 828 | |
| 829 | close(fd); |
| 830 | v->handleVolumeShared(); |
| 831 | return 0; |
| 832 | } |
| 833 | |
| 834 | int VolumeManager::unshareVolume(const char *label, const char *method) { |
| 835 | Volume *v = lookupVolume(label); |
| 836 | |
| 837 | if (!v) { |
| 838 | errno = ENOENT; |
| 839 | return -1; |
| 840 | } |
| 841 | |
| 842 | if (strcmp(method, "ums")) { |
| 843 | errno = ENOSYS; |
| 844 | return -1; |
| 845 | } |
| 846 | |
| 847 | if (v->getState() != Volume::State_Shared) { |
| 848 | errno = EINVAL; |
| 849 | return -1; |
| 850 | } |
| 851 | |
| 852 | dev_t d = v->getDiskDevice(); |
| 853 | |
| 854 | int fd; |
| 855 | char nodepath[255]; |
| 856 | snprintf(nodepath, |
| 857 | sizeof(nodepath), "/dev/block/vold/%d:%d", |
| 858 | MAJOR(d), MINOR(d)); |
| 859 | |
San Mehat | 0cde53c | 2009-12-22 08:32:33 -0800 | [diff] [blame] | 860 | if ((fd = open("/sys/devices/platform/usb_mass_storage/lun0/file", O_WRONLY)) < 0) { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 861 | SLOGE("Unable to open ums lunfile (%s)", strerror(errno)); |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 862 | return -1; |
| 863 | } |
| 864 | |
| 865 | char ch = 0; |
| 866 | if (write(fd, &ch, 1) < 0) { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 867 | SLOGE("Unable to write to ums lunfile (%s)", strerror(errno)); |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 868 | close(fd); |
| 869 | return -1; |
| 870 | } |
| 871 | |
| 872 | close(fd); |
| 873 | v->handleVolumeUnshared(); |
| 874 | return 0; |
San Mehat | 49e2bce | 2009-10-12 16:29:01 -0700 | [diff] [blame] | 875 | } |
| 876 | |
San Mehat | 4ba8948 | 2010-02-18 09:00:18 -0800 | [diff] [blame] | 877 | int VolumeManager::unmountVolume(const char *label, bool force) { |
San Mehat | 49e2bce | 2009-10-12 16:29:01 -0700 | [diff] [blame] | 878 | Volume *v = lookupVolume(label); |
| 879 | |
| 880 | if (!v) { |
| 881 | errno = ENOENT; |
| 882 | return -1; |
| 883 | } |
| 884 | |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 885 | if (v->getState() == Volume::State_NoMedia) { |
| 886 | errno = ENODEV; |
| 887 | return -1; |
| 888 | } |
| 889 | |
San Mehat | 49e2bce | 2009-10-12 16:29:01 -0700 | [diff] [blame] | 890 | if (v->getState() != Volume::State_Mounted) { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 891 | SLOGW("Attempt to unmount volume which isn't mounted (%d)\n", |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 892 | v->getState()); |
San Mehat | 49e2bce | 2009-10-12 16:29:01 -0700 | [diff] [blame] | 893 | errno = EBUSY; |
| 894 | return -1; |
| 895 | } |
| 896 | |
San Mehat | 1a06eda | 2010-04-15 12:58:50 -0700 | [diff] [blame] | 897 | cleanupAsec(v, force); |
San Mehat | 8870516 | 2010-01-15 09:26:28 -0800 | [diff] [blame] | 898 | |
San Mehat | 4ba8948 | 2010-02-18 09:00:18 -0800 | [diff] [blame] | 899 | return v->unmountVol(force); |
San Mehat | 49e2bce | 2009-10-12 16:29:01 -0700 | [diff] [blame] | 900 | } |
| 901 | |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 902 | /* |
| 903 | * Looks up a volume by it's label or mount-point |
| 904 | */ |
San Mehat | 49e2bce | 2009-10-12 16:29:01 -0700 | [diff] [blame] | 905 | Volume *VolumeManager::lookupVolume(const char *label) { |
| 906 | VolumeCollection::iterator i; |
| 907 | |
| 908 | for (i = mVolumes->begin(); i != mVolumes->end(); ++i) { |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 909 | if (label[0] == '/') { |
| 910 | if (!strcmp(label, (*i)->getMountpoint())) |
| 911 | return (*i); |
| 912 | } else { |
| 913 | if (!strcmp(label, (*i)->getLabel())) |
| 914 | return (*i); |
| 915 | } |
San Mehat | 49e2bce | 2009-10-12 16:29:01 -0700 | [diff] [blame] | 916 | } |
| 917 | return NULL; |
| 918 | } |
San Mehat | a19b250 | 2010-01-06 10:33:53 -0800 | [diff] [blame] | 919 | |
| 920 | bool VolumeManager::isMountpointMounted(const char *mp) |
| 921 | { |
| 922 | char device[256]; |
| 923 | char mount_path[256]; |
| 924 | char rest[256]; |
| 925 | FILE *fp; |
| 926 | char line[1024]; |
| 927 | |
| 928 | if (!(fp = fopen("/proc/mounts", "r"))) { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 929 | SLOGE("Error opening /proc/mounts (%s)", strerror(errno)); |
San Mehat | a19b250 | 2010-01-06 10:33:53 -0800 | [diff] [blame] | 930 | return false; |
| 931 | } |
| 932 | |
| 933 | while(fgets(line, sizeof(line), fp)) { |
| 934 | line[strlen(line)-1] = '\0'; |
| 935 | sscanf(line, "%255s %255s %255s\n", device, mount_path, rest); |
| 936 | if (!strcmp(mount_path, mp)) { |
| 937 | fclose(fp); |
| 938 | return true; |
| 939 | } |
San Mehat | a19b250 | 2010-01-06 10:33:53 -0800 | [diff] [blame] | 940 | } |
| 941 | |
| 942 | fclose(fp); |
| 943 | return false; |
| 944 | } |
| 945 | |
San Mehat | 1a06eda | 2010-04-15 12:58:50 -0700 | [diff] [blame] | 946 | int VolumeManager::cleanupAsec(Volume *v, bool force) { |
| 947 | while(mActiveContainers->size()) { |
| 948 | AsecIdCollection::iterator it = mActiveContainers->begin(); |
| 949 | SLOGI("Unmounting ASEC %s (dependant on %s)", *it, v->getMountpoint()); |
| 950 | if (unmountAsec(*it, force)) { |
| 951 | SLOGE("Failed to unmount ASEC %s (%s)", *it, strerror(errno)); |
| 952 | return -1; |
| 953 | } |
| 954 | } |
| 955 | return 0; |
| 956 | } |
| 957 | |