fastboot/fs_mgr/init: add sload_f2fs
Change-Id: Iab1e4037cbb835aba97f941c8840b8971caf38e7
Signed-off-by: Jaegeuk Kim <jaegeuk@google.com>
diff --git a/fastboot/Android.mk b/fastboot/Android.mk
index e0f702d..10ef356 100644
--- a/fastboot/Android.mk
+++ b/fastboot/Android.mk
@@ -39,7 +39,7 @@
LOCAL_MODULE_TAGS := debug
LOCAL_MODULE_HOST_OS := darwin linux windows
LOCAL_CFLAGS += -Wall -Wextra -Werror -Wunreachable-code
-LOCAL_REQUIRED_MODULES := mke2fs e2fsdroid mke2fs.conf make_f2fs
+LOCAL_REQUIRED_MODULES := mke2fs e2fsdroid mke2fs.conf make_f2fs sload_f2fs
LOCAL_SRC_FILES_linux := usb_linux.cpp
LOCAL_STATIC_LIBRARIES_linux := libselinux
@@ -79,6 +79,7 @@
my_dist_files += $(HOST_OUT_EXECUTABLES)/mke2fs$(HOST_EXECUTABLE_SUFFIX)
my_dist_files += $(HOST_OUT_EXECUTABLES)/e2fsdroid$(HOST_EXECUTABLE_SUFFIX)
my_dist_files += $(HOST_OUT_EXECUTABLES)/make_f2fs$(HOST_EXECUTABLE_SUFFIX)
+my_dist_files += $(HOST_OUT_EXECUTABLES)/sload_f2fs$(HOST_EXECUTABLE_SUFFIX)
$(call dist-for-goals,dist_files sdk win_sdk,$(my_dist_files))
ifdef HOST_CROSS_OS
# Archive fastboot.exe for win_sdk build.
diff --git a/fastboot/fs.cpp b/fastboot/fs.cpp
index 9949eae..9db710d 100644
--- a/fastboot/fs.cpp
+++ b/fastboot/fs.cpp
@@ -28,7 +28,7 @@
using android::base::unique_fd;
#ifdef WIN32
-static int exec_e2fs_cmd(const char* /*path*/, const char** argv, const char** envp) {
+static int exec_cmd(const char* path, const char** argv, const char** envp) {
std::string cmd;
int i = 0;
while (argv[i] != nullptr) {
@@ -76,10 +76,14 @@
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
- return exit_code != 0;
+ if (exit_code != 0) {
+ fprintf(stderr, "%s failed: %lu\n", path, exit_code);
+ return -1;
+ }
+ return 0;
}
#else
-static int exec_e2fs_cmd(const char* path, const char** argv, const char** envp) {
+static int exec_cmd(const char* path, const char** argv, const char** envp) {
int status;
pid_t child;
if ((child = fork()) == 0) {
@@ -97,11 +101,13 @@
int ret = -1;
if (WIFEXITED(status)) {
ret = WEXITSTATUS(status);
- if (ret != 0) {
- fprintf(stderr, "%s failed with status %d\n", path, ret);
- }
}
- return ret;
+
+ if (ret != 0) {
+ fprintf(stderr, "%s failed with status %d\n", path, ret);
+ return -1;
+ }
+ return 0;
}
#endif
@@ -140,9 +146,8 @@
const std::string mke2fs_env = "MKE2FS_CONFIG=" + GetExecutableDirectory() + "/mke2fs.conf";
std::vector<const char*> mke2fs_envp = {mke2fs_env.c_str(), nullptr};
- int ret = exec_e2fs_cmd(mke2fs_args[0], mke2fs_args.data(), mke2fs_envp.data());
+ int ret = exec_cmd(mke2fs_args[0], mke2fs_args.data(), mke2fs_envp.data());
if (ret != 0) {
- fprintf(stderr, "mke2fs failed: %d\n", ret);
return -1;
}
@@ -154,13 +159,7 @@
std::vector<const char*> e2fsdroid_args = {e2fsdroid_path.c_str(), "-f", initial_dir.c_str(),
fileName, nullptr};
- ret = exec_e2fs_cmd(e2fsdroid_args[0], e2fsdroid_args.data(), nullptr);
- if (ret != 0) {
- fprintf(stderr, "e2fsdroid failed: %d\n", ret);
- return -1;
- }
-
- return 0;
+ return exec_cmd(e2fsdroid_args[0], e2fsdroid_args.data(), nullptr);
}
static int generate_f2fs_image(const char* fileName, long long partSize, const std::string& initial_dir,
@@ -182,20 +181,23 @@
mkf2fs_args.push_back(fileName);
mkf2fs_args.push_back(nullptr);
- int ret = exec_e2fs_cmd(mkf2fs_args[0], mkf2fs_args.data(), nullptr);
+ int ret = exec_cmd(mkf2fs_args[0], mkf2fs_args.data(), nullptr);
if (ret != 0) {
- fprintf(stderr, "mkf2fs failed: %d\n", ret);
return -1;
}
- if (!initial_dir.empty()) {
- fprintf(stderr, "sload.f2s not supported yet\n");
+ if (initial_dir.empty()) {
return 0;
}
- return 0;
+
+ const std::string sload_path = exec_dir + "/sload_f2fs";
+ std::vector<const char*> sload_args = {sload_path.c_str(), "-S",
+ "-f", initial_dir.c_str(), fileName, nullptr};
+
+ return exec_cmd(sload_args[0], sload_args.data(), nullptr);
#else
UNUSED(fileName, partSize, initial_dir);
- fprintf(stderr, "make_f2fs not supported on Windows\n");
+ fprintf(stderr, "generate_f2fs_image: Not supported on Windows\n");
return -1;
#endif
}
diff --git a/init/Android.bp b/init/Android.bp
index 45ee754..0ec348c 100644
--- a/init/Android.bp
+++ b/init/Android.bp
@@ -118,6 +118,8 @@
required: [
"e2fsdroid",
"mke2fs",
+ "sload_f2fs",
+ "make_f2fs",
],
static_executable: true,
srcs: [
diff --git a/init/Android.mk b/init/Android.mk
index 44300f6..516f1b3 100644
--- a/init/Android.mk
+++ b/init/Android.mk
@@ -88,6 +88,8 @@
LOCAL_REQUIRED_MODULES := \
e2fsdroid \
mke2fs \
+ sload_f2fs \
+ make_f2fs \
# Create symlinks.
LOCAL_POST_INSTALL_CMD := $(hide) mkdir -p $(TARGET_ROOT_OUT)/sbin; \
diff --git a/init/selinux.cpp b/init/selinux.cpp
index 21010b0..1febccd 100644
--- a/init/selinux.cpp
+++ b/init/selinux.cpp
@@ -436,6 +436,9 @@
selinux_android_restorecon("/sbin/mke2fs_static", 0);
selinux_android_restorecon("/sbin/e2fsdroid_static", 0);
+
+ selinux_android_restorecon("/sbin/mkfs.f2fs", 0);
+ selinux_android_restorecon("/sbin/sload.f2fs", 0);
}
// This function sets up SELinux logging to be written to kmsg, to match init's logging.