Merge "Use dynamically linked f2fs executables." am: 22a27f9965
am: ad4ce79b4d

Change-Id: I0fc7309dc6ab5a87d26677a0ed9f0d5c6f288b7a
diff --git a/Android.mk b/Android.mk
index 7be1230..429c52d 100644
--- a/Android.mk
+++ b/Android.mk
@@ -58,8 +58,8 @@
 ifeq ($(TARGET_USERIMAGES_USE_F2FS),true)
 ifeq ($(HOST_OS),linux)
 LOCAL_REQUIRED_MODULES += \
-    sload.f2fs \
-    mkfs.f2fs
+    make_f2fs.recovery \
+    sload_f2fs.recovery
 endif
 endif
 
diff --git a/CleanSpec.mk b/CleanSpec.mk
index e2d97d4..fec823e 100644
--- a/CleanSpec.mk
+++ b/CleanSpec.mk
@@ -49,3 +49,4 @@
 # ************************************************
 $(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/EXECUTABLES/recovery_intermediates)
 $(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/STATIC_LIBRARIES/libminui_intermediates/import_includes)
+$(call add-clean-step, rm -rf $(PRODUCT_OUT)/recovery/root/sbin)
diff --git a/roots.cpp b/roots.cpp
index 6db0ca5..290be47 100644
--- a/roots.cpp
+++ b/roots.cpp
@@ -223,35 +223,29 @@
 
   // Has to be f2fs because we checked earlier.
   static constexpr int kSectorSize = 4096;
-  std::string cmd("/sbin/mkfs.f2fs");
-  // clang-format off
   std::vector<std::string> make_f2fs_cmd = {
-    cmd,
-    "-g", "android",
+    "/system/bin/make_f2fs",
+    "-g",
+    "android",
     v->blk_device,
   };
-  // clang-format on
   if (length >= kSectorSize) {
     make_f2fs_cmd.push_back(std::to_string(length / kSectorSize));
   }
 
-  int result = exec_cmd(make_f2fs_cmd);
-  if (result == 0 && !directory.empty()) {
-    cmd = "/sbin/sload.f2fs";
-    // clang-format off
-    std::vector<std::string> sload_f2fs_cmd = {
-      cmd,
-      "-f", directory,
-      "-t", volume,
-      v->blk_device,
-    };
-    // clang-format on
-    result = exec_cmd(sload_f2fs_cmd);
-  }
-  if (result != 0) {
-    PLOG(ERROR) << "format_volume: Failed " << cmd << " on " << v->blk_device;
+  if (exec_cmd(make_f2fs_cmd) != 0) {
+    PLOG(ERROR) << "format_volume: Failed to make_f2fs on " << v->blk_device;
     return -1;
   }
+  if (!directory.empty()) {
+    std::vector<std::string> sload_f2fs_cmd = {
+      "/system/bin/sload_f2fs", "-f", directory, "-t", volume, v->blk_device,
+    };
+    if (exec_cmd(sload_f2fs_cmd) != 0) {
+      PLOG(ERROR) << "format_volume: Failed to sload_f2fs on " << v->blk_device;
+      return -1;
+    }
+  }
   return 0;
 }
 
diff --git a/updater/install.cpp b/updater/install.cpp
index 0e1028b..20a204a 100644
--- a/updater/install.cpp
+++ b/updater/install.cpp
@@ -482,18 +482,19 @@
       return StringValue("");
     }
     std::vector<std::string> f2fs_args = {
-      "/sbin/mkfs.f2fs", "-g", "android", "-w", "512", location
+      "/system/bin/make_f2fs", "-g", "android", "-w", "512", location
     };
     if (size >= 512) {
       f2fs_args.push_back(std::to_string(size / 512));
     }
     if (auto status = exec_cmd(f2fs_args); status != 0) {
-      LOG(ERROR) << name << ": mkfs.f2fs failed (" << status << ") on " << location;
+      LOG(ERROR) << name << ": make_f2fs failed (" << status << ") on " << location;
       return StringValue("");
     }
 
-    if (auto status = exec_cmd({ "/sbin/sload.f2fs", "-t", mount_point, location }); status != 0) {
-      LOG(ERROR) << name << ": sload.f2fs failed (" << status << ") on " << location;
+    if (auto status = exec_cmd({ "/system/bin/sload_f2fs", "-t", mount_point, location });
+        status != 0) {
+      LOG(ERROR) << name << ": sload_f2fs failed (" << status << ") on " << location;
       return StringValue("");
     }