DirectVolume.cpp revision 49e2bce5b74129c26a35e25d4693cbfe98c4688e
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> 18#include <stdlib.h> 19#include <string.h> 20#include <errno.h> 21 22#define LOG_TAG "Vold" 23 24#include <cutils/log.h> 25#include <sysutils/NetlinkEvent.h> 26 27#include "DirectVolume.h" 28 29DirectVolume::DirectVolume(const char *label, const char *mount_point, int partIdx) : 30 Volume(label, mount_point) { 31 mPartIdx = partIdx; 32 33 mPaths = new PathCollection(); 34} 35 36DirectVolume::~DirectVolume() { 37 PathCollection::iterator it; 38 39 for (it = mPaths->begin(); it != mPaths->end(); ++it) 40 free(*it); 41 delete mPaths; 42} 43 44int DirectVolume::addPath(const char *path) { 45 mPaths->push_back(strdup(path)); 46 return 0; 47} 48 49int DirectVolume::handleBlockEvent(NetlinkEvent *evt) { 50 const char *dp = evt->findParam("DEVPATH"); 51 52 PathCollection::iterator it; 53 for (it = mPaths->begin(); it != mPaths->end(); ++it) { 54 if (!strncmp(dp, *it, strlen(*it))) { 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"); 66 } else { 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"); 73 } 74 75 return 0; 76 } 77 } 78 errno = ENODEV; 79 return -1; 80} 81 82void DirectVolume::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 = 1; 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 103void DirectVolume::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 mPendingPartMap &= ~(1 << part_num); 109 if (!mPendingPartMap) { 110 LOGD("Dv:partAdd: Got all partitions - ready to rock!"); 111 setState(Volume::State_Idle); 112 } else { 113 LOGD("Dv:partAdd: pending mask now = 0x%x", mPendingPartMap); 114 } 115} 116 117void DirectVolume::handleDiskRemoved(const char *devpath, NetlinkEvent *evt) { 118} 119 120void DirectVolume::handlePartitionRemoved(const char *devpath, NetlinkEvent *evt) { 121} 122 123int DirectVolume::prepareToMount(int *major, int *minor) { 124 errno = ENOSYS; 125 return -1; 126} 127