mkfs_f2fs: give the log in kernel

It's very useful to see the mkfs log in console to debug any issues.

Bug: 172378121
Signed-off-by: Jaegeuk Kim <jaegeuk@google.com>
Change-Id: Icdac3609860cf0bba3fa758cead885bd4960f2c0
This commit is contained in:
Jaegeuk Kim 2021-04-14 12:02:41 -07:00
parent 5e5819a761
commit 2c1380f1ab

View file

@ -20,6 +20,7 @@
#include <android-base/logging.h> #include <android-base/logging.h>
#include <android-base/properties.h> #include <android-base/properties.h>
#include <android-base/stringprintf.h> #include <android-base/stringprintf.h>
#include <logwrap/logwrap.h>
#include <fscrypt/fscrypt.h> #include <fscrypt/fscrypt.h>
#include <string> #include <string>
@ -71,45 +72,46 @@ status_t Mount(const std::string& source, const std::string& target) {
} }
status_t Format(const std::string& source) { status_t Format(const std::string& source) {
std::vector<std::string> cmd; std::vector<char const*> cmd;
cmd.push_back(kMkfsPath); cmd.emplace_back(kMkfsPath);
cmd.push_back("-f"); cmd.emplace_back("-f");
cmd.push_back("-d1"); cmd.emplace_back("-d1");
if (android::base::GetBoolProperty("vold.has_quota", false)) { if (android::base::GetBoolProperty("vold.has_quota", false)) {
cmd.push_back("-O"); cmd.emplace_back("-O");
cmd.push_back("quota"); cmd.emplace_back("quota");
} }
if (fscrypt_is_native()) { if (fscrypt_is_native()) {
cmd.push_back("-O"); cmd.emplace_back("-O");
cmd.push_back("encrypt"); cmd.emplace_back("encrypt");
} }
if (android::base::GetBoolProperty("vold.has_compress", false)) { if (android::base::GetBoolProperty("vold.has_compress", false)) {
cmd.push_back("-O"); cmd.emplace_back("-O");
cmd.push_back("compression"); cmd.emplace_back("compression");
cmd.push_back("-O"); cmd.emplace_back("-O");
cmd.push_back("extra_attr"); cmd.emplace_back("extra_attr");
} }
cmd.push_back("-O"); cmd.emplace_back("-O");
cmd.push_back("verity"); cmd.emplace_back("verity");
const bool needs_casefold = const bool needs_casefold =
android::base::GetBoolProperty("external_storage.casefold.enabled", false); android::base::GetBoolProperty("external_storage.casefold.enabled", false);
const bool needs_projid = const bool needs_projid =
android::base::GetBoolProperty("external_storage.projid.enabled", false); android::base::GetBoolProperty("external_storage.projid.enabled", false);
if (needs_projid) { if (needs_projid) {
cmd.push_back("-O"); cmd.emplace_back("-O");
cmd.push_back("project_quota,extra_attr"); cmd.emplace_back("project_quota,extra_attr");
} }
if (needs_casefold) { if (needs_casefold) {
cmd.push_back("-O"); cmd.emplace_back("-O");
cmd.push_back("casefold"); cmd.emplace_back("casefold");
cmd.push_back("-C"); cmd.emplace_back("-C");
cmd.push_back("utf8"); cmd.emplace_back("utf8");
} }
cmd.push_back(source); cmd.emplace_back(source.c_str());
return ForkExecvp(cmd); return logwrap_fork_execvp(cmd.size(), cmd.data(), nullptr, false, LOG_KLOG,
false, nullptr);
} }
} // namespace f2fs } // namespace f2fs