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> |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 19 | #include <string.h> |
San Mehat | fd7f587 | 2009-10-12 11:32:47 -0700 | [diff] [blame] | 20 | #include <errno.h> |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 21 | |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 22 | #include <linux/kdev_t.h> |
| 23 | |
| 24 | #define LOG_TAG "DirectVolume" |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 25 | |
| 26 | #include <cutils/log.h> |
San Mehat | fd7f587 | 2009-10-12 11:32:47 -0700 | [diff] [blame] | 27 | #include <sysutils/NetlinkEvent.h> |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 28 | |
San Mehat | ae10b91 | 2009-10-12 14:57:05 -0700 | [diff] [blame] | 29 | #include "DirectVolume.h" |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 30 | #include "VolumeManager.h" |
| 31 | #include "ResponseCode.h" |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 32 | |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 33 | // #define PARTITION_DEBUG |
| 34 | |
| 35 | DirectVolume::DirectVolume(VolumeManager *vm, const char *label, |
| 36 | const char *mount_point, int partIdx) : |
| 37 | Volume(vm, label, mount_point) { |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 38 | mPartIdx = partIdx; |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 39 | |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 40 | mPaths = new PathCollection(); |
San Mehat | dd9b8e9 | 2009-10-21 11:06:52 -0700 | [diff] [blame] | 41 | for (int i = 0; i < MAX_PARTITIONS; i++) |
| 42 | mPartMinors[i] = -1; |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 43 | mPendingPartMap = 0; |
| 44 | mDiskMajor = -1; |
| 45 | mDiskMinor = -1; |
| 46 | mDiskNumParts = 0; |
| 47 | |
| 48 | setState(Volume::State_NoMedia); |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 49 | } |
| 50 | |
San Mehat | ae10b91 | 2009-10-12 14:57:05 -0700 | [diff] [blame] | 51 | DirectVolume::~DirectVolume() { |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 52 | PathCollection::iterator it; |
| 53 | |
| 54 | for (it = mPaths->begin(); it != mPaths->end(); ++it) |
| 55 | free(*it); |
| 56 | delete mPaths; |
| 57 | } |
| 58 | |
San Mehat | ae10b91 | 2009-10-12 14:57:05 -0700 | [diff] [blame] | 59 | int DirectVolume::addPath(const char *path) { |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 60 | mPaths->push_back(strdup(path)); |
| 61 | return 0; |
| 62 | } |
| 63 | |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 64 | dev_t DirectVolume::getDiskDevice() { |
| 65 | return MKDEV(mDiskMajor, mDiskMinor); |
| 66 | } |
| 67 | |
Mike Lockwood | 2dfe297 | 2010-09-17 18:50:51 -0400 | [diff] [blame] | 68 | dev_t DirectVolume::getShareDevice() { |
| 69 | if (mPartIdx != -1) { |
| 70 | return MKDEV(mDiskMajor, mPartIdx); |
| 71 | } else { |
| 72 | return MKDEV(mDiskMajor, mDiskMinor); |
| 73 | } |
| 74 | } |
| 75 | |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 76 | void DirectVolume::handleVolumeShared() { |
| 77 | setState(Volume::State_Shared); |
| 78 | } |
| 79 | |
| 80 | void DirectVolume::handleVolumeUnshared() { |
| 81 | setState(Volume::State_Idle); |
| 82 | } |
| 83 | |
San Mehat | ae10b91 | 2009-10-12 14:57:05 -0700 | [diff] [blame] | 84 | int DirectVolume::handleBlockEvent(NetlinkEvent *evt) { |
San Mehat | fd7f587 | 2009-10-12 11:32:47 -0700 | [diff] [blame] | 85 | const char *dp = evt->findParam("DEVPATH"); |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 86 | |
San Mehat | fd7f587 | 2009-10-12 11:32:47 -0700 | [diff] [blame] | 87 | PathCollection::iterator it; |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 88 | for (it = mPaths->begin(); it != mPaths->end(); ++it) { |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 89 | if (!strncmp(dp, *it, strlen(*it))) { |
San Mehat | fd7f587 | 2009-10-12 11:32:47 -0700 | [diff] [blame] | 90 | /* We can handle this disk */ |
| 91 | int action = evt->getAction(); |
| 92 | const char *devtype = evt->findParam("DEVTYPE"); |
| 93 | |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 94 | if (action == NetlinkEvent::NlActionAdd) { |
| 95 | int major = atoi(evt->findParam("MAJOR")); |
| 96 | int minor = atoi(evt->findParam("MINOR")); |
| 97 | char nodepath[255]; |
| 98 | |
| 99 | snprintf(nodepath, |
| 100 | sizeof(nodepath), "/dev/block/vold/%d:%d", |
| 101 | major, minor); |
| 102 | if (createDeviceNode(nodepath, major, minor)) { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 103 | SLOGE("Error making device node '%s' (%s)", nodepath, |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 104 | strerror(errno)); |
| 105 | } |
| 106 | if (!strcmp(devtype, "disk")) { |
San Mehat | fd7f587 | 2009-10-12 11:32:47 -0700 | [diff] [blame] | 107 | handleDiskAdded(dp, evt); |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 108 | } else { |
San Mehat | fd7f587 | 2009-10-12 11:32:47 -0700 | [diff] [blame] | 109 | handlePartitionAdded(dp, evt); |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 110 | } |
| 111 | } else if (action == NetlinkEvent::NlActionRemove) { |
| 112 | if (!strcmp(devtype, "disk")) { |
| 113 | handleDiskRemoved(dp, evt); |
| 114 | } else { |
San Mehat | fd7f587 | 2009-10-12 11:32:47 -0700 | [diff] [blame] | 115 | handlePartitionRemoved(dp, evt); |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 116 | } |
| 117 | } else if (action == NetlinkEvent::NlActionChange) { |
| 118 | if (!strcmp(devtype, "disk")) { |
| 119 | handleDiskChanged(dp, evt); |
| 120 | } else { |
| 121 | handlePartitionChanged(dp, evt); |
| 122 | } |
| 123 | } else { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 124 | SLOGW("Ignoring non add/remove/change event"); |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 125 | } |
San Mehat | fd7f587 | 2009-10-12 11:32:47 -0700 | [diff] [blame] | 126 | |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 127 | return 0; |
| 128 | } |
| 129 | } |
| 130 | errno = ENODEV; |
| 131 | return -1; |
| 132 | } |
San Mehat | fd7f587 | 2009-10-12 11:32:47 -0700 | [diff] [blame] | 133 | |
San Mehat | ae10b91 | 2009-10-12 14:57:05 -0700 | [diff] [blame] | 134 | void DirectVolume::handleDiskAdded(const char *devpath, NetlinkEvent *evt) { |
Kenny Root | da62e7c | 2010-03-24 20:18:00 -0700 | [diff] [blame] | 135 | mDiskMajor = atoi(evt->findParam("MAJOR")); |
| 136 | mDiskMinor = atoi(evt->findParam("MINOR")); |
San Mehat | 7b8f2db | 2010-01-04 14:03:36 -0800 | [diff] [blame] | 137 | |
| 138 | const char *tmp = evt->findParam("NPARTS"); |
| 139 | if (tmp) { |
| 140 | mDiskNumParts = atoi(tmp); |
| 141 | } else { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 142 | SLOGW("Kernel block uevent missing 'NPARTS'"); |
San Mehat | 7b8f2db | 2010-01-04 14:03:36 -0800 | [diff] [blame] | 143 | mDiskNumParts = 1; |
| 144 | } |
| 145 | |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 146 | char msg[255]; |
San Mehat | fd7f587 | 2009-10-12 11:32:47 -0700 | [diff] [blame] | 147 | |
| 148 | int partmask = 0; |
| 149 | int i; |
San Mehat | 59abc3c | 2009-10-12 14:48:47 -0700 | [diff] [blame] | 150 | for (i = 1; i <= mDiskNumParts; i++) { |
San Mehat | fd7f587 | 2009-10-12 11:32:47 -0700 | [diff] [blame] | 151 | partmask |= (1 << i); |
| 152 | } |
| 153 | mPendingPartMap = partmask; |
| 154 | |
| 155 | if (mDiskNumParts == 0) { |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 156 | #ifdef PARTITION_DEBUG |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 157 | SLOGD("Dv::diskIns - No partitions - good to go son!"); |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 158 | #endif |
San Mehat | fd7f587 | 2009-10-12 11:32:47 -0700 | [diff] [blame] | 159 | setState(Volume::State_Idle); |
| 160 | } else { |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 161 | #ifdef PARTITION_DEBUG |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 162 | SLOGD("Dv::diskIns - waiting for %d partitions (mask 0x%x)", |
San Mehat | fd7f587 | 2009-10-12 11:32:47 -0700 | [diff] [blame] | 163 | mDiskNumParts, mPendingPartMap); |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 164 | #endif |
San Mehat | fd7f587 | 2009-10-12 11:32:47 -0700 | [diff] [blame] | 165 | setState(Volume::State_Pending); |
| 166 | } |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 167 | |
| 168 | snprintf(msg, sizeof(msg), "Volume %s %s disk inserted (%d:%d)", |
| 169 | getLabel(), getMountpoint(), mDiskMajor, mDiskMinor); |
| 170 | mVm->getBroadcaster()->sendBroadcast(ResponseCode::VolumeDiskInserted, |
| 171 | msg, false); |
San Mehat | fd7f587 | 2009-10-12 11:32:47 -0700 | [diff] [blame] | 172 | } |
| 173 | |
San Mehat | ae10b91 | 2009-10-12 14:57:05 -0700 | [diff] [blame] | 174 | void DirectVolume::handlePartitionAdded(const char *devpath, NetlinkEvent *evt) { |
Kenny Root | da62e7c | 2010-03-24 20:18:00 -0700 | [diff] [blame] | 175 | int major = atoi(evt->findParam("MAJOR")); |
| 176 | int minor = atoi(evt->findParam("MINOR")); |
San Mehat | 7b8f2db | 2010-01-04 14:03:36 -0800 | [diff] [blame] | 177 | |
| 178 | int part_num; |
| 179 | |
| 180 | const char *tmp = evt->findParam("PARTN"); |
| 181 | |
| 182 | if (tmp) { |
| 183 | part_num = atoi(tmp); |
| 184 | } else { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 185 | SLOGW("Kernel block uevent missing 'PARTN'"); |
San Mehat | 7b8f2db | 2010-01-04 14:03:36 -0800 | [diff] [blame] | 186 | part_num = 1; |
| 187 | } |
San Mehat | 59abc3c | 2009-10-12 14:48:47 -0700 | [diff] [blame] | 188 | |
Nick Kralevich | f3d3ce5 | 2011-04-18 11:16:13 -0700 | [diff] [blame^] | 189 | if (part_num > MAX_PARTITIONS || part_num < 1) { |
| 190 | SLOGW("Invalid 'PARTN' value"); |
| 191 | part_num = 1; |
| 192 | } |
| 193 | |
San Mehat | 2a5b8ce | 2010-03-10 12:48:57 -0800 | [diff] [blame] | 194 | if (part_num > mDiskNumParts) { |
| 195 | mDiskNumParts = part_num; |
| 196 | } |
| 197 | |
San Mehat | dd9b8e9 | 2009-10-21 11:06:52 -0700 | [diff] [blame] | 198 | if (major != mDiskMajor) { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 199 | SLOGE("Partition '%s' has a different major than its disk!", devpath); |
San Mehat | dd9b8e9 | 2009-10-21 11:06:52 -0700 | [diff] [blame] | 200 | return; |
| 201 | } |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 202 | #ifdef PARTITION_DEBUG |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 203 | SLOGD("Dv:partAdd: part_num = %d, minor = %d\n", part_num, minor); |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 204 | #endif |
San Mehat | dd9b8e9 | 2009-10-21 11:06:52 -0700 | [diff] [blame] | 205 | mPartMinors[part_num -1] = minor; |
| 206 | |
San Mehat | 59abc3c | 2009-10-12 14:48:47 -0700 | [diff] [blame] | 207 | mPendingPartMap &= ~(1 << part_num); |
| 208 | if (!mPendingPartMap) { |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 209 | #ifdef PARTITION_DEBUG |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 210 | SLOGD("Dv:partAdd: Got all partitions - ready to rock!"); |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 211 | #endif |
San Mehat | 2a5b8ce | 2010-03-10 12:48:57 -0800 | [diff] [blame] | 212 | if (getState() != Volume::State_Formatting) { |
| 213 | setState(Volume::State_Idle); |
| 214 | } |
San Mehat | 59abc3c | 2009-10-12 14:48:47 -0700 | [diff] [blame] | 215 | } else { |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 216 | #ifdef PARTITION_DEBUG |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 217 | SLOGD("Dv:partAdd: pending mask now = 0x%x", mPendingPartMap); |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 218 | #endif |
San Mehat | 59abc3c | 2009-10-12 14:48:47 -0700 | [diff] [blame] | 219 | } |
San Mehat | fd7f587 | 2009-10-12 11:32:47 -0700 | [diff] [blame] | 220 | } |
| 221 | |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 222 | void DirectVolume::handleDiskChanged(const char *devpath, NetlinkEvent *evt) { |
Kenny Root | da62e7c | 2010-03-24 20:18:00 -0700 | [diff] [blame] | 223 | int major = atoi(evt->findParam("MAJOR")); |
| 224 | int minor = atoi(evt->findParam("MINOR")); |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 225 | |
| 226 | if ((major != mDiskMajor) || (minor != mDiskMinor)) { |
| 227 | return; |
| 228 | } |
| 229 | |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 230 | SLOGI("Volume %s disk has changed", getLabel()); |
San Mehat | 7b8f2db | 2010-01-04 14:03:36 -0800 | [diff] [blame] | 231 | const char *tmp = evt->findParam("NPARTS"); |
| 232 | if (tmp) { |
| 233 | mDiskNumParts = atoi(tmp); |
| 234 | } else { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 235 | SLOGW("Kernel block uevent missing 'NPARTS'"); |
San Mehat | 7b8f2db | 2010-01-04 14:03:36 -0800 | [diff] [blame] | 236 | mDiskNumParts = 1; |
| 237 | } |
| 238 | |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 239 | int partmask = 0; |
| 240 | int i; |
| 241 | for (i = 1; i <= mDiskNumParts; i++) { |
| 242 | partmask |= (1 << i); |
| 243 | } |
| 244 | mPendingPartMap = partmask; |
| 245 | |
San Mehat | 2a5b8ce | 2010-03-10 12:48:57 -0800 | [diff] [blame] | 246 | if (getState() != Volume::State_Formatting) { |
| 247 | if (mDiskNumParts == 0) { |
| 248 | setState(Volume::State_Idle); |
| 249 | } else { |
| 250 | setState(Volume::State_Pending); |
| 251 | } |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 252 | } |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | void DirectVolume::handlePartitionChanged(const char *devpath, NetlinkEvent *evt) { |
Kenny Root | da62e7c | 2010-03-24 20:18:00 -0700 | [diff] [blame] | 256 | int major = atoi(evt->findParam("MAJOR")); |
| 257 | int minor = atoi(evt->findParam("MINOR")); |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 258 | SLOGD("Volume %s %s partition %d:%d changed\n", getLabel(), getMountpoint(), major, minor); |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 259 | } |
| 260 | |
San Mehat | ae10b91 | 2009-10-12 14:57:05 -0700 | [diff] [blame] | 261 | void DirectVolume::handleDiskRemoved(const char *devpath, NetlinkEvent *evt) { |
Kenny Root | da62e7c | 2010-03-24 20:18:00 -0700 | [diff] [blame] | 262 | int major = atoi(evt->findParam("MAJOR")); |
| 263 | int minor = atoi(evt->findParam("MINOR")); |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 264 | char msg[255]; |
| 265 | |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 266 | SLOGD("Volume %s %s disk %d:%d removed\n", getLabel(), getMountpoint(), major, minor); |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 267 | snprintf(msg, sizeof(msg), "Volume %s %s disk removed (%d:%d)", |
| 268 | getLabel(), getMountpoint(), major, minor); |
| 269 | mVm->getBroadcaster()->sendBroadcast(ResponseCode::VolumeDiskRemoved, |
| 270 | msg, false); |
| 271 | setState(Volume::State_NoMedia); |
San Mehat | fd7f587 | 2009-10-12 11:32:47 -0700 | [diff] [blame] | 272 | } |
| 273 | |
San Mehat | ae10b91 | 2009-10-12 14:57:05 -0700 | [diff] [blame] | 274 | void DirectVolume::handlePartitionRemoved(const char *devpath, NetlinkEvent *evt) { |
Kenny Root | da62e7c | 2010-03-24 20:18:00 -0700 | [diff] [blame] | 275 | int major = atoi(evt->findParam("MAJOR")); |
| 276 | int minor = atoi(evt->findParam("MINOR")); |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 277 | char msg[255]; |
| 278 | |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 279 | SLOGD("Volume %s %s partition %d:%d removed\n", getLabel(), getMountpoint(), major, minor); |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 280 | |
| 281 | /* |
| 282 | * The framework doesn't need to get notified of |
| 283 | * partition removal unless it's mounted. Otherwise |
| 284 | * the removal notification will be sent on the Disk |
| 285 | * itself |
| 286 | */ |
| 287 | if (getState() != Volume::State_Mounted) { |
| 288 | return; |
| 289 | } |
| 290 | |
| 291 | if ((dev_t) MKDEV(major, minor) == mCurrentlyMountedKdev) { |
| 292 | /* |
| 293 | * Yikes, our mounted partition is going away! |
| 294 | */ |
| 295 | |
| 296 | snprintf(msg, sizeof(msg), "Volume %s %s bad removal (%d:%d)", |
| 297 | getLabel(), getMountpoint(), major, minor); |
| 298 | mVm->getBroadcaster()->sendBroadcast(ResponseCode::VolumeBadRemoval, |
| 299 | msg, false); |
San Mehat | 1a06eda | 2010-04-15 12:58:50 -0700 | [diff] [blame] | 300 | |
| 301 | if (mVm->cleanupAsec(this, true)) { |
| 302 | SLOGE("Failed to cleanup ASEC - unmount will probably fail!"); |
| 303 | } |
| 304 | |
San Mehat | 4ba8948 | 2010-02-18 09:00:18 -0800 | [diff] [blame] | 305 | if (Volume::unmountVol(true)) { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 306 | SLOGE("Failed to unmount volume on bad removal (%s)", |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 307 | strerror(errno)); |
| 308 | // XXX: At this point we're screwed for now |
| 309 | } else { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 310 | SLOGD("Crisis averted"); |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 311 | } |
| 312 | } |
San Mehat | fd7f587 | 2009-10-12 11:32:47 -0700 | [diff] [blame] | 313 | } |
San Mehat | 49e2bce | 2009-10-12 16:29:01 -0700 | [diff] [blame] | 314 | |
San Mehat | dd9b8e9 | 2009-10-21 11:06:52 -0700 | [diff] [blame] | 315 | /* |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 316 | * Called from base to get a list of devicenodes for mounting |
San Mehat | dd9b8e9 | 2009-10-21 11:06:52 -0700 | [diff] [blame] | 317 | */ |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 318 | int DirectVolume::getDeviceNodes(dev_t *devs, int max) { |
San Mehat | dd9b8e9 | 2009-10-21 11:06:52 -0700 | [diff] [blame] | 319 | |
| 320 | if (mPartIdx == -1) { |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 321 | // If the disk has no partitions, try the disk itself |
San Mehat | dd9b8e9 | 2009-10-21 11:06:52 -0700 | [diff] [blame] | 322 | if (!mDiskNumParts) { |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 323 | devs[0] = MKDEV(mDiskMajor, mDiskMinor); |
| 324 | return 1; |
San Mehat | dd9b8e9 | 2009-10-21 11:06:52 -0700 | [diff] [blame] | 325 | } |
| 326 | |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 327 | int i; |
| 328 | for (i = 0; i < mDiskNumParts; i++) { |
| 329 | if (i == max) |
| 330 | break; |
| 331 | devs[i] = MKDEV(mDiskMajor, mPartMinors[i]); |
| 332 | } |
| 333 | return mDiskNumParts; |
San Mehat | dd9b8e9 | 2009-10-21 11:06:52 -0700 | [diff] [blame] | 334 | } |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 335 | devs[0] = MKDEV(mDiskMajor, mPartMinors[mPartIdx -1]); |
| 336 | return 1; |
San Mehat | 49e2bce | 2009-10-12 16:29:01 -0700 | [diff] [blame] | 337 | } |