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#include <stdio.h>
18fd7f5875129adfe2845f4f3fffb17db3a89eea25San Mehat#include <stdlib.h>
19f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehat#include <string.h>
20fd7f5875129adfe2845f4f3fffb17db3a89eea25San Mehat#include <errno.h>
21f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehat
22a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat#include <linux/kdev_t.h>
23a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat
24a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat#define LOG_TAG "DirectVolume"
25f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehat
26f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehat#include <cutils/log.h>
27fd7f5875129adfe2845f4f3fffb17db3a89eea25San Mehat#include <sysutils/NetlinkEvent.h>
28f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehat
29ae10b91044bf76b40b77d81c169e48e0bbdf6d75San Mehat#include "DirectVolume.h"
30a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat#include "VolumeManager.h"
31a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat#include "ResponseCode.h"
3229d8da8cefa99e436c13295d4c9bad060ca18a6dKen Sumrall#include "cryptfs.h"
33a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat
34a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat// #define PARTITION_DEBUG
35f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehat
36a2677e4ad01f250b0765f04adf0acfa6627efc98San MehatDirectVolume::DirectVolume(VolumeManager *vm, const char *label,
37a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat                           const char *mount_point, int partIdx) :
38a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat              Volume(vm, label, mount_point) {
39f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehat    mPartIdx = partIdx;
40a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat
41f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehat    mPaths = new PathCollection();
42dd9b8e92aaf330b48ddb40a7380588ef92b53de6San Mehat    for (int i = 0; i < MAX_PARTITIONS; i++)
43dd9b8e92aaf330b48ddb40a7380588ef92b53de6San Mehat        mPartMinors[i] = -1;
44a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat    mPendingPartMap = 0;
45a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat    mDiskMajor = -1;
46a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat    mDiskMinor = -1;
47a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat    mDiskNumParts = 0;
48a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat
49a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat    setState(Volume::State_NoMedia);
50f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehat}
51f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehat
52ae10b91044bf76b40b77d81c169e48e0bbdf6d75San MehatDirectVolume::~DirectVolume() {
53f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehat    PathCollection::iterator it;
54f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehat
55f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehat    for (it = mPaths->begin(); it != mPaths->end(); ++it)
56f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehat        free(*it);
57f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehat    delete mPaths;
58f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehat}
59f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehat
60ae10b91044bf76b40b77d81c169e48e0bbdf6d75San Mehatint DirectVolume::addPath(const char *path) {
61f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehat    mPaths->push_back(strdup(path));
62f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehat    return 0;
63f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehat}
64f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehat
6529d8da8cefa99e436c13295d4c9bad060ca18a6dKen Sumrallvoid DirectVolume::setFlags(int flags) {
6629d8da8cefa99e436c13295d4c9bad060ca18a6dKen Sumrall    mFlags = flags;
6729d8da8cefa99e436c13295d4c9bad060ca18a6dKen Sumrall}
6829d8da8cefa99e436c13295d4c9bad060ca18a6dKen Sumrall
69a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehatdev_t DirectVolume::getDiskDevice() {
70a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat    return MKDEV(mDiskMajor, mDiskMinor);
71a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat}
72a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat
732dfe297ec47559dbe2297a72bea71cf515c03797Mike Lockwooddev_t DirectVolume::getShareDevice() {
742dfe297ec47559dbe2297a72bea71cf515c03797Mike Lockwood    if (mPartIdx != -1) {
752dfe297ec47559dbe2297a72bea71cf515c03797Mike Lockwood        return MKDEV(mDiskMajor, mPartIdx);
762dfe297ec47559dbe2297a72bea71cf515c03797Mike Lockwood    } else {
772dfe297ec47559dbe2297a72bea71cf515c03797Mike Lockwood        return MKDEV(mDiskMajor, mDiskMinor);
782dfe297ec47559dbe2297a72bea71cf515c03797Mike Lockwood    }
792dfe297ec47559dbe2297a72bea71cf515c03797Mike Lockwood}
802dfe297ec47559dbe2297a72bea71cf515c03797Mike Lockwood
81a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehatvoid DirectVolume::handleVolumeShared() {
82a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat    setState(Volume::State_Shared);
83a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat}
84a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat
85a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehatvoid DirectVolume::handleVolumeUnshared() {
86a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat    setState(Volume::State_Idle);
87a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat}
88a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat
89ae10b91044bf76b40b77d81c169e48e0bbdf6d75San Mehatint DirectVolume::handleBlockEvent(NetlinkEvent *evt) {
90fd7f5875129adfe2845f4f3fffb17db3a89eea25San Mehat    const char *dp = evt->findParam("DEVPATH");
91f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehat
92fd7f5875129adfe2845f4f3fffb17db3a89eea25San Mehat    PathCollection::iterator  it;
93f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehat    for (it = mPaths->begin(); it != mPaths->end(); ++it) {
94f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehat        if (!strncmp(dp, *it, strlen(*it))) {
95fd7f5875129adfe2845f4f3fffb17db3a89eea25San Mehat            /* We can handle this disk */
96fd7f5875129adfe2845f4f3fffb17db3a89eea25San Mehat            int action = evt->getAction();
97fd7f5875129adfe2845f4f3fffb17db3a89eea25San Mehat            const char *devtype = evt->findParam("DEVTYPE");
98fd7f5875129adfe2845f4f3fffb17db3a89eea25San Mehat
99a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat            if (action == NetlinkEvent::NlActionAdd) {
100a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat                int major = atoi(evt->findParam("MAJOR"));
101a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat                int minor = atoi(evt->findParam("MINOR"));
102a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat                char nodepath[255];
103a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat
104a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat                snprintf(nodepath,
105a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat                         sizeof(nodepath), "/dev/block/vold/%d:%d",
106a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat                         major, minor);
107a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat                if (createDeviceNode(nodepath, major, minor)) {
10897ac40e4e6f3ed0bd5d6878d7d8d4a54fcaecb76San Mehat                    SLOGE("Error making device node '%s' (%s)", nodepath,
109a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat                                                               strerror(errno));
110a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat                }
111a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat                if (!strcmp(devtype, "disk")) {
112fd7f5875129adfe2845f4f3fffb17db3a89eea25San Mehat                    handleDiskAdded(dp, evt);
113a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat                } else {
114fd7f5875129adfe2845f4f3fffb17db3a89eea25San Mehat                    handlePartitionAdded(dp, evt);
115a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat                }
1163dafc26e4f3adb9607e82ab0bd52ead5f76859a1Magnus Malmborn                /* Send notification iff disk is ready (ie all partitions found) */
1173dafc26e4f3adb9607e82ab0bd52ead5f76859a1Magnus Malmborn                if (getState() == Volume::State_Idle) {
1183dafc26e4f3adb9607e82ab0bd52ead5f76859a1Magnus Malmborn                    char msg[255];
1193dafc26e4f3adb9607e82ab0bd52ead5f76859a1Magnus Malmborn
1203dafc26e4f3adb9607e82ab0bd52ead5f76859a1Magnus Malmborn                    snprintf(msg, sizeof(msg),
1213dafc26e4f3adb9607e82ab0bd52ead5f76859a1Magnus Malmborn                             "Volume %s %s disk inserted (%d:%d)", getLabel(),
1223dafc26e4f3adb9607e82ab0bd52ead5f76859a1Magnus Malmborn                             getMountpoint(), mDiskMajor, mDiskMinor);
1233dafc26e4f3adb9607e82ab0bd52ead5f76859a1Magnus Malmborn                    mVm->getBroadcaster()->sendBroadcast(ResponseCode::VolumeDiskInserted,
1243dafc26e4f3adb9607e82ab0bd52ead5f76859a1Magnus Malmborn                                                         msg, false);
1253dafc26e4f3adb9607e82ab0bd52ead5f76859a1Magnus Malmborn                }
126a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat            } else if (action == NetlinkEvent::NlActionRemove) {
127a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat                if (!strcmp(devtype, "disk")) {
128a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat                    handleDiskRemoved(dp, evt);
129a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat                } else {
130fd7f5875129adfe2845f4f3fffb17db3a89eea25San Mehat                    handlePartitionRemoved(dp, evt);
131a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat                }
132a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat            } else if (action == NetlinkEvent::NlActionChange) {
133a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat                if (!strcmp(devtype, "disk")) {
134a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat                    handleDiskChanged(dp, evt);
135a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat                } else {
136a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat                    handlePartitionChanged(dp, evt);
137a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat                }
138a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat            } else {
13997ac40e4e6f3ed0bd5d6878d7d8d4a54fcaecb76San Mehat                    SLOGW("Ignoring non add/remove/change event");
140f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehat            }
141fd7f5875129adfe2845f4f3fffb17db3a89eea25San Mehat
142f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehat            return 0;
143f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehat        }
144f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehat    }
145f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehat    errno = ENODEV;
146f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehat    return -1;
147f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehat}
148fd7f5875129adfe2845f4f3fffb17db3a89eea25San Mehat
149ae10b91044bf76b40b77d81c169e48e0bbdf6d75San Mehatvoid DirectVolume::handleDiskAdded(const char *devpath, NetlinkEvent *evt) {
150da62e7c00259f6b98696cedb7d031f04951caef0Kenny Root    mDiskMajor = atoi(evt->findParam("MAJOR"));
151da62e7c00259f6b98696cedb7d031f04951caef0Kenny Root    mDiskMinor = atoi(evt->findParam("MINOR"));
1527b8f2db4b07deaaa2f6f5ffbee0386a394032b08San Mehat
1537b8f2db4b07deaaa2f6f5ffbee0386a394032b08San Mehat    const char *tmp = evt->findParam("NPARTS");
1547b8f2db4b07deaaa2f6f5ffbee0386a394032b08San Mehat    if (tmp) {
1557b8f2db4b07deaaa2f6f5ffbee0386a394032b08San Mehat        mDiskNumParts = atoi(tmp);
1567b8f2db4b07deaaa2f6f5ffbee0386a394032b08San Mehat    } else {
15797ac40e4e6f3ed0bd5d6878d7d8d4a54fcaecb76San Mehat        SLOGW("Kernel block uevent missing 'NPARTS'");
1587b8f2db4b07deaaa2f6f5ffbee0386a394032b08San Mehat        mDiskNumParts = 1;
1597b8f2db4b07deaaa2f6f5ffbee0386a394032b08San Mehat    }
1607b8f2db4b07deaaa2f6f5ffbee0386a394032b08San Mehat
161fd7f5875129adfe2845f4f3fffb17db3a89eea25San Mehat    int partmask = 0;
162fd7f5875129adfe2845f4f3fffb17db3a89eea25San Mehat    int i;
16359abc3c56b432089abfe868c04cdbc3b6d28aee2San Mehat    for (i = 1; i <= mDiskNumParts; i++) {
164fd7f5875129adfe2845f4f3fffb17db3a89eea25San Mehat        partmask |= (1 << i);
165fd7f5875129adfe2845f4f3fffb17db3a89eea25San Mehat    }
166fd7f5875129adfe2845f4f3fffb17db3a89eea25San Mehat    mPendingPartMap = partmask;
167fd7f5875129adfe2845f4f3fffb17db3a89eea25San Mehat
168fd7f5875129adfe2845f4f3fffb17db3a89eea25San Mehat    if (mDiskNumParts == 0) {
169a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat#ifdef PARTITION_DEBUG
17097ac40e4e6f3ed0bd5d6878d7d8d4a54fcaecb76San Mehat        SLOGD("Dv::diskIns - No partitions - good to go son!");
171a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat#endif
172fd7f5875129adfe2845f4f3fffb17db3a89eea25San Mehat        setState(Volume::State_Idle);
173fd7f5875129adfe2845f4f3fffb17db3a89eea25San Mehat    } else {
174a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat#ifdef PARTITION_DEBUG
17597ac40e4e6f3ed0bd5d6878d7d8d4a54fcaecb76San Mehat        SLOGD("Dv::diskIns - waiting for %d partitions (mask 0x%x)",
176fd7f5875129adfe2845f4f3fffb17db3a89eea25San Mehat             mDiskNumParts, mPendingPartMap);
177a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat#endif
178fd7f5875129adfe2845f4f3fffb17db3a89eea25San Mehat        setState(Volume::State_Pending);
179fd7f5875129adfe2845f4f3fffb17db3a89eea25San Mehat    }
180fd7f5875129adfe2845f4f3fffb17db3a89eea25San Mehat}
181fd7f5875129adfe2845f4f3fffb17db3a89eea25San Mehat
182ae10b91044bf76b40b77d81c169e48e0bbdf6d75San Mehatvoid DirectVolume::handlePartitionAdded(const char *devpath, NetlinkEvent *evt) {
183da62e7c00259f6b98696cedb7d031f04951caef0Kenny Root    int major = atoi(evt->findParam("MAJOR"));
184da62e7c00259f6b98696cedb7d031f04951caef0Kenny Root    int minor = atoi(evt->findParam("MINOR"));
1857b8f2db4b07deaaa2f6f5ffbee0386a394032b08San Mehat
1867b8f2db4b07deaaa2f6f5ffbee0386a394032b08San Mehat    int part_num;
1877b8f2db4b07deaaa2f6f5ffbee0386a394032b08San Mehat
1887b8f2db4b07deaaa2f6f5ffbee0386a394032b08San Mehat    const char *tmp = evt->findParam("PARTN");
1897b8f2db4b07deaaa2f6f5ffbee0386a394032b08San Mehat
1907b8f2db4b07deaaa2f6f5ffbee0386a394032b08San Mehat    if (tmp) {
1917b8f2db4b07deaaa2f6f5ffbee0386a394032b08San Mehat        part_num = atoi(tmp);
1927b8f2db4b07deaaa2f6f5ffbee0386a394032b08San Mehat    } else {
19397ac40e4e6f3ed0bd5d6878d7d8d4a54fcaecb76San Mehat        SLOGW("Kernel block uevent missing 'PARTN'");
1947b8f2db4b07deaaa2f6f5ffbee0386a394032b08San Mehat        part_num = 1;
1957b8f2db4b07deaaa2f6f5ffbee0386a394032b08San Mehat    }
19659abc3c56b432089abfe868c04cdbc3b6d28aee2San Mehat
197f3d3ce5e53ab7928f4c292c183c417a1bd051151Nick Kralevich    if (part_num > MAX_PARTITIONS || part_num < 1) {
198cc8e96c8dccea1e8041db3146d389175582d3890Nick Kralevich        SLOGE("Invalid 'PARTN' value");
199cc8e96c8dccea1e8041db3146d389175582d3890Nick Kralevich        return;
200f3d3ce5e53ab7928f4c292c183c417a1bd051151Nick Kralevich    }
201f3d3ce5e53ab7928f4c292c183c417a1bd051151Nick Kralevich
2022a5b8ce09b8836a8463ef9beaaff865c36ca5e6aSan Mehat    if (part_num > mDiskNumParts) {
2032a5b8ce09b8836a8463ef9beaaff865c36ca5e6aSan Mehat        mDiskNumParts = part_num;
2042a5b8ce09b8836a8463ef9beaaff865c36ca5e6aSan Mehat    }
2052a5b8ce09b8836a8463ef9beaaff865c36ca5e6aSan Mehat
206dd9b8e92aaf330b48ddb40a7380588ef92b53de6San Mehat    if (major != mDiskMajor) {
20797ac40e4e6f3ed0bd5d6878d7d8d4a54fcaecb76San Mehat        SLOGE("Partition '%s' has a different major than its disk!", devpath);
208dd9b8e92aaf330b48ddb40a7380588ef92b53de6San Mehat        return;
209dd9b8e92aaf330b48ddb40a7380588ef92b53de6San Mehat    }
210a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat#ifdef PARTITION_DEBUG
21197ac40e4e6f3ed0bd5d6878d7d8d4a54fcaecb76San Mehat    SLOGD("Dv:partAdd: part_num = %d, minor = %d\n", part_num, minor);
212a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat#endif
213d11b833201ae72265d52d606fa084841b44e9a65Bruce Beare    if (part_num >= MAX_PARTITIONS) {
214d11b833201ae72265d52d606fa084841b44e9a65Bruce Beare        SLOGE("Dv:partAdd: ignoring part_num = %d (max: %d)\n", part_num, MAX_PARTITIONS-1);
215d766090b7a72562be9e64700e13882663004650eBruce Beare    } else {
216d766090b7a72562be9e64700e13882663004650eBruce Beare        mPartMinors[part_num -1] = minor;
217d766090b7a72562be9e64700e13882663004650eBruce Beare    }
21859abc3c56b432089abfe868c04cdbc3b6d28aee2San Mehat    mPendingPartMap &= ~(1 << part_num);
219d766090b7a72562be9e64700e13882663004650eBruce Beare
22059abc3c56b432089abfe868c04cdbc3b6d28aee2San Mehat    if (!mPendingPartMap) {
221a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat#ifdef PARTITION_DEBUG
22297ac40e4e6f3ed0bd5d6878d7d8d4a54fcaecb76San Mehat        SLOGD("Dv:partAdd: Got all partitions - ready to rock!");
223a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat#endif
2242a5b8ce09b8836a8463ef9beaaff865c36ca5e6aSan Mehat        if (getState() != Volume::State_Formatting) {
2252a5b8ce09b8836a8463ef9beaaff865c36ca5e6aSan Mehat            setState(Volume::State_Idle);
226507d31b86b38dffe7c60ca5c54b5e631f5a7cab3Joseph Lehrer            if (mRetryMount == true) {
227507d31b86b38dffe7c60ca5c54b5e631f5a7cab3Joseph Lehrer                mRetryMount = false;
228507d31b86b38dffe7c60ca5c54b5e631f5a7cab3Joseph Lehrer                mountVol();
229507d31b86b38dffe7c60ca5c54b5e631f5a7cab3Joseph Lehrer            }
2302a5b8ce09b8836a8463ef9beaaff865c36ca5e6aSan Mehat        }
23159abc3c56b432089abfe868c04cdbc3b6d28aee2San Mehat    } else {
232a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat#ifdef PARTITION_DEBUG
23397ac40e4e6f3ed0bd5d6878d7d8d4a54fcaecb76San Mehat        SLOGD("Dv:partAdd: pending mask now = 0x%x", mPendingPartMap);
234a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat#endif
235a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat    }
236a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat}
237a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat
238a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehatvoid DirectVolume::handleDiskChanged(const char *devpath, NetlinkEvent *evt) {
239da62e7c00259f6b98696cedb7d031f04951caef0Kenny Root    int major = atoi(evt->findParam("MAJOR"));
240da62e7c00259f6b98696cedb7d031f04951caef0Kenny Root    int minor = atoi(evt->findParam("MINOR"));
241a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat
242a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat    if ((major != mDiskMajor) || (minor != mDiskMinor)) {
243a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat        return;
244a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat    }
245a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat
24697ac40e4e6f3ed0bd5d6878d7d8d4a54fcaecb76San Mehat    SLOGI("Volume %s disk has changed", getLabel());
2477b8f2db4b07deaaa2f6f5ffbee0386a394032b08San Mehat    const char *tmp = evt->findParam("NPARTS");
2487b8f2db4b07deaaa2f6f5ffbee0386a394032b08San Mehat    if (tmp) {
2497b8f2db4b07deaaa2f6f5ffbee0386a394032b08San Mehat        mDiskNumParts = atoi(tmp);
2507b8f2db4b07deaaa2f6f5ffbee0386a394032b08San Mehat    } else {
25197ac40e4e6f3ed0bd5d6878d7d8d4a54fcaecb76San Mehat        SLOGW("Kernel block uevent missing 'NPARTS'");
2527b8f2db4b07deaaa2f6f5ffbee0386a394032b08San Mehat        mDiskNumParts = 1;
2537b8f2db4b07deaaa2f6f5ffbee0386a394032b08San Mehat    }
2547b8f2db4b07deaaa2f6f5ffbee0386a394032b08San Mehat
255a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat    int partmask = 0;
256a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat    int i;
257a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat    for (i = 1; i <= mDiskNumParts; i++) {
258a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat        partmask |= (1 << i);
259a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat    }
260a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat    mPendingPartMap = partmask;
261a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat
2622a5b8ce09b8836a8463ef9beaaff865c36ca5e6aSan Mehat    if (getState() != Volume::State_Formatting) {
2632a5b8ce09b8836a8463ef9beaaff865c36ca5e6aSan Mehat        if (mDiskNumParts == 0) {
2642a5b8ce09b8836a8463ef9beaaff865c36ca5e6aSan Mehat            setState(Volume::State_Idle);
2652a5b8ce09b8836a8463ef9beaaff865c36ca5e6aSan Mehat        } else {
2662a5b8ce09b8836a8463ef9beaaff865c36ca5e6aSan Mehat            setState(Volume::State_Pending);
2672a5b8ce09b8836a8463ef9beaaff865c36ca5e6aSan Mehat        }
26859abc3c56b432089abfe868c04cdbc3b6d28aee2San Mehat    }
269a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat}
270a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat
271a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehatvoid DirectVolume::handlePartitionChanged(const char *devpath, NetlinkEvent *evt) {
272da62e7c00259f6b98696cedb7d031f04951caef0Kenny Root    int major = atoi(evt->findParam("MAJOR"));
273da62e7c00259f6b98696cedb7d031f04951caef0Kenny Root    int minor = atoi(evt->findParam("MINOR"));
27497ac40e4e6f3ed0bd5d6878d7d8d4a54fcaecb76San Mehat    SLOGD("Volume %s %s partition %d:%d changed\n", getLabel(), getMountpoint(), major, minor);
275fd7f5875129adfe2845f4f3fffb17db3a89eea25San Mehat}
276fd7f5875129adfe2845f4f3fffb17db3a89eea25San Mehat
277ae10b91044bf76b40b77d81c169e48e0bbdf6d75San Mehatvoid DirectVolume::handleDiskRemoved(const char *devpath, NetlinkEvent *evt) {
278da62e7c00259f6b98696cedb7d031f04951caef0Kenny Root    int major = atoi(evt->findParam("MAJOR"));
279da62e7c00259f6b98696cedb7d031f04951caef0Kenny Root    int minor = atoi(evt->findParam("MINOR"));
280a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat    char msg[255];
281627366196859339d72ab9f68a817dd395a13468fLars Svensson    bool enabled;
282627366196859339d72ab9f68a817dd395a13468fLars Svensson
283627366196859339d72ab9f68a817dd395a13468fLars Svensson    if (mVm->shareEnabled(getLabel(), "ums", &enabled) == 0 && enabled) {
284627366196859339d72ab9f68a817dd395a13468fLars Svensson        mVm->unshareVolume(getLabel(), "ums");
285627366196859339d72ab9f68a817dd395a13468fLars Svensson    }
286a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat
28797ac40e4e6f3ed0bd5d6878d7d8d4a54fcaecb76San Mehat    SLOGD("Volume %s %s disk %d:%d removed\n", getLabel(), getMountpoint(), major, minor);
288a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat    snprintf(msg, sizeof(msg), "Volume %s %s disk removed (%d:%d)",
289a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat             getLabel(), getMountpoint(), major, minor);
290a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat    mVm->getBroadcaster()->sendBroadcast(ResponseCode::VolumeDiskRemoved,
291a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat                                             msg, false);
292a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat    setState(Volume::State_NoMedia);
293fd7f5875129adfe2845f4f3fffb17db3a89eea25San Mehat}
294fd7f5875129adfe2845f4f3fffb17db3a89eea25San Mehat
295ae10b91044bf76b40b77d81c169e48e0bbdf6d75San Mehatvoid DirectVolume::handlePartitionRemoved(const char *devpath, NetlinkEvent *evt) {
296da62e7c00259f6b98696cedb7d031f04951caef0Kenny Root    int major = atoi(evt->findParam("MAJOR"));
297da62e7c00259f6b98696cedb7d031f04951caef0Kenny Root    int minor = atoi(evt->findParam("MINOR"));
298a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat    char msg[255];
29975a3e1a95af0a2790de1b12aeca0008bfdc61649Ethan    int state;
300a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat
30197ac40e4e6f3ed0bd5d6878d7d8d4a54fcaecb76San Mehat    SLOGD("Volume %s %s partition %d:%d removed\n", getLabel(), getMountpoint(), major, minor);
302a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat
303a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat    /*
304a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat     * The framework doesn't need to get notified of
305a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat     * partition removal unless it's mounted. Otherwise
306a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat     * the removal notification will be sent on the Disk
307a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat     * itself
308a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat     */
30975a3e1a95af0a2790de1b12aeca0008bfdc61649Ethan    state = getState();
31075a3e1a95af0a2790de1b12aeca0008bfdc61649Ethan    if (state != Volume::State_Mounted && state != Volume::State_Shared) {
311a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat        return;
312a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat    }
313a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat
314a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat    if ((dev_t) MKDEV(major, minor) == mCurrentlyMountedKdev) {
315a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat        /*
316a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat         * Yikes, our mounted partition is going away!
317a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat         */
318a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat
319a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat        snprintf(msg, sizeof(msg), "Volume %s %s bad removal (%d:%d)",
320a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat                 getLabel(), getMountpoint(), major, minor);
321a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat        mVm->getBroadcaster()->sendBroadcast(ResponseCode::VolumeBadRemoval,
322a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat                                             msg, false);
3231a06edaf4db4e9c520624bcc06e0e13ee470d90eSan Mehat
3241a06edaf4db4e9c520624bcc06e0e13ee470d90eSan Mehat	if (mVm->cleanupAsec(this, true)) {
3251a06edaf4db4e9c520624bcc06e0e13ee470d90eSan Mehat            SLOGE("Failed to cleanup ASEC - unmount will probably fail!");
3261a06edaf4db4e9c520624bcc06e0e13ee470d90eSan Mehat        }
3271a06edaf4db4e9c520624bcc06e0e13ee470d90eSan Mehat
3280b8b59719357fb80c330442787f7d5b1e332263bKen Sumrall        if (Volume::unmountVol(true, false)) {
32997ac40e4e6f3ed0bd5d6878d7d8d4a54fcaecb76San Mehat            SLOGE("Failed to unmount volume on bad removal (%s)",
330a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat                 strerror(errno));
331a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat            // XXX: At this point we're screwed for now
332a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat        } else {
33397ac40e4e6f3ed0bd5d6878d7d8d4a54fcaecb76San Mehat            SLOGD("Crisis averted");
334a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat        }
33575a3e1a95af0a2790de1b12aeca0008bfdc61649Ethan    } else if (state == Volume::State_Shared) {
33675a3e1a95af0a2790de1b12aeca0008bfdc61649Ethan        /* removed during mass storage */
33775a3e1a95af0a2790de1b12aeca0008bfdc61649Ethan        snprintf(msg, sizeof(msg), "Volume %s bad removal (%d:%d)",
33875a3e1a95af0a2790de1b12aeca0008bfdc61649Ethan                 getLabel(), major, minor);
33975a3e1a95af0a2790de1b12aeca0008bfdc61649Ethan        mVm->getBroadcaster()->sendBroadcast(ResponseCode::VolumeBadRemoval,
34075a3e1a95af0a2790de1b12aeca0008bfdc61649Ethan                                             msg, false);
34175a3e1a95af0a2790de1b12aeca0008bfdc61649Ethan
34275a3e1a95af0a2790de1b12aeca0008bfdc61649Ethan        if (mVm->unshareVolume(getLabel(), "ums")) {
34375a3e1a95af0a2790de1b12aeca0008bfdc61649Ethan            SLOGE("Failed to unshare volume on bad removal (%s)",
34475a3e1a95af0a2790de1b12aeca0008bfdc61649Ethan                strerror(errno));
34575a3e1a95af0a2790de1b12aeca0008bfdc61649Ethan        } else {
34675a3e1a95af0a2790de1b12aeca0008bfdc61649Ethan            SLOGD("Crisis averted");
34775a3e1a95af0a2790de1b12aeca0008bfdc61649Ethan        }
348a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat    }
349fd7f5875129adfe2845f4f3fffb17db3a89eea25San Mehat}
35049e2bce5b74129c26a35e25d4693cbfe98c4688eSan Mehat
351dd9b8e92aaf330b48ddb40a7380588ef92b53de6San Mehat/*
352a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat * Called from base to get a list of devicenodes for mounting
353dd9b8e92aaf330b48ddb40a7380588ef92b53de6San Mehat */
354a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehatint DirectVolume::getDeviceNodes(dev_t *devs, int max) {
355dd9b8e92aaf330b48ddb40a7380588ef92b53de6San Mehat
356dd9b8e92aaf330b48ddb40a7380588ef92b53de6San Mehat    if (mPartIdx == -1) {
357a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat        // If the disk has no partitions, try the disk itself
358dd9b8e92aaf330b48ddb40a7380588ef92b53de6San Mehat        if (!mDiskNumParts) {
359a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat            devs[0] = MKDEV(mDiskMajor, mDiskMinor);
360a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat            return 1;
361dd9b8e92aaf330b48ddb40a7380588ef92b53de6San Mehat        }
362dd9b8e92aaf330b48ddb40a7380588ef92b53de6San Mehat
363a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat        int i;
364a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat        for (i = 0; i < mDiskNumParts; i++) {
365a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat            if (i == max)
366a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat                break;
367a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat            devs[i] = MKDEV(mDiskMajor, mPartMinors[i]);
368a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat        }
369a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat        return mDiskNumParts;
370dd9b8e92aaf330b48ddb40a7380588ef92b53de6San Mehat    }
371a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat    devs[0] = MKDEV(mDiskMajor, mPartMinors[mPartIdx -1]);
372a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat    return 1;
37349e2bce5b74129c26a35e25d4693cbfe98c4688eSan Mehat}
37429d8da8cefa99e436c13295d4c9bad060ca18a6dKen Sumrall
37529d8da8cefa99e436c13295d4c9bad060ca18a6dKen Sumrall/*
37629d8da8cefa99e436c13295d4c9bad060ca18a6dKen Sumrall * Called from base to update device info,
37729d8da8cefa99e436c13295d4c9bad060ca18a6dKen Sumrall * e.g. When setting up an dm-crypt mapping for the sd card.
37829d8da8cefa99e436c13295d4c9bad060ca18a6dKen Sumrall */
37929d8da8cefa99e436c13295d4c9bad060ca18a6dKen Sumrallint DirectVolume::updateDeviceInfo(char *new_path, int new_major, int new_minor)
38029d8da8cefa99e436c13295d4c9bad060ca18a6dKen Sumrall{
38129d8da8cefa99e436c13295d4c9bad060ca18a6dKen Sumrall    PathCollection::iterator it;
38229d8da8cefa99e436c13295d4c9bad060ca18a6dKen Sumrall
38329d8da8cefa99e436c13295d4c9bad060ca18a6dKen Sumrall    if (mPartIdx == -1) {
38429d8da8cefa99e436c13295d4c9bad060ca18a6dKen Sumrall        SLOGE("Can only change device info on a partition\n");
38529d8da8cefa99e436c13295d4c9bad060ca18a6dKen Sumrall        return -1;
38629d8da8cefa99e436c13295d4c9bad060ca18a6dKen Sumrall    }
38729d8da8cefa99e436c13295d4c9bad060ca18a6dKen Sumrall
38829d8da8cefa99e436c13295d4c9bad060ca18a6dKen Sumrall    /*
38929d8da8cefa99e436c13295d4c9bad060ca18a6dKen Sumrall     * This is to change the sysfs path associated with a partition, in particular,
39029d8da8cefa99e436c13295d4c9bad060ca18a6dKen Sumrall     * for an internal SD card partition that is encrypted.  Thus, the list is
39129d8da8cefa99e436c13295d4c9bad060ca18a6dKen Sumrall     * expected to be only 1 entry long.  Check that and bail if not.
39229d8da8cefa99e436c13295d4c9bad060ca18a6dKen Sumrall     */
39329d8da8cefa99e436c13295d4c9bad060ca18a6dKen Sumrall    if (mPaths->size() != 1) {
39429d8da8cefa99e436c13295d4c9bad060ca18a6dKen Sumrall        SLOGE("Cannot change path if there are more than one for a volume\n");
39529d8da8cefa99e436c13295d4c9bad060ca18a6dKen Sumrall        return -1;
39629d8da8cefa99e436c13295d4c9bad060ca18a6dKen Sumrall    }
39729d8da8cefa99e436c13295d4c9bad060ca18a6dKen Sumrall
39829d8da8cefa99e436c13295d4c9bad060ca18a6dKen Sumrall    it = mPaths->begin();
39929d8da8cefa99e436c13295d4c9bad060ca18a6dKen Sumrall    free(*it); /* Free the string storage */
40029d8da8cefa99e436c13295d4c9bad060ca18a6dKen Sumrall    mPaths->erase(it); /* Remove it from the list */
40129d8da8cefa99e436c13295d4c9bad060ca18a6dKen Sumrall    addPath(new_path); /* Put the new path on the list */
40229d8da8cefa99e436c13295d4c9bad060ca18a6dKen Sumrall
4030b8b59719357fb80c330442787f7d5b1e332263bKen Sumrall    /* Save away original info so we can restore it when doing factory reset.
4040b8b59719357fb80c330442787f7d5b1e332263bKen Sumrall     * Then, when doing the format, it will format the original device in the
4050b8b59719357fb80c330442787f7d5b1e332263bKen Sumrall     * clear, otherwise it just formats the encrypted device which is not
4060b8b59719357fb80c330442787f7d5b1e332263bKen Sumrall     * readable when the device boots unencrypted after the reset.
4070b8b59719357fb80c330442787f7d5b1e332263bKen Sumrall     */
4080b8b59719357fb80c330442787f7d5b1e332263bKen Sumrall    mOrigDiskMajor = mDiskMajor;
4090b8b59719357fb80c330442787f7d5b1e332263bKen Sumrall    mOrigDiskMinor = mDiskMinor;
4100b8b59719357fb80c330442787f7d5b1e332263bKen Sumrall    mOrigPartIdx = mPartIdx;
4110b8b59719357fb80c330442787f7d5b1e332263bKen Sumrall    memcpy(mOrigPartMinors, mPartMinors, sizeof(mPartMinors));
4120b8b59719357fb80c330442787f7d5b1e332263bKen Sumrall
41329d8da8cefa99e436c13295d4c9bad060ca18a6dKen Sumrall    mDiskMajor = new_major;
41429d8da8cefa99e436c13295d4c9bad060ca18a6dKen Sumrall    mDiskMinor = new_minor;
41529d8da8cefa99e436c13295d4c9bad060ca18a6dKen Sumrall    /* Ugh, virual block devices don't use minor 0 for whole disk and minor > 0 for
41629d8da8cefa99e436c13295d4c9bad060ca18a6dKen Sumrall     * partition number.  They don't have partitions, they are just virtual block
41729d8da8cefa99e436c13295d4c9bad060ca18a6dKen Sumrall     * devices, and minor number 0 is the first dm-crypt device.  Luckily the first
41829d8da8cefa99e436c13295d4c9bad060ca18a6dKen Sumrall     * dm-crypt device is for the userdata partition, which gets minor number 0, and
41929d8da8cefa99e436c13295d4c9bad060ca18a6dKen Sumrall     * it is not managed by vold.  So the next device is minor number one, which we
42029d8da8cefa99e436c13295d4c9bad060ca18a6dKen Sumrall     * will call partition one.
42129d8da8cefa99e436c13295d4c9bad060ca18a6dKen Sumrall     */
42229d8da8cefa99e436c13295d4c9bad060ca18a6dKen Sumrall    mPartIdx = new_minor;
42329d8da8cefa99e436c13295d4c9bad060ca18a6dKen Sumrall    mPartMinors[new_minor-1] = new_minor;
42429d8da8cefa99e436c13295d4c9bad060ca18a6dKen Sumrall
42529d8da8cefa99e436c13295d4c9bad060ca18a6dKen Sumrall    mIsDecrypted = 1;
42629d8da8cefa99e436c13295d4c9bad060ca18a6dKen Sumrall
42729d8da8cefa99e436c13295d4c9bad060ca18a6dKen Sumrall    return 0;
42829d8da8cefa99e436c13295d4c9bad060ca18a6dKen Sumrall}
42929d8da8cefa99e436c13295d4c9bad060ca18a6dKen Sumrall
43029d8da8cefa99e436c13295d4c9bad060ca18a6dKen Sumrall/*
4310b8b59719357fb80c330442787f7d5b1e332263bKen Sumrall * Called from base to revert device info to the way it was before a
4320b8b59719357fb80c330442787f7d5b1e332263bKen Sumrall * crypto mapping was created for it.
4330b8b59719357fb80c330442787f7d5b1e332263bKen Sumrall */
4340b8b59719357fb80c330442787f7d5b1e332263bKen Sumrallvoid DirectVolume::revertDeviceInfo(void)
4350b8b59719357fb80c330442787f7d5b1e332263bKen Sumrall{
4360b8b59719357fb80c330442787f7d5b1e332263bKen Sumrall    if (mIsDecrypted) {
4370b8b59719357fb80c330442787f7d5b1e332263bKen Sumrall        mDiskMajor = mOrigDiskMajor;
4380b8b59719357fb80c330442787f7d5b1e332263bKen Sumrall        mDiskMinor = mOrigDiskMinor;
4390b8b59719357fb80c330442787f7d5b1e332263bKen Sumrall        mPartIdx = mOrigPartIdx;
4400b8b59719357fb80c330442787f7d5b1e332263bKen Sumrall        memcpy(mPartMinors, mOrigPartMinors, sizeof(mPartMinors));
4410b8b59719357fb80c330442787f7d5b1e332263bKen Sumrall
4420b8b59719357fb80c330442787f7d5b1e332263bKen Sumrall        mIsDecrypted = 0;
4430b8b59719357fb80c330442787f7d5b1e332263bKen Sumrall    }
4440b8b59719357fb80c330442787f7d5b1e332263bKen Sumrall
4450b8b59719357fb80c330442787f7d5b1e332263bKen Sumrall    return;
4460b8b59719357fb80c330442787f7d5b1e332263bKen Sumrall}
4470b8b59719357fb80c330442787f7d5b1e332263bKen Sumrall
4480b8b59719357fb80c330442787f7d5b1e332263bKen Sumrall/*
44929d8da8cefa99e436c13295d4c9bad060ca18a6dKen Sumrall * Called from base to give cryptfs all the info it needs to encrypt eligible volumes
45029d8da8cefa99e436c13295d4c9bad060ca18a6dKen Sumrall */
45129d8da8cefa99e436c13295d4c9bad060ca18a6dKen Sumrallint DirectVolume::getVolInfo(struct volume_info *v)
45229d8da8cefa99e436c13295d4c9bad060ca18a6dKen Sumrall{
45329d8da8cefa99e436c13295d4c9bad060ca18a6dKen Sumrall    strcpy(v->label, mLabel);
45429d8da8cefa99e436c13295d4c9bad060ca18a6dKen Sumrall    strcpy(v->mnt_point, mMountpoint);
45529d8da8cefa99e436c13295d4c9bad060ca18a6dKen Sumrall    v->flags=mFlags;
45629d8da8cefa99e436c13295d4c9bad060ca18a6dKen Sumrall    /* Other fields of struct volume_info are filled in by the caller or cryptfs.c */
45729d8da8cefa99e436c13295d4c9bad060ca18a6dKen Sumrall
45829d8da8cefa99e436c13295d4c9bad060ca18a6dKen Sumrall    return 0;
45929d8da8cefa99e436c13295d4c9bad060ca18a6dKen Sumrall}
460