vold: Add support for renaming secure containers

Signed-off-by: San Mehat <san@google.com>
This commit is contained in:
San Mehat 2010-01-23 08:17:06 -08:00
parent 68f8ebdb24
commit 048b0801fc
4 changed files with 65 additions and 1 deletions

View file

@ -46,6 +46,7 @@ CommandListener::CommandListener() :
registerCmd(new DestroyAsecCmd());
registerCmd(new MountAsecCmd());
registerCmd(new UnmountAsecCmd());
registerCmd(new RenameAsecCmd());
registerCmd(new ListAsecCmd());
registerCmd(new AsecPathCmd());
}
@ -275,6 +276,26 @@ int CommandListener::UnmountAsecCmd::runCommand(SocketClient *cli,
return 0;
}
CommandListener::RenameAsecCmd::RenameAsecCmd() :
VoldCommand("rename_asec") {
}
int CommandListener::RenameAsecCmd::runCommand(SocketClient *cli,
int argc, char **argv) {
if (argc != 3) {
cli->sendMsg(ResponseCode::CommandSyntaxError,
"Usage: rename_asec <id1> <id2>", false);
return 0;
}
if (VolumeManager::Instance()->renameAsec(argv[1], argv[2])) {
cli->sendMsg(ResponseCode::OperationFailed, "Rename failed", true);
} else {
cli->sendMsg(ResponseCode::CommandOkay, "Rename succeeded", false);
}
return 0;
}
CommandListener::ListAsecCmd::ListAsecCmd() :
VoldCommand("list_asec") {

View file

@ -118,6 +118,13 @@ private:
int runCommand(SocketClient *c, int argc, char ** argv);
};
class RenameAsecCmd : public VoldCommand {
public:
RenameAsecCmd();
virtual ~RenameAsecCmd() {}
int runCommand(SocketClient *c, int argc, char ** argv);
};
class ListAsecCmd : public VoldCommand {
public:
ListAsecCmd();
@ -132,7 +139,6 @@ private:
int runCommand(SocketClient *c, int argc, char ** argv);
};
};
#endif

View file

@ -284,6 +284,42 @@ int VolumeManager::finalizeAsec(const char *id) {
return 0;
}
int VolumeManager::renameAsec(const char *id1, const char *id2) {
char *asecFilename1;
char *asecFilename2;
char mountPoint[255];
asprintf(&asecFilename1, "/sdcard/android_secure/%s.asec", id1);
asprintf(&asecFilename2, "/sdcard/android_secure/%s.asec", id2);
snprintf(mountPoint, sizeof(mountPoint), "/asec/%s", id1);
if (isMountpointMounted(mountPoint)) {
LOGW("Rename attempt when src mounted");
errno = EBUSY;
goto out_err;
}
if (!access(asecFilename2, F_OK)) {
LOGE("Rename attempt when dst exists");
errno = EADDRINUSE;
goto out_err;
}
if (rename(asecFilename1, asecFilename2)) {
LOGE("Rename of '%s' to '%s' failed (%s)", asecFilename1, asecFilename2, strerror(errno));
goto out_err;
}
free(asecFilename1);
free(asecFilename2);
return 0;
out_err:
free(asecFilename1);
free(asecFilename2);
return -1;
}
int VolumeManager::unmountAsec(const char *id) {
char asecFileName[255];
char mountPoint[255];

View file

@ -64,6 +64,7 @@ public:
int destroyAsec(const char *id);
int mountAsec(const char *id, const char *key, int ownerUid);
int unmountAsec(const char *id);
int renameAsec(const char *id1, const char *id2);
int getAsecMountPath(const char *id, char *buffer, int maxlen);
// XXX: This should be moved private once switch uevents are working