From 7485f1c81d607fe9fbf56b8ce0a458fbf06c5285 Mon Sep 17 00:00:00 2001 From: chenrun1 Date: Mon, 6 Mar 2023 10:41:03 +0800 Subject: [PATCH] fs/fs_initialize.c:Sync fs in system restart callback --- fs/fs_initialize.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/fs/fs_initialize.c b/fs/fs_initialize.c index f04aee4e702..a598f9b7e86 100644 --- a/fs/fs_initialize.c +++ b/fs/fs_initialize.c @@ -23,11 +23,40 @@ ****************************************************************************/ #include +#include #include "rpmsgfs/rpmsgfs.h" #include "inode/inode.h" #include "aio/aio.h" +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: sync_reboot_handler + ****************************************************************************/ + +static int sync_reboot_handler(FAR struct notifier_block *nb, + unsigned long action, FAR void *data) +{ + sync(); + return 0; +} + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Name: fs_sync_reboot_nb + ****************************************************************************/ + +static struct notifier_block g_sync_nb = +{ + sync_reboot_handler +}; + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -57,4 +86,6 @@ void fs_initialize(void) #ifdef CONFIG_FS_RPMSGFS_SERVER rpmsgfs_server_init(); #endif + + register_reboot_notifier(&g_sync_nb); }