Skip to content

Commit f1b736b

Browse files
author
San Mehat
committed
system: vold2: Initial skeleton for vold2.
Let there be light. Signed-off-by: San Mehat <[email protected]>
1 parent 8f8ba4d commit f1b736b

20 files changed

+1332
-0
lines changed

Android.mk

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
BUILD_VOLD2 := false
2+
ifeq ($(BUILD_VOLD2),true)
3+
4+
LOCAL_PATH:= $(call my-dir)
5+
6+
include $(CLEAR_VARS)
7+
8+
LOCAL_SRC_FILES:= \
9+
main.cpp \
10+
VolumeManager.cpp \
11+
CommandListener.cpp \
12+
VoldCommand.cpp \
13+
NetlinkManager.cpp \
14+
NetlinkHandler.cpp \
15+
BlockDevice.cpp \
16+
Volume.cpp \
17+
DeviceVolume.cpp
18+
19+
LOCAL_MODULE:= vold
20+
21+
LOCAL_C_INCLUDES := $(KERNEL_HEADERS) -I../../frameworks/base/include/
22+
23+
LOCAL_CFLAGS :=
24+
25+
LOCAL_SHARED_LIBRARIES := libsysutils
26+
27+
include $(BUILD_EXECUTABLE)
28+
29+
include $(CLEAR_VARS)
30+
LOCAL_SRC_FILES:= \
31+
vdc.c \
32+
33+
LOCAL_MODULE:= vdc
34+
35+
LOCAL_C_INCLUDES := $(KERNEL_HEADERS)
36+
37+
LOCAL_CFLAGS :=
38+
39+
LOCAL_SHARED_LIBRARIES := libcutils
40+
41+
include $(BUILD_EXECUTABLE)
42+
43+
endif # ifeq ($(BUILD_VOLD,true)

BlockDevice.cpp

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
#include <stdio.h>
18+
#include <errno.h>
19+
#include <string.h>
20+
21+
#define LOG_TAG "Vold"
22+
23+
#include <cutils/log.h>
24+
25+
#include "BlockDevice.h"
26+
27+
BlockDevice::BlockDevice(const char *devpath, int major, int minor) {
28+
mDevpath = strdup(devpath);
29+
mMajor = major;
30+
mMinor = minor;
31+
}
32+
33+
BlockDevice::~BlockDevice() {
34+
free(mDevpath);
35+
}
36+

BlockDevice.h

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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 _BLKDEVICE_H
18+
#define _BLKDEVICE_H
19+
20+
#include <utils/List.h>
21+
22+
class BlockDevice {
23+
24+
char *mDevpath;
25+
int mMajor;
26+
int mMinor;
27+
28+
public:
29+
BlockDevice(const char *devpath, int major, int minor);
30+
virtual ~BlockDevice();
31+
32+
const char *getDevpath() { return mDevpath; }
33+
int getMajor() { return mMajor; }
34+
int getMinor() { return mMinor; }
35+
};
36+
37+
typedef android::List<BlockDevice *> BlockDeviceCollection;
38+
39+
#endif

CommandListener.cpp

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
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+
#include <stdlib.h>
18+
#include <sys/socket.h>
19+
#include <netinet/in.h>
20+
#include <arpa/inet.h>
21+
#include <errno.h>
22+
23+
#define LOG_TAG "CommandListener"
24+
#include <cutils/log.h>
25+
26+
#include <sysutils/SocketClient.h>
27+
28+
#include "CommandListener.h"
29+
#include "VolumeManager.h"
30+
#include "ErrorCode.h"
31+
32+
CommandListener::CommandListener() :
33+
FrameworkListener("vold") {
34+
registerCmd(new ListVolumesCmd());
35+
registerCmd(new MountVolumeCmd());
36+
registerCmd(new UnmountVolumeCmd());
37+
registerCmd(new ShareVolumeCmd());
38+
registerCmd(new UnshareVolumeCmd());
39+
}
40+
41+
CommandListener::ListVolumesCmd::ListVolumesCmd() :
42+
VoldCommand("list_volumes") {
43+
}
44+
45+
int CommandListener::ListVolumesCmd::runCommand(SocketClient *cli,
46+
int argc, char **argv) {
47+
return VolumeManager::Instance()->listVolumes(cli);
48+
}
49+
50+
CommandListener::MountVolumeCmd::MountVolumeCmd() :
51+
VoldCommand("mount_volume") {
52+
}
53+
54+
int CommandListener::MountVolumeCmd::runCommand(SocketClient *cli,
55+
int argc, char **argv) {
56+
VolumeManager *nm = VolumeManager::Instance();
57+
errno = ENOSYS;
58+
cli->sendMsg(ErrorCode::OperationFailed, "Failed to mount volume", true);
59+
return 0;
60+
}
61+
62+
CommandListener::UnmountVolumeCmd::UnmountVolumeCmd() :
63+
VoldCommand("unmount_volume") {
64+
}
65+
66+
int CommandListener::UnmountVolumeCmd::runCommand(SocketClient *cli,
67+
int argc, char **argv) {
68+
VolumeManager *nm = VolumeManager::Instance();
69+
errno = ENOSYS;
70+
cli->sendMsg(ErrorCode::OperationFailed, "Failed to unmount volume", true);
71+
return 0;
72+
}
73+
74+
CommandListener::ShareVolumeCmd::ShareVolumeCmd() :
75+
VoldCommand("share_volume") {
76+
}
77+
78+
int CommandListener::ShareVolumeCmd::runCommand(SocketClient *cli,
79+
int argc, char **argv) {
80+
VolumeManager *nm = VolumeManager::Instance();
81+
errno = ENOSYS;
82+
cli->sendMsg(ErrorCode::OperationFailed, "Failed to share volume", true);
83+
return 0;
84+
}
85+
86+
CommandListener::UnshareVolumeCmd::UnshareVolumeCmd() :
87+
VoldCommand("unshare_volume") {
88+
}
89+
90+
int CommandListener::UnshareVolumeCmd::runCommand(SocketClient *cli,
91+
int argc, char **argv) {
92+
VolumeManager *nm = VolumeManager::Instance();
93+
errno = ENOSYS;
94+
cli->sendMsg(ErrorCode::OperationFailed, "Failed to unshare volume", true);
95+
return 0;
96+
}

