Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2a9a6b56 authored by Junichi Uekawa's avatar Junichi Uekawa Committed by Yuan Yao
Browse files

init: flush ext4 file system on shutdown

Previously, only f2fs /data filesystems were shutdown using the
F2FS_IOC_SHUTDOWN ioctl. This change adds support for shutting down ext4
/data filesystem with the EXT4_IOC_SHUTDOWN ioctl.

Bug: 403381187
Test: Verify /data was clean after reboot on desktop
Test: Verify e2fsck returns immediately when booting on desktop

Change-Id: I08208888d839649efe54fcab5d73177e9e06ec88
parent a47b636e
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -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 @@ static void DoReboot(unsigned int cmd, const std::string& reason, const std::str
        } 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();