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 | |
| 22 | #define LOG_TAG "Vold" |
| 23 | |
| 24 | #include <cutils/log.h> |
San Mehat | fd7f587 | 2009-10-12 11:32:47 -0700 | [diff] [blame^] | 25 | #include <sysutils/NetlinkEvent.h> |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 26 | |
| 27 | #include "DeviceVolume.h" |
| 28 | |
| 29 | DeviceVolume::DeviceVolume(const char *label, const char *mount_point, int partIdx) : |
| 30 | Volume(label, mount_point) { |
| 31 | mPartIdx = partIdx; |
| 32 | |
| 33 | mPaths = new PathCollection(); |
| 34 | } |
| 35 | |
| 36 | DeviceVolume::~DeviceVolume() { |
| 37 | PathCollection::iterator it; |
| 38 | |
| 39 | for (it = mPaths->begin(); it != mPaths->end(); ++it) |
| 40 | free(*it); |
| 41 | delete mPaths; |
| 42 | } |
| 43 | |
| 44 | int DeviceVolume::addPath(const char *path) { |
| 45 | mPaths->push_back(strdup(path)); |
| 46 | return 0; |
| 47 | } |
| 48 | |
San Mehat | fd7f587 | 2009-10-12 11:32:47 -0700 | [diff] [blame^] | 49 | int DeviceVolume::handleBlockEvent(NetlinkEvent *evt) { |
| 50 | const char *dp = evt->findParam("DEVPATH"); |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 51 | |
San Mehat | fd7f587 | 2009-10-12 11:32:47 -0700 | [diff] [blame^] | 52 | PathCollection::iterator it; |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 53 | for (it = mPaths->begin(); it != mPaths->end(); ++it) { |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 54 | if (!strncmp(dp, *it, strlen(*it))) { |
San Mehat | fd7f587 | 2009-10-12 11:32:47 -0700 | [diff] [blame^] | 55 | /* We can handle this disk */ |
| 56 | int action = evt->getAction(); |
| 57 | const char *devtype = evt->findParam("DEVTYPE"); |
| 58 | |
| 59 | if (!strcmp(devtype, "disk")) { |
| 60 | if (action == NetlinkEvent::NlActionAdd) |
| 61 | handleDiskAdded(dp, evt); |
| 62 | else if (action == NetlinkEvent::NlActionRemove) |
| 63 | handleDiskRemoved(dp, evt); |
| 64 | else |
| 65 | LOGD("Ignoring non add/remove event"); |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 66 | } else { |
San Mehat | fd7f587 | 2009-10-12 11:32:47 -0700 | [diff] [blame^] | 67 | if (action == NetlinkEvent::NlActionAdd) |
| 68 | handlePartitionAdded(dp, evt); |
| 69 | else if (action == NetlinkEvent::NlActionRemove) |
| 70 | handlePartitionRemoved(dp, evt); |
| 71 | else |
| 72 | LOGD("Ignoring non add/remove event"); |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 73 | } |
San Mehat | fd7f587 | 2009-10-12 11:32:47 -0700 | [diff] [blame^] | 74 | |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 75 | return 0; |
| 76 | } |
| 77 | } |
| 78 | errno = ENODEV; |
| 79 | return -1; |
| 80 | } |
San Mehat | fd7f587 | 2009-10-12 11:32:47 -0700 | [diff] [blame^] | 81 | |
| 82 | void DeviceVolume::handleDiskAdded(const char *devpath, NetlinkEvent *evt) { |
| 83 | mDiskMaj = atoi(evt->findParam("MAJOR")); |
| 84 | mDiskNumParts = atoi(evt->findParam("NPARTS")); |
| 85 | |
| 86 | int partmask = 0; |
| 87 | int i; |
| 88 | for (i = 0; i < mDiskNumParts; i++) { |
| 89 | partmask |= (1 << i); |
| 90 | } |
| 91 | mPendingPartMap = partmask; |
| 92 | |
| 93 | if (mDiskNumParts == 0) { |
| 94 | LOGD("Dv::diskIns - No partitions - good to go son!"); |
| 95 | setState(Volume::State_Idle); |
| 96 | } else { |
| 97 | LOGD("Dv::diskIns - waiting for %d partitions (mask 0x%x)", |
| 98 | mDiskNumParts, mPendingPartMap); |
| 99 | setState(Volume::State_Pending); |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | void DeviceVolume::handlePartitionAdded(const char *devpath, NetlinkEvent *evt) { |
| 104 | int major = atoi(evt->findParam("MAJOR")); |
| 105 | int minor = atoi(evt->findParam("MINOR")); |
| 106 | int part_num = atoi(evt->findParam("PARTN")); |
| 107 | } |
| 108 | |
| 109 | void DeviceVolume::handleDiskRemoved(const char *devpath, NetlinkEvent *evt) { |
| 110 | } |
| 111 | |
| 112 | void DeviceVolume::handlePartitionRemoved(const char *devpath, NetlinkEvent *evt) { |
| 113 | } |