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>
21
22#include "Volume.h"
23
24#define MAX_PARTS 4
25
26typedef android::List<char *> PathCollection;
27
28class DirectVolume : public Volume {
29public:
30    static const int MAX_PARTITIONS = 32;
31protected:
32    const char* mMountpoint;
33    const char* mFuseMountpoint;
34
35    PathCollection *mPaths;
36    int            mDiskMajor;
37    int            mDiskMinor;
38    int            mPartMinors[MAX_PARTITIONS];
39    int            mOrigDiskMajor;
40    int            mOrigDiskMinor;
41    int            mOrigPartMinors[MAX_PARTITIONS];
42    int            mDiskNumParts;
43    unsigned int   mPendingPartMap;
44    int            mIsDecrypted;
45
46public:
47    DirectVolume(VolumeManager *vm, const fstab_rec* rec, int flags);
48    virtual ~DirectVolume();
49
50    int addPath(const char *path);
51
52    const char *getMountpoint() { return mMountpoint; }
53    const char *getFuseMountpoint() { return mFuseMountpoint; }
54
55    int handleBlockEvent(NetlinkEvent *evt);
56    dev_t getDiskDevice();
57    dev_t getShareDevice();
58    void handleVolumeShared();
59    void handleVolumeUnshared();
60    int getVolInfo(struct volume_info *v);
61
62protected:
63    int getDeviceNodes(dev_t *devs, int max);
64    int updateDeviceInfo(char *new_path, int new_major, int new_minor);
65    virtual void revertDeviceInfo(void);
66    int isDecrypted() { return mIsDecrypted; }
67
68private:
69    void handleDiskAdded(const char *devpath, NetlinkEvent *evt);
70    void handleDiskRemoved(const char *devpath, NetlinkEvent *evt);
71    void handleDiskChanged(const char *devpath, NetlinkEvent *evt);
72    void handlePartitionAdded(const char *devpath, NetlinkEvent *evt);
73    void handlePartitionRemoved(const char *devpath, NetlinkEvent *evt);
74    void handlePartitionChanged(const char *devpath, NetlinkEvent *evt);
75
76    int doMountVfat(const char *deviceNode, const char *mountPoint);
77
78};
79
80typedef android::List<DirectVolume *> DirectVolumeCollection;
81
82#endif
83