blob: 3c95b4b67278f27531f7bae9e811a250bd888fe8 [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#ifndef _DEVICEVOLUME_H
18#define _DEVICEVOLUME_H
19
20#include <utils/List.h>
Kenny Roota9f423d2010-03-24 15:37:48 -070021#include <sysutils/NetlinkEvent.h>
San Mehatf1b736b2009-10-10 17:22:08 -070022
23#include "Volume.h"
24
San Mehatdd9b8e92009-10-21 11:06:52 -070025#define MAX_PARTS 4
26
San Mehatf1b736b2009-10-10 17:22:08 -070027typedef android::List<char *> PathCollection;
28
Kenny Roota9f423d2010-03-24 15:37:48 -070029inline bool getMajorMinorNum(NetlinkEvent *evt, int *major, int *minor) {
30 const char *major_str = evt->findParam("MAJOR");
31 const char *minor_str = evt->findParam("MINOR");
32
33 if (major_str == NULL || minor_str == NULL) {
34 return false;
35 }
36
37 *major = atoi(major_str);
38 *minor = atoi(minor_str);
39
40 return true;
41}
42
San Mehatae10b912009-10-12 14:57:05 -070043class DirectVolume : public Volume {
San Mehatdd9b8e92009-10-21 11:06:52 -070044public:
45 static const int MAX_PARTITIONS = 4;
San Mehatf1b736b2009-10-10 17:22:08 -070046protected:
47 PathCollection *mPaths;
48 int mPartIdx;
San Mehatdd9b8e92009-10-21 11:06:52 -070049 int mDiskMajor;
50 int mDiskMinor;
51 int mPartMinors[MAX_PARTITIONS];
San Mehatf1b736b2009-10-10 17:22:08 -070052 int mDiskNumParts;
San Mehatfd7f5872009-10-12 11:32:47 -070053 unsigned char mPendingPartMap;
San Mehatf1b736b2009-10-10 17:22:08 -070054
55public:
San Mehata2677e42009-12-13 10:40:18 -080056 DirectVolume(VolumeManager *vm, const char *label, const char *mount_point, int partIdx);
San Mehatae10b912009-10-12 14:57:05 -070057 virtual ~DirectVolume();
San Mehatf1b736b2009-10-10 17:22:08 -070058
59 int addPath(const char *path);
60
San Mehatfd7f5872009-10-12 11:32:47 -070061 int handleBlockEvent(NetlinkEvent *evt);
San Mehata2677e42009-12-13 10:40:18 -080062 dev_t getDiskDevice();
63 void handleVolumeShared();
64 void handleVolumeUnshared();
65
San Mehat49e2bce2009-10-12 16:29:01 -070066protected:
San Mehata2677e42009-12-13 10:40:18 -080067 int getDeviceNodes(dev_t *devs, int max);
San Mehatfd7f5872009-10-12 11:32:47 -070068
69private:
70 void handleDiskAdded(const char *devpath, NetlinkEvent *evt);
71 void handleDiskRemoved(const char *devpath, NetlinkEvent *evt);
San Mehata2677e42009-12-13 10:40:18 -080072 void handleDiskChanged(const char *devpath, NetlinkEvent *evt);
San Mehatfd7f5872009-10-12 11:32:47 -070073 void handlePartitionAdded(const char *devpath, NetlinkEvent *evt);
74 void handlePartitionRemoved(const char *devpath, NetlinkEvent *evt);
San Mehata2677e42009-12-13 10:40:18 -080075 void handlePartitionChanged(const char *devpath, NetlinkEvent *evt);
76
77 int doMountVfat(const char *deviceNode, const char *mountPoint);
San Mehat49e2bce2009-10-12 16:29:01 -070078
San Mehatf1b736b2009-10-10 17:22:08 -070079};
80
San Mehatae10b912009-10-12 14:57:05 -070081typedef android::List<DirectVolume *> DirectVolumeCollection;
San Mehatf1b736b2009-10-10 17:22:08 -070082
83#endif