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 | #ifndef _DEVICEVOLUME_H |
| 18 | #define _DEVICEVOLUME_H |
| 19 | |
| 20 | #include <utils/List.h> |
Kenny Root | a9f423d | 2010-03-24 15:37:48 -0700 | [diff] [blame^] | 21 | #include <sysutils/NetlinkEvent.h> |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 22 | |
| 23 | #include "Volume.h" |
| 24 | |
San Mehat | dd9b8e9 | 2009-10-21 11:06:52 -0700 | [diff] [blame] | 25 | #define MAX_PARTS 4 |
| 26 | |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 27 | typedef android::List<char *> PathCollection; |
| 28 | |
Kenny Root | a9f423d | 2010-03-24 15:37:48 -0700 | [diff] [blame^] | 29 | inline 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 Mehat | ae10b91 | 2009-10-12 14:57:05 -0700 | [diff] [blame] | 43 | class DirectVolume : public Volume { |
San Mehat | dd9b8e9 | 2009-10-21 11:06:52 -0700 | [diff] [blame] | 44 | public: |
| 45 | static const int MAX_PARTITIONS = 4; |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 46 | protected: |
| 47 | PathCollection *mPaths; |
| 48 | int mPartIdx; |
San Mehat | dd9b8e9 | 2009-10-21 11:06:52 -0700 | [diff] [blame] | 49 | int mDiskMajor; |
| 50 | int mDiskMinor; |
| 51 | int mPartMinors[MAX_PARTITIONS]; |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 52 | int mDiskNumParts; |
San Mehat | fd7f587 | 2009-10-12 11:32:47 -0700 | [diff] [blame] | 53 | unsigned char mPendingPartMap; |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 54 | |
| 55 | public: |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 56 | DirectVolume(VolumeManager *vm, const char *label, const char *mount_point, int partIdx); |
San Mehat | ae10b91 | 2009-10-12 14:57:05 -0700 | [diff] [blame] | 57 | virtual ~DirectVolume(); |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 58 | |
| 59 | int addPath(const char *path); |
| 60 | |
San Mehat | fd7f587 | 2009-10-12 11:32:47 -0700 | [diff] [blame] | 61 | int handleBlockEvent(NetlinkEvent *evt); |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 62 | dev_t getDiskDevice(); |
| 63 | void handleVolumeShared(); |
| 64 | void handleVolumeUnshared(); |
| 65 | |
San Mehat | 49e2bce | 2009-10-12 16:29:01 -0700 | [diff] [blame] | 66 | protected: |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 67 | int getDeviceNodes(dev_t *devs, int max); |
San Mehat | fd7f587 | 2009-10-12 11:32:47 -0700 | [diff] [blame] | 68 | |
| 69 | private: |
| 70 | void handleDiskAdded(const char *devpath, NetlinkEvent *evt); |
| 71 | void handleDiskRemoved(const char *devpath, NetlinkEvent *evt); |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 72 | void handleDiskChanged(const char *devpath, NetlinkEvent *evt); |
San Mehat | fd7f587 | 2009-10-12 11:32:47 -0700 | [diff] [blame] | 73 | void handlePartitionAdded(const char *devpath, NetlinkEvent *evt); |
| 74 | void handlePartitionRemoved(const char *devpath, NetlinkEvent *evt); |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 75 | void handlePartitionChanged(const char *devpath, NetlinkEvent *evt); |
| 76 | |
| 77 | int doMountVfat(const char *deviceNode, const char *mountPoint); |
San Mehat | 49e2bce | 2009-10-12 16:29:01 -0700 | [diff] [blame] | 78 | |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 79 | }; |
| 80 | |
San Mehat | ae10b91 | 2009-10-12 14:57:05 -0700 | [diff] [blame] | 81 | typedef android::List<DirectVolume *> DirectVolumeCollection; |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 82 | |
| 83 | #endif |