You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
122 lines
3.6 KiB
122 lines
3.6 KiB
15 years ago
|
/*
|
||
|
* Copyright (C) 2008 The Android Open Source Project
|
||
|
*
|
||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||
|
* you may not use this file except in compliance with the License.
|
||
|
* You may obtain a copy of the License at
|
||
|
*
|
||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||
|
*
|
||
|
* Unless required by applicable law or agreed to in writing, software
|
||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||
|
* See the License for the specific language governing permissions and
|
||
|
* limitations under the License.
|
||
|
*/
|
||
|
|
||
|
#include <stdio.h>
|
||
15 years ago
|
#include <stdlib.h>
|
||
15 years ago
|
#include <string.h>
|
||
15 years ago
|
#include <errno.h>
|
||
15 years ago
|
|
||
|
#define LOG_TAG "Vold"
|
||
|
|
||
|
#include <cutils/log.h>
|
||
15 years ago
|
#include <sysutils/NetlinkEvent.h>
|
||
15 years ago
|
|
||
15 years ago
|
#include "DirectVolume.h"
|
||
15 years ago
|
|
||
15 years ago
|
DirectVolume::DirectVolume(const char *label, const char *mount_point, int partIdx) :
|
||
15 years ago
|
Volume(label, mount_point) {
|
||
|
mPartIdx = partIdx;
|
||
|
|
||
|
mPaths = new PathCollection();
|
||
|
}
|
||
|
|
||
15 years ago
|
DirectVolume::~DirectVolume() {
|
||
15 years ago
|
PathCollection::iterator it;
|
||
|
|
||
|
for (it = mPaths->begin(); it != mPaths->end(); ++it)
|
||
|
free(*it);
|
||
|
delete mPaths;
|
||
|
}
|
||
|
|
||
15 years ago
|
int DirectVolume::addPath(const char *path) {
|
||
15 years ago
|
mPaths->push_back(strdup(path));
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
15 years ago
|
int DirectVolume::handleBlockEvent(NetlinkEvent *evt) {
|
||
15 years ago
|
const char *dp = evt->findParam("DEVPATH");
|
||
15 years ago
|
|
||
15 years ago
|
PathCollection::iterator it;
|
||
15 years ago
|
for (it = mPaths->begin(); it != mPaths->end(); ++it) {
|
||
|
if (!strncmp(dp, *it, strlen(*it))) {
|
||
15 years ago
|
/* We can handle this disk */
|
||
|
int action = evt->getAction();
|
||
|
const char *devtype = evt->findParam("DEVTYPE");
|
||
|
|
||
|
if (!strcmp(devtype, "disk")) {
|
||
|
if (action == NetlinkEvent::NlActionAdd)
|
||
|
handleDiskAdded(dp, evt);
|
||
|
else if (action == NetlinkEvent::NlActionRemove)
|
||
|
handleDiskRemoved(dp, evt);
|
||
|
else
|
||
|
LOGD("Ignoring non add/remove event");
|
||
15 years ago
|
} else {
|
||
15 years ago
|
if (action == NetlinkEvent::NlActionAdd)
|
||
|
handlePartitionAdded(dp, evt);
|
||
|
else if (action == NetlinkEvent::NlActionRemove)
|
||
|
handlePartitionRemoved(dp, evt);
|
||
|
else
|
||
|
LOGD("Ignoring non add/remove event");
|
||
15 years ago
|
}
|
||
15 years ago
|
|
||
15 years ago
|
return 0;
|
||
|
}
|
||
|
}
|
||
|
errno = ENODEV;
|
||
|
return -1;
|
||
|
}
|
||
15 years ago
|
|
||
15 years ago
|
void DirectVolume::handleDiskAdded(const char *devpath, NetlinkEvent *evt) {
|
||
15 years ago
|
mDiskMaj = atoi(evt->findParam("MAJOR"));
|
||
|
mDiskNumParts = atoi(evt->findParam("NPARTS"));
|
||
|
|
||
|
int partmask = 0;
|
||
|
int i;
|
||
15 years ago
|
for (i = 1; i <= mDiskNumParts; i++) {
|
||
15 years ago
|
partmask |= (1 << i);
|
||
|
}
|
||
|
mPendingPartMap = partmask;
|
||
|
|
||
|
if (mDiskNumParts == 0) {
|
||
|
LOGD("Dv::diskIns - No partitions - good to go son!");
|
||
|
setState(Volume::State_Idle);
|
||
|
} else {
|
||
|
LOGD("Dv::diskIns - waiting for %d partitions (mask 0x%x)",
|
||
|
mDiskNumParts, mPendingPartMap);
|
||
|
setState(Volume::State_Pending);
|
||
|
}
|
||
|
}
|
||
|
|
||
15 years ago
|
void DirectVolume::handlePartitionAdded(const char *devpath, NetlinkEvent *evt) {
|
||
15 years ago
|
int major = atoi(evt->findParam("MAJOR"));
|
||
|
int minor = atoi(evt->findParam("MINOR"));
|
||
|
int part_num = atoi(evt->findParam("PARTN"));
|
||
15 years ago
|
|
||
|
mPendingPartMap &= ~(1 << part_num);
|
||
|
if (!mPendingPartMap) {
|
||
|
LOGD("Dv:partAdd: Got all partitions - ready to rock!");
|
||
|
setState(Volume::State_Idle);
|
||
|
} else {
|
||
|
LOGD("Dv:partAdd: pending mask now = 0x%x", mPendingPartMap);
|
||
|
}
|
||
15 years ago
|
}
|
||
|
|
||
15 years ago
|
void DirectVolume::handleDiskRemoved(const char *devpath, NetlinkEvent *evt) {
|
||
15 years ago
|
}
|
||
|
|
||
15 years ago
|
void DirectVolume::handlePartitionRemoved(const char *devpath, NetlinkEvent *evt) {
|
||
15 years ago
|
}
|