vold: Clean up asec command response and add support for 'StorageBusy'
Signed-off-by: San Mehat <san@google.com>
This commit is contained in:
parent
4ba8948dc1
commit
8f2875b297
4 changed files with 61 additions and 51 deletions
|
@ -24,7 +24,8 @@ LOCAL_SRC_FILES:= \
|
||||||
geom_mbr_enc.c \
|
geom_mbr_enc.c \
|
||||||
Fat.cpp \
|
Fat.cpp \
|
||||||
Loop.cpp \
|
Loop.cpp \
|
||||||
Devmapper.cpp
|
Devmapper.cpp \
|
||||||
|
ResponseCode.cpp
|
||||||
|
|
||||||
LOCAL_MODULE:= vold
|
LOCAL_MODULE:= vold
|
||||||
|
|
||||||
|
|
|
@ -88,21 +88,8 @@ int CommandListener::VolumeCmd::runCommand(SocketClient *cli,
|
||||||
if (!rc) {
|
if (!rc) {
|
||||||
cli->sendMsg(ResponseCode::CommandOkay, "volume operation succeeded", false);
|
cli->sendMsg(ResponseCode::CommandOkay, "volume operation succeeded", false);
|
||||||
} else {
|
} else {
|
||||||
/*
|
int erno = errno;
|
||||||
* Failed
|
rc = ResponseCode::convertFromErrno();
|
||||||
*/
|
|
||||||
if (errno == ENODEV) {
|
|
||||||
rc = ResponseCode::OpFailedNoMedia;
|
|
||||||
} else if (errno == ENODATA) {
|
|
||||||
rc = ResponseCode::OpFailedMediaBlank;
|
|
||||||
} else if (errno == EIO) {
|
|
||||||
rc = ResponseCode::OpFailedMediaCorrupt;
|
|
||||||
} else if (errno == EBUSY) {
|
|
||||||
rc = ResponseCode::OpFailedVolBusy;
|
|
||||||
} else {
|
|
||||||
LOGW("Returning OperationFailed - no handler for errno %d", errno);
|
|
||||||
rc = ResponseCode::OperationFailed;
|
|
||||||
}
|
|
||||||
cli->sendMsg(rc, "volume operation failed", true);
|
cli->sendMsg(rc, "volume operation failed", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -223,7 +210,6 @@ int CommandListener::AsecCmd::runCommand(SocketClient *cli,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
closedir(d);
|
closedir(d);
|
||||||
cli->sendMsg(ResponseCode::CommandOkay, "ASEC listing complete", false);
|
|
||||||
} else if (!strcmp(argv[1], "create")) {
|
} else if (!strcmp(argv[1], "create")) {
|
||||||
if (argc != 7) {
|
if (argc != 7) {
|
||||||
cli->sendMsg(ResponseCode::CommandSyntaxError,
|
cli->sendMsg(ResponseCode::CommandSyntaxError,
|
||||||
|
@ -232,21 +218,13 @@ int CommandListener::AsecCmd::runCommand(SocketClient *cli,
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int numSectors = (atoi(argv[3]) * (1024 * 1024)) / 512;
|
unsigned int numSectors = (atoi(argv[3]) * (1024 * 1024)) / 512;
|
||||||
if (vm->createAsec(argv[2], numSectors, argv[4], argv[5], atoi(argv[6]))) {
|
rc = vm->createAsec(argv[2], numSectors, argv[4], argv[5], atoi(argv[6]));
|
||||||
cli->sendMsg(ResponseCode::OperationFailed, "Container creation failed", true);
|
|
||||||
} else {
|
|
||||||
cli->sendMsg(ResponseCode::CommandOkay, "Container created", false);
|
|
||||||
}
|
|
||||||
} else if (!strcmp(argv[1], "finalize")) {
|
} else if (!strcmp(argv[1], "finalize")) {
|
||||||
if (argc != 3) {
|
if (argc != 3) {
|
||||||
cli->sendMsg(ResponseCode::CommandSyntaxError, "Usage: asec finalize <container-id>", false);
|
cli->sendMsg(ResponseCode::CommandSyntaxError, "Usage: asec finalize <container-id>", false);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (vm->finalizeAsec(argv[2])) {
|
rc = vm->finalizeAsec(argv[2]);
|
||||||
cli->sendMsg(ResponseCode::OperationFailed, "Container finalize failed", true);
|
|
||||||
} else {
|
|
||||||
cli->sendMsg(ResponseCode::CommandOkay, "Container finalized", false);
|
|
||||||
}
|
|
||||||
} else if (!strcmp(argv[1], "destroy")) {
|
} else if (!strcmp(argv[1], "destroy")) {
|
||||||
if (argc < 3) {
|
if (argc < 3) {
|
||||||
cli->sendMsg(ResponseCode::CommandSyntaxError, "Usage: asec destroy <container-id> [force]", false);
|
cli->sendMsg(ResponseCode::CommandSyntaxError, "Usage: asec destroy <container-id> [force]", false);
|
||||||
|
@ -256,25 +234,14 @@ int CommandListener::AsecCmd::runCommand(SocketClient *cli,
|
||||||
if (argc > 3 && !strcmp(argv[3], "force")) {
|
if (argc > 3 && !strcmp(argv[3], "force")) {
|
||||||
force = true;
|
force = true;
|
||||||
}
|
}
|
||||||
if (vm->destroyAsec(argv[2], force)) {
|
rc = vm->destroyAsec(argv[2], force);
|
||||||
cli->sendMsg(ResponseCode::OperationFailed, "Container destroy failed", true);
|
|
||||||
} else {
|
|
||||||
cli->sendMsg(ResponseCode::CommandOkay, "Container destroyed", false);
|
|
||||||
}
|
|
||||||
} else if (!strcmp(argv[1], "mount")) {
|
} else if (!strcmp(argv[1], "mount")) {
|
||||||
if (argc != 5) {
|
if (argc != 5) {
|
||||||
cli->sendMsg(ResponseCode::CommandSyntaxError,
|
cli->sendMsg(ResponseCode::CommandSyntaxError,
|
||||||
"Usage: asec mount <namespace-id> <key> <ownerUid>", false);
|
"Usage: asec mount <namespace-id> <key> <ownerUid>", false);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
rc = vm->mountAsec(argv[2], argv[3], atoi(argv[4]));
|
||||||
int rc = vm->mountAsec(argv[2], argv[3], atoi(argv[4]));
|
|
||||||
|
|
||||||
if (rc < 0) {
|
|
||||||
cli->sendMsg(ResponseCode::OperationFailed, "Mount failed", true);
|
|
||||||
} else {
|
|
||||||
cli->sendMsg(ResponseCode::CommandOkay, "Mount succeeded", false);
|
|
||||||
}
|
|
||||||
} else if (!strcmp(argv[1], "unmount")) {
|
} else if (!strcmp(argv[1], "unmount")) {
|
||||||
if (argc < 3) {
|
if (argc < 3) {
|
||||||
cli->sendMsg(ResponseCode::CommandSyntaxError, "Usage: asec unmount <container-id> [force]", false);
|
cli->sendMsg(ResponseCode::CommandSyntaxError, "Usage: asec unmount <container-id> [force]", false);
|
||||||
|
@ -284,22 +251,14 @@ int CommandListener::AsecCmd::runCommand(SocketClient *cli,
|
||||||
if (argc > 3 && !strcmp(argv[3], "force")) {
|
if (argc > 3 && !strcmp(argv[3], "force")) {
|
||||||
force = true;
|
force = true;
|
||||||
}
|
}
|
||||||
if (vm->unmountAsec(argv[2], force)) {
|
rc = vm->unmountAsec(argv[2], force);
|
||||||
cli->sendMsg(ResponseCode::OperationFailed, "Container unmount failed", true);
|
|
||||||
} else {
|
|
||||||
cli->sendMsg(ResponseCode::CommandOkay, "Container unmounted", false);
|
|
||||||
}
|
|
||||||
} else if (!strcmp(argv[1], "rename")) {
|
} else if (!strcmp(argv[1], "rename")) {
|
||||||
if (argc != 4) {
|
if (argc != 4) {
|
||||||
cli->sendMsg(ResponseCode::CommandSyntaxError,
|
cli->sendMsg(ResponseCode::CommandSyntaxError,
|
||||||
"Usage: asec rename <old_id> <new_id>", false);
|
"Usage: asec rename <old_id> <new_id>", false);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (vm->renameAsec(argv[2], argv[3])) {
|
rc = vm->renameAsec(argv[2], argv[3]);
|
||||||
cli->sendMsg(ResponseCode::OperationFailed, "Container rename failed", true);
|
|
||||||
} else {
|
|
||||||
cli->sendMsg(ResponseCode::CommandOkay, "Container renamed", false);
|
|
||||||
}
|
|
||||||
} else if (!strcmp(argv[1], "path")) {
|
} else if (!strcmp(argv[1], "path")) {
|
||||||
if (argc != 3) {
|
if (argc != 3) {
|
||||||
cli->sendMsg(ResponseCode::CommandSyntaxError, "Usage: asec path <container-id>", false);
|
cli->sendMsg(ResponseCode::CommandSyntaxError, "Usage: asec path <container-id>", false);
|
||||||
|
@ -312,9 +271,17 @@ int CommandListener::AsecCmd::runCommand(SocketClient *cli,
|
||||||
} else {
|
} else {
|
||||||
cli->sendMsg(ResponseCode::AsecPathResult, path, false);
|
cli->sendMsg(ResponseCode::AsecPathResult, path, false);
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
cli->sendMsg(ResponseCode::CommandSyntaxError, "Unknown asec cmd", false);
|
cli->sendMsg(ResponseCode::CommandSyntaxError, "Unknown asec cmd", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!rc) {
|
||||||
|
cli->sendMsg(ResponseCode::CommandOkay, "asec operation succeeded", false);
|
||||||
|
} else {
|
||||||
|
rc = ResponseCode::convertFromErrno();
|
||||||
|
cli->sendMsg(rc, "asec operation failed", true);
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
40
ResponseCode.cpp
Normal file
40
ResponseCode.cpp
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2008 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#define LOG_TAG "Vold"
|
||||||
|
|
||||||
|
#include <cutils/log.h>
|
||||||
|
|
||||||
|
#include "ResponseCode.h"
|
||||||
|
|
||||||
|
int ResponseCode::convertFromErrno() {
|
||||||
|
if (errno == ENODEV) {
|
||||||
|
return(ResponseCode::OpFailedNoMedia);
|
||||||
|
} else if (errno == ENODATA) {
|
||||||
|
return(ResponseCode::OpFailedMediaBlank);
|
||||||
|
} else if (errno == EIO) {
|
||||||
|
return(ResponseCode::OpFailedMediaCorrupt);
|
||||||
|
} else if (errno == EBUSY) {
|
||||||
|
return(ResponseCode::OpFailedStorageBusy);
|
||||||
|
}
|
||||||
|
|
||||||
|
LOGW("Returning OperationFailed - no handler for errno %d", errno);
|
||||||
|
return(ResponseCode::OperationFailed);
|
||||||
|
}
|
|
@ -40,7 +40,7 @@ public:
|
||||||
static const int OpFailedMediaBlank = 402;
|
static const int OpFailedMediaBlank = 402;
|
||||||
static const int OpFailedMediaCorrupt = 403;
|
static const int OpFailedMediaCorrupt = 403;
|
||||||
static const int OpFailedVolNotMounted = 404;
|
static const int OpFailedVolNotMounted = 404;
|
||||||
static const int OpFailedVolBusy = 405;
|
static const int OpFailedStorageBusy = 405;
|
||||||
|
|
||||||
// 500 series - The command was not accepted and the requested
|
// 500 series - The command was not accepted and the requested
|
||||||
// action did not take place.
|
// action did not take place.
|
||||||
|
@ -59,5 +59,7 @@ public:
|
||||||
static const int VolumeDiskInserted = 630;
|
static const int VolumeDiskInserted = 630;
|
||||||
static const int VolumeDiskRemoved = 631;
|
static const int VolumeDiskRemoved = 631;
|
||||||
static const int VolumeBadRemoval = 632;
|
static const int VolumeBadRemoval = 632;
|
||||||
|
|
||||||
|
static int convertFromErrno();
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue