Merge "init: flush ext4 file system on shutdown" into main
diff --git a/init/reboot.cpp b/init/reboot.cpp
index a26149f..3b81cb5 100644
--- a/init/reboot.cpp
+++ b/init/reboot.cpp
@@ -18,6 +18,7 @@
 
 #include <dirent.h>
 #include <fcntl.h>
+#include <linux/ext4.h>
 #include <linux/f2fs.h>
 #include <linux/fs.h>
 #include <linux/loop.h>
@@ -835,6 +836,15 @@
         } else {
             LOG(INFO) << "Shutdown /data";
         }
+    } else if (IsDataMounted("ext4")) {
+        uint32_t flag = EXT4_GOING_FLAGS_DEFAULT;
+        unique_fd fd(TEMP_FAILURE_RETRY(open("/data", O_RDONLY)));
+        int ret = ioctl(fd.get(), EXT4_IOC_SHUTDOWN, &flag);
+        if (ret) {
+            PLOG(ERROR) << "Shutdown /data: ";
+        } else {
+            LOG(INFO) << "Shutdown /data";
+        }
     }
     RebootSystem(cmd, reboot_target, reason);
     abort();