CommandListener.h

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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 _COMMANDLISTENER_H__
18+
#define _COMMANDLISTENER_H__
19+
20+
#include <sysutils/FrameworkListener.h>
21+
#include "VoldCommand.h"
22+
23+
class CommandListener : public FrameworkListener {
24+
public:
25+
CommandListener();
26+
virtual ~CommandListener() {}
27+
28+
private:
29+
30+
class ListVolumesCmd : public VoldCommand {
31+
public:
32+
ListVolumesCmd();
33+
virtual ~ListVolumesCmd() {}
34+
int runCommand(SocketClient *c, int argc, char ** argv);
35+
};
36+
37+
class MountVolumeCmd : public VoldCommand {
38+
public:
39+
MountVolumeCmd();
40+
virtual ~MountVolumeCmd() {}
41+
int runCommand(SocketClient *c, int argc, char ** argv);
42+
};
43+
44+
class UnmountVolumeCmd : public VoldCommand {
45+
public:
46+
UnmountVolumeCmd();
47+
virtual ~UnmountVolumeCmd() {}
48+
int runCommand(SocketClient *c, int argc, char ** argv);
49+
};
50+
51+
class ShareVolumeCmd : public VoldCommand {
52+
public:
53+
ShareVolumeCmd();
54+
virtual ~ShareVolumeCmd() {}
55+
int runCommand(SocketClient *c, int argc, char ** argv);
56+
};
57+
58+
class UnshareVolumeCmd : public VoldCommand {
59+
public:
60+
UnshareVolumeCmd();
61+
virtual ~UnshareVolumeCmd() {}
62+
int runCommand(SocketClient *c, int argc, char ** argv);
63+
};
64+
65+
};
66+
67+
#endif

DeviceVolume.cpp

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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+
#include <stdio.h>
18+
#include <errno.h>
19+
#include <string.h>
20+
21+
#define LOG_TAG "Vold"
22+
23+
#include <cutils/log.h>
24+
25+
#include "DeviceVolume.h"
26+
27+
DeviceVolume::DeviceVolume(const char *label, const char *mount_point, int partIdx) :
28+
Volume(label, mount_point) {
29+
mPartIdx = partIdx;
30+
31+
mPaths = new PathCollection();
32+
}
33+
34+
DeviceVolume::~DeviceVolume() {
35+
PathCollection::iterator it;
36+
37+
for (it = mPaths->begin(); it != mPaths->end(); ++it)
38+
free(*it);
39+
delete mPaths;
40+
}
41+
42+
int DeviceVolume::addPath(const char *path) {
43+
mPaths->push_back(strdup(path));
44+
return 0;
45+
}
46+
47+
int DeviceVolume::handleDiskInsertion(const char *dp, int maj, int min,
48+
int nr_parts) {
49+
PathCollection::iterator it;
50+
51+
LOGD("Dv::diskInsertion - %s %d %d %d", dp, maj, min, nr_parts);
52+
for (it = mPaths->begin(); it != mPaths->end(); ++it) {
53+
LOGD("Dv::chk %s", *it);
54+
if (!strncmp(dp, *it, strlen(*it))) {
55+
/*
56+
* We can handle this disk. If there are no partitions then we're
57+
* good to go son!
58+
*/
59+
mDiskMaj = maj;
60+
mDiskNumParts = nr_parts;
61+
if (nr_parts == 0) {
62+
LOGD("Dv::diskIns - No partitions - good to go");
63+
setState(Volume::State_Idle);
64+
} else {
65+
LOGD("Dv::diskIns - waiting for %d partitions", nr_parts);
66+
setState(Volume::State_Pending);
67+
}
68+
return 0;
69+
}
70+
}
71+
errno = ENODEV;
72+
return -1;
73+
}

0 commit comments

Comments
 (0)