1f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehat/*
2f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehat * Copyright (C) 2008 The Android Open Source Project
3f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehat *
4f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehat * Licensed under the Apache License, Version 2.0 (the "License");
5f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehat * you may not use this file except in compliance with the License.
6f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehat * You may obtain a copy of the License at
7f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehat *
8f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehat *      http://www.apache.org/licenses/LICENSE-2.0
9f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehat *
10f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehat * Unless required by applicable law or agreed to in writing, software
11f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehat * distributed under the License is distributed on an "AS IS" BASIS,
12f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehat * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehat * See the License for the specific language governing permissions and
14f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehat * limitations under the License.
15f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehat */
16f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehat
17f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehat#ifndef _DEVICEVOLUME_H
18f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehat#define _DEVICEVOLUME_H
19f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehat
20f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehat#include <utils/List.h>
21f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehat
22f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehat#include "Volume.h"
23f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehat
24dd9b8e92aaf330b48ddb40a7380588ef92b53de6San Mehat#define MAX_PARTS 4
25dd9b8e92aaf330b48ddb40a7380588ef92b53de6San Mehat
26f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehattypedef android::List<char *> PathCollection;
27f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehat
28ae10b91044bf76b40b77d81c169e48e0bbdf6d75San Mehatclass DirectVolume : public Volume {
29dd9b8e92aaf330b48ddb40a7380588ef92b53de6San Mehatpublic:
30dd9b8e92aaf330b48ddb40a7380588ef92b53de6San Mehat    static const int MAX_PARTITIONS = 4;
31f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehatprotected:
32f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehat    PathCollection *mPaths;
33dd9b8e92aaf330b48ddb40a7380588ef92b53de6San Mehat    int            mDiskMajor;
34dd9b8e92aaf330b48ddb40a7380588ef92b53de6San Mehat    int            mDiskMinor;
35dd9b8e92aaf330b48ddb40a7380588ef92b53de6San Mehat    int            mPartMinors[MAX_PARTITIONS];
360b8b59719357fb80c330442787f7d5b1e332263bKen Sumrall    int            mOrigDiskMajor;
370b8b59719357fb80c330442787f7d5b1e332263bKen Sumrall    int            mOrigDiskMinor;
380b8b59719357fb80c330442787f7d5b1e332263bKen Sumrall    int            mOrigPartMinors[MAX_PARTITIONS];
39f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehat    int            mDiskNumParts;
40fd7f5875129adfe2845f4f3fffb17db3a89eea25San Mehat    unsigned char  mPendingPartMap;
4129d8da8cefa99e436c13295d4c9bad060ca18a6dKen Sumrall    int            mIsDecrypted;
4229d8da8cefa99e436c13295d4c9bad060ca18a6dKen Sumrall    int            mFlags;
43f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehat
44f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehatpublic:
45a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat    DirectVolume(VolumeManager *vm, const char *label, const char *mount_point, int partIdx);
46ae10b91044bf76b40b77d81c169e48e0bbdf6d75San Mehat    virtual ~DirectVolume();
47f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehat
48f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehat    int addPath(const char *path);
49f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehat
50fd7f5875129adfe2845f4f3fffb17db3a89eea25San Mehat    int handleBlockEvent(NetlinkEvent *evt);
51a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat    dev_t getDiskDevice();
522dfe297ec47559dbe2297a72bea71cf515c03797Mike Lockwood    dev_t getShareDevice();
53a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat    void handleVolumeShared();
54a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat    void handleVolumeUnshared();
5529d8da8cefa99e436c13295d4c9bad060ca18a6dKen Sumrall    int getVolInfo(struct volume_info *v);
5629d8da8cefa99e436c13295d4c9bad060ca18a6dKen Sumrall    void setFlags(int flags);
57a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat
5849e2bce5b74129c26a35e25d4693cbfe98c4688eSan Mehatprotected:
59a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat    int getDeviceNodes(dev_t *devs, int max);
6029d8da8cefa99e436c13295d4c9bad060ca18a6dKen Sumrall    int updateDeviceInfo(char *new_path, int new_major, int new_minor);
610b8b59719357fb80c330442787f7d5b1e332263bKen Sumrall    virtual void revertDeviceInfo(void);
6229d8da8cefa99e436c13295d4c9bad060ca18a6dKen Sumrall    int isDecrypted() { return mIsDecrypted; }
6329d8da8cefa99e436c13295d4c9bad060ca18a6dKen Sumrall    int getFlags() { return mFlags; }
64fd7f5875129adfe2845f4f3fffb17db3a89eea25San Mehat
65fd7f5875129adfe2845f4f3fffb17db3a89eea25San Mehatprivate:
66fd7f5875129adfe2845f4f3fffb17db3a89eea25San Mehat    void handleDiskAdded(const char *devpath, NetlinkEvent *evt);
67fd7f5875129adfe2845f4f3fffb17db3a89eea25San Mehat    void handleDiskRemoved(const char *devpath, NetlinkEvent *evt);
68a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat    void handleDiskChanged(const char *devpath, NetlinkEvent *evt);
69fd7f5875129adfe2845f4f3fffb17db3a89eea25San Mehat    void handlePartitionAdded(const char *devpath, NetlinkEvent *evt);
70fd7f5875129adfe2845f4f3fffb17db3a89eea25San Mehat    void handlePartitionRemoved(const char *devpath, NetlinkEvent *evt);
71a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat    void handlePartitionChanged(const char *devpath, NetlinkEvent *evt);
72a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat
73a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat    int doMountVfat(const char *deviceNode, const char *mountPoint);
7449e2bce5b74129c26a35e25d4693cbfe98c4688eSan Mehat
75f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehat};
76f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehat
77ae10b91044bf76b40b77d81c169e48e0bbdf6d75San Mehattypedef android::List<DirectVolume *> DirectVolumeCollection;
78f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehat
79f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehat#endif
80