blob: d7441806d1d54f4e5c51dd612fec8415d60265e1 [file] [log] [blame]
San Mehatf1b736b2009-10-10 17:22:08 -07001/*
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 Mehatfd7f5872009-10-12 11:32:47 -070018#include <stdlib.h>
San Mehatf1b736b2009-10-10 17:22:08 -070019#include <string.h>
San Mehatfd7f5872009-10-12 11:32:47 -070020#include <errno.h>
San Mehatf1b736b2009-10-10 17:22:08 -070021
22#define LOG_TAG "Vold"
23
24#include <cutils/log.h>
San Mehatfd7f5872009-10-12 11:32:47 -070025#include <sysutils/NetlinkEvent.h>
San Mehatf1b736b2009-10-10 17:22:08 -070026
27#include "DeviceVolume.h"
28
29DeviceVolume::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
36DeviceVolume::~DeviceVolume() {
37 PathCollection::iterator it;
38
39 for (it = mPaths->begin(); it != mPaths->end(); ++it)
40 free(*it);
41 delete mPaths;
42}
43
44int DeviceVolume::addPath(const char *path) {
45 mPaths->push_back(strdup(path));
46 return 0;
47}
48
San Mehatfd7f5872009-10-12 11:32:47 -070049int DeviceVolume::handleBlockEvent(NetlinkEvent *evt) {
50 const char *dp = evt->findParam("DEVPATH");
San Mehatf1b736b2009-10-10 17:22:08 -070051
San Mehatfd7f5872009-10-12 11:32:47 -070052 PathCollection::iterator it;
San Mehatf1b736b2009-10-10 17:22:08 -070053 for (it = mPaths->begin(); it != mPaths->end(); ++it) {
San Mehatf1b736b2009-10-10 17:22:08 -070054 if (!strncmp(dp, *it, strlen(*it))) {
San Mehatfd7f5872009-10-12 11:32:47 -070055 /* 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 Mehatf1b736b2009-10-10 17:22:08 -070066 } else {
San Mehatfd7f5872009-10-12 11:32:47 -070067 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 Mehatf1b736b2009-10-10 17:22:08 -070073 }
San Mehatfd7f5872009-10-12 11:32:47 -070074
San Mehatf1b736b2009-10-10 17:22:08 -070075 return 0;
76 }
77 }
78 errno = ENODEV;
79 return -1;
80}
San Mehatfd7f5872009-10-12 11:32:47 -070081
82void 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
103void 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
109void DeviceVolume::handleDiskRemoved(const char *devpath, NetlinkEvent *evt) {
110}
111
112void DeviceVolume::handlePartitionRemoved(const char *devpath, NetlinkEvent *evt) {
113}