Merge "add sload.f2fs for recovery format" am: 4eaf7a157d am: 3d4359d3ae
am: adb8f660a2

Change-Id: I551f6fe2e040720ea02cbdacfc73bc3aaa5b2e3d
diff --git a/Android.mk b/Android.mk
index 50627b9..54f4054 100644
--- a/Android.mk
+++ b/Android.mk
@@ -89,7 +89,7 @@
 
 ifeq ($(TARGET_USERIMAGES_USE_F2FS),true)
 ifeq ($(HOST_OS),linux)
-LOCAL_REQUIRED_MODULES += mkfs.f2fs
+LOCAL_REQUIRED_MODULES += sload.f2fs mkfs.f2fs
 endif
 endif
 
diff --git a/roots.cpp b/roots.cpp
index eb299ad..e2d5d65 100644
--- a/roots.cpp
+++ b/roots.cpp
@@ -324,16 +324,23 @@
   }
 
   // Has to be f2fs because we checked earlier.
-  std::vector<std::string> f2fs_args = { "/sbin/mkfs.f2fs", "-d1", "-f",
-                                         "-O", "encrypt", "-O", "quota",
-                                         v->blk_device };
+  std::string cmd("/sbin/mkfs.f2fs");
+  std::vector<std::string> make_f2fs_cmd = { cmd,       "-d1", "-f",    "-O",
+                                             "encrypt", "-O",  "quota", v->blk_device };
   if (length >= 512) {
-    f2fs_args.push_back(std::to_string(length / 512));
+    make_f2fs_cmd.push_back(std::to_string(length / 512));
   }
 
-  int result = exec_cmd(f2fs_args);
+  int result = exec_cmd(make_f2fs_cmd);
+  if (result == 0 && directory != nullptr) {
+    cmd = "/sbin/sload.f2fs";
+    std::vector<std::string> sload_f2fs_cmd = {
+      cmd, "-f", directory, "-t", volume, v->blk_device,
+    };
+    result = exec_cmd(sload_f2fs_cmd);
+  }
   if (result != 0) {
-    PLOG(ERROR) << "format_volume: Failed to make f2fs on " << v->blk_device;
+    PLOG(ERROR) << "format_volume: Failed " << cmd << " on " << v->blk_device;
     return -1;
   }
   return 0;
diff --git a/updater/install.cpp b/updater/install.cpp
index 870b857..b83d30f 100644
--- a/updater/install.cpp
+++ b/updater/install.cpp
@@ -318,6 +318,15 @@
       LOG(ERROR) << name << ": mkfs.f2fs failed (" << status << ") on " << location;
       return StringValue("");
     }
+
+    const char* sload_argv[] = { "/sbin/sload.f2fs", "-t", mount_point.c_str(), location.c_str(),
+                                 nullptr };
+    status = exec_cmd(sload_argv[0], const_cast<char**>(sload_argv));
+    if (status != 0) {
+      LOG(ERROR) << name << ": sload.f2fs failed (" << status << ") on " << location;
+      return StringValue("");
+    }
+
     return StringValue(location);
   } else {
     LOG(ERROR) << name << ": unsupported fs_type \"" << fs_type << "\" partition_type \""