2009-10-11 02:22:08 +02:00
|
|
|
/*
|
|
|
|
* 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 <errno.h>
|
|
|
|
#include <fcntl.h>
|
2016-02-02 01:02:29 +01:00
|
|
|
#include <poll.h>
|
2018-09-18 22:30:21 +02:00
|
|
|
#include <signal.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
2009-10-11 02:22:08 +02:00
|
|
|
|
|
|
|
#include <sys/select.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/un.h>
|
|
|
|
|
2017-09-14 02:43:44 +02:00
|
|
|
#include "android/os/IVold.h"
|
|
|
|
|
2017-03-30 01:50:28 +02:00
|
|
|
#include <android-base/logging.h>
|
2018-08-28 10:58:49 +02:00
|
|
|
#include <android-base/parseint.h>
|
2019-04-04 18:35:51 +02:00
|
|
|
#include <android-base/strings.h>
|
2016-02-02 01:02:29 +01:00
|
|
|
#include <android-base/stringprintf.h>
|
2017-09-14 02:43:44 +02:00
|
|
|
#include <binder/IServiceManager.h>
|
2017-10-27 22:37:24 +02:00
|
|
|
#include <binder/Status.h>
|
2016-02-02 01:02:29 +01:00
|
|
|
|
2009-10-11 02:22:08 +02:00
|
|
|
#include <private/android_filesystem_config.h>
|
|
|
|
|
2018-09-18 22:30:21 +02:00
|
|
|
static void usage(char* progname);
|
2017-09-14 02:43:44 +02:00
|
|
|
|
2017-09-27 18:44:33 +02:00
|
|
|
static android::sp<android::IBinder> getServiceAggressive() {
|
|
|
|
android::sp<android::IBinder> res;
|
|
|
|
auto sm = android::defaultServiceManager();
|
|
|
|
auto name = android::String16("vold");
|
2018-01-30 18:48:19 +01:00
|
|
|
for (int i = 0; i < 5000; i++) {
|
2017-09-27 18:44:33 +02:00
|
|
|
res = sm->checkService(name);
|
|
|
|
if (res) {
|
|
|
|
LOG(VERBOSE) << "Waited " << (i * 10) << "ms for vold";
|
|
|
|
break;
|
|
|
|
}
|
2018-09-18 22:30:21 +02:00
|
|
|
usleep(10000); // 10ms
|
2017-09-27 18:44:33 +02:00
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2019-04-04 18:35:51 +02:00
|
|
|
static void checkStatus(std::vector<std::string>& cmd, android::binder::Status status) {
|
2017-10-27 22:37:24 +02:00
|
|
|
if (status.isOk()) return;
|
2019-04-04 18:35:51 +02:00
|
|
|
std::string command = ::android::base::Join(cmd, " ");
|
|
|
|
LOG(ERROR) << "Command: " << command << " Failed: " << status.toString8().string();
|
2017-10-27 22:37:24 +02:00
|
|
|
exit(ENOTTY);
|
|
|
|
}
|
2009-10-11 02:22:08 +02:00
|
|
|
|
2017-10-27 22:37:24 +02:00
|
|
|
int main(int argc, char** argv) {
|
2017-09-27 18:44:33 +02:00
|
|
|
setenv("ANDROID_LOG_TAGS", "*:v", 1);
|
2017-03-30 01:50:28 +02:00
|
|
|
if (getppid() == 1) {
|
|
|
|
// If init is calling us then it's during boot and we should log to kmsg
|
|
|
|
android::base::InitLogging(argv, &android::base::KernelLogger);
|
|
|
|
} else {
|
|
|
|
android::base::InitLogging(argv, &android::base::StderrLogger);
|
|
|
|
}
|
2017-10-27 22:37:24 +02:00
|
|
|
std::vector<std::string> args(argv + 1, argv + argc);
|
2017-03-30 01:50:28 +02:00
|
|
|
|
2017-10-27 22:37:24 +02:00
|
|
|
if (args.size() > 0 && args[0] == "--wait") {
|
|
|
|
// Just ignore the --wait flag
|
|
|
|
args.erase(args.begin());
|
2009-10-11 02:22:08 +02:00
|
|
|
}
|
|
|
|
|
2017-10-27 22:37:24 +02:00
|
|
|
if (args.size() < 2) {
|
|
|
|
usage(argv[0]);
|
2014-01-29 22:31:03 +01:00
|
|
|
exit(5);
|
2014-04-16 03:08:05 +02:00
|
|
|
}
|
2017-09-27 18:44:33 +02:00
|
|
|
android::sp<android::IBinder> binder = getServiceAggressive();
|
2017-09-14 02:43:44 +02:00
|
|
|
if (!binder) {
|
|
|
|
LOG(ERROR) << "Failed to obtain vold Binder";
|
|
|
|
exit(EINVAL);
|
|
|
|
}
|
|
|
|
auto vold = android::interface_cast<android::os::IVold>(binder);
|
|
|
|
|
2017-10-27 22:37:24 +02:00
|
|
|
if (args[0] == "cryptfs" && args[1] == "enablefilecrypto") {
|
2019-04-04 18:35:51 +02:00
|
|
|
checkStatus(args, vold->fbeEnable());
|
2017-10-27 22:37:24 +02:00
|
|
|
} else if (args[0] == "cryptfs" && args[1] == "init_user0") {
|
2019-04-04 18:35:51 +02:00
|
|
|
checkStatus(args, vold->initUser0());
|
2017-10-27 22:37:24 +02:00
|
|
|
} else if (args[0] == "cryptfs" && args[1] == "enablecrypto") {
|
2017-09-14 02:43:44 +02:00
|
|
|
int passwordType = android::os::IVold::PASSWORD_TYPE_DEFAULT;
|
2017-12-22 19:12:06 +01:00
|
|
|
int encryptionFlags = android::os::IVold::ENCRYPTION_FLAG_NO_UI;
|
2019-04-04 18:35:51 +02:00
|
|
|
checkStatus(args, vold->fdeEnable(passwordType, "", encryptionFlags));
|
2017-10-27 22:37:24 +02:00
|
|
|
} else if (args[0] == "cryptfs" && args[1] == "mountdefaultencrypted") {
|
2019-04-04 18:35:51 +02:00
|
|
|
checkStatus(args, vold->mountDefaultEncrypted());
|
2020-04-29 07:49:41 +02:00
|
|
|
} else if (args[0] == "volume" && args[1] == "abort_fuse") {
|
|
|
|
checkStatus(args, vold->abortFuse());
|
2017-10-27 22:37:24 +02:00
|
|
|
} else if (args[0] == "volume" && args[1] == "shutdown") {
|
2019-04-04 18:35:51 +02:00
|
|
|
checkStatus(args, vold->shutdown());
|
2019-12-02 12:48:06 +01:00
|
|
|
} else if (args[0] == "volume" && args[1] == "reset") {
|
|
|
|
checkStatus(args, vold->reset());
|
2019-06-25 23:44:33 +02:00
|
|
|
} else if (args[0] == "cryptfs" && args[1] == "mountFstab" && args.size() == 4) {
|
|
|
|
checkStatus(args, vold->mountFstab(args[2], args[3]));
|
|
|
|
} else if (args[0] == "cryptfs" && args[1] == "encryptFstab" && args.size() == 4) {
|
|
|
|
checkStatus(args, vold->encryptFstab(args[2], args[3]));
|
2019-01-23 02:27:25 +01:00
|
|
|
} else if (args[0] == "checkpoint" && args[1] == "supportsCheckpoint" && args.size() == 2) {
|
|
|
|
bool supported = false;
|
2019-04-04 18:35:51 +02:00
|
|
|
checkStatus(args, vold->supportsCheckpoint(&supported));
|
2019-01-23 02:27:25 +01:00
|
|
|
return supported ? 1 : 0;
|
2019-12-02 12:48:06 +01:00
|
|
|
} else if (args[0] == "checkpoint" && args[1] == "supportsBlockCheckpoint" &&
|
|
|
|
args.size() == 2) {
|
2019-03-18 21:36:40 +01:00
|
|
|
bool supported = false;
|
2019-04-04 18:35:51 +02:00
|
|
|
checkStatus(args, vold->supportsBlockCheckpoint(&supported));
|
2019-03-18 21:36:40 +01:00
|
|
|
return supported ? 1 : 0;
|
|
|
|
} else if (args[0] == "checkpoint" && args[1] == "supportsFileCheckpoint" && args.size() == 2) {
|
|
|
|
bool supported = false;
|
2019-04-04 18:35:51 +02:00
|
|
|
checkStatus(args, vold->supportsFileCheckpoint(&supported));
|
2019-03-18 21:36:40 +01:00
|
|
|
return supported ? 1 : 0;
|
2018-08-28 10:58:49 +02:00
|
|
|
} else if (args[0] == "checkpoint" && args[1] == "startCheckpoint" && args.size() == 3) {
|
|
|
|
int retry;
|
|
|
|
if (!android::base::ParseInt(args[2], &retry)) exit(EINVAL);
|
2019-04-04 18:35:51 +02:00
|
|
|
checkStatus(args, vold->startCheckpoint(retry));
|
2018-08-28 10:58:49 +02:00
|
|
|
} else if (args[0] == "checkpoint" && args[1] == "needsCheckpoint" && args.size() == 2) {
|
|
|
|
bool enabled = false;
|
2019-04-04 18:35:51 +02:00
|
|
|
checkStatus(args, vold->needsCheckpoint(&enabled));
|
2018-08-28 10:58:49 +02:00
|
|
|
return enabled ? 1 : 0;
|
2018-10-03 02:40:44 +02:00
|
|
|
} else if (args[0] == "checkpoint" && args[1] == "needsRollback" && args.size() == 2) {
|
|
|
|
bool enabled = false;
|
2019-04-04 18:35:51 +02:00
|
|
|
checkStatus(args, vold->needsRollback(&enabled));
|
2018-10-03 02:40:44 +02:00
|
|
|
return enabled ? 1 : 0;
|
2018-08-28 10:58:49 +02:00
|
|
|
} else if (args[0] == "checkpoint" && args[1] == "commitChanges" && args.size() == 2) {
|
2019-04-04 18:35:51 +02:00
|
|
|
checkStatus(args, vold->commitChanges());
|
2018-10-10 04:26:57 +02:00
|
|
|
} else if (args[0] == "checkpoint" && args[1] == "prepareCheckpoint" && args.size() == 2) {
|
2019-04-04 18:35:51 +02:00
|
|
|
checkStatus(args, vold->prepareCheckpoint());
|
2018-09-21 19:49:57 +02:00
|
|
|
} else if (args[0] == "checkpoint" && args[1] == "restoreCheckpoint" && args.size() == 3) {
|
2019-04-04 18:35:51 +02:00
|
|
|
checkStatus(args, vold->restoreCheckpoint(args[2]));
|
2019-03-07 02:45:17 +01:00
|
|
|
} else if (args[0] == "checkpoint" && args[1] == "restoreCheckpointPart" && args.size() == 4) {
|
|
|
|
int count;
|
|
|
|
if (!android::base::ParseInt(args[3], &count)) exit(EINVAL);
|
2019-04-04 18:35:51 +02:00
|
|
|
checkStatus(args, vold->restoreCheckpointPart(args[2], count));
|
2018-08-28 10:58:49 +02:00
|
|
|
} else if (args[0] == "checkpoint" && args[1] == "markBootAttempt" && args.size() == 2) {
|
2019-04-04 18:35:51 +02:00
|
|
|
checkStatus(args, vold->markBootAttempt());
|
2019-03-21 01:02:47 +01:00
|
|
|
} else if (args[0] == "checkpoint" && args[1] == "abortChanges" && args.size() == 4) {
|
|
|
|
int retry;
|
|
|
|
if (!android::base::ParseInt(args[2], &retry)) exit(EINVAL);
|
2019-04-04 18:35:51 +02:00
|
|
|
checkStatus(args, vold->abortChanges(args[2], retry != 0));
|
2019-10-11 17:38:21 +02:00
|
|
|
} else if (args[0] == "checkpoint" && args[1] == "resetCheckpoint") {
|
|
|
|
checkStatus(args, vold->resetCheckpoint());
|
2020-12-01 23:36:06 +01:00
|
|
|
} else if (args[0] == "keymaster" && args[1] == "earlyBootEnded") {
|
2020-11-12 10:59:13 +01:00
|
|
|
checkStatus(args, vold->earlyBootEnded());
|
2017-09-14 02:43:44 +02:00
|
|
|
} else {
|
|
|
|
LOG(ERROR) << "Raw commands are no longer supported";
|
|
|
|
exit(EINVAL);
|
|
|
|
}
|
2017-10-27 22:37:24 +02:00
|
|
|
return 0;
|
2009-10-11 02:22:08 +02:00
|
|
|
}
|
|
|
|
|
2018-09-18 22:30:21 +02:00
|
|
|
static void usage(char* progname) {
|
2017-10-27 22:37:24 +02:00
|
|
|
LOG(INFO) << "Usage: " << progname << " [--wait] <system> <subcommand> [args...]";
|
2016-02-02 01:02:29 +01:00
|
|
|
}
|