This is an automated email from the ASF dual-hosted git repository.

GUIDINGLI pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 5fa5bfda8423068d4b5c8b07ead1c4c834227d11
Author: jingfei <[email protected]>
AuthorDate: Wed Nov 18 20:33:04 2026 +0800

    fs: move the reboot notifier into fs_reboot.c
    
    Move the filesystem reboot notifier out of fs_initialize.c into a
    dedicated fs/fs_reboot.c that exports fs_reboot_initialize(), called
    from fs_initialize().  No functional change.
    
    Signed-off-by: jingfei <[email protected]>
---
 fs/CMakeLists.txt                   |  2 +-
 fs/Makefile                         |  2 +-
 fs/fs_initialize.c                  | 38 +-----------------
 fs/{fs_initialize.c => fs_reboot.c} | 80 +++++++++++--------------------------
 fs/fs_reboot.h                      | 46 +++++++++++++++++++++
 5 files changed, 74 insertions(+), 94 deletions(-)

diff --git a/fs/CMakeLists.txt b/fs/CMakeLists.txt
index 3baedd44f3e..03db3defc07 100644
--- a/fs/CMakeLists.txt
+++ b/fs/CMakeLists.txt
@@ -20,7 +20,7 @@
 #
 # 
##############################################################################
 
-nuttx_add_kernel_library(fs fs_initialize.c fs_heap.c)
+nuttx_add_kernel_library(fs fs_initialize.c fs_reboot.c fs_heap.c)
 nuttx_add_subdirectory()
 target_include_directories(fs PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
                                       ${NUTTX_DIR}/sched)
diff --git a/fs/Makefile b/fs/Makefile
index 316ffaadcf8..9b4620fcc39 100644
--- a/fs/Makefile
+++ b/fs/Makefile
@@ -22,7 +22,7 @@
 
 include $(TOPDIR)/Make.defs
 
-CSRCS = fs_initialize.c fs_heap.c
+CSRCS = fs_initialize.c fs_reboot.c fs_heap.c
 
 ifneq ($(CONFIG_FS_HEAPBUF_SECTION),"")
   CFLAGS += ${DEFINE_PREFIX}FS_HEAPBUF_SECTION=CONFIG_FS_HEAPBUF_SECTION
diff --git a/fs/fs_initialize.c b/fs/fs_initialize.c
index a5ed0aff789..45430c1fa5a 100644
--- a/fs/fs_initialize.c
+++ b/fs/fs_initialize.c
@@ -25,50 +25,16 @@
  ****************************************************************************/
 
 #include <nuttx/config.h>
-#include <nuttx/reboot_notifier.h>
 #include <nuttx/trace.h>
-#include <nuttx/irq.h>
 
 #include "rpmsgfs/rpmsgfs.h"
 #include "inode/inode.h"
 #include "aio/aio.h"
 #include "vfs/vfs.h"
 #include "fs_heap.h"
+#include "fs_reboot.h"
 #include "shm/shmfs.h"
 
-/****************************************************************************
- * Private Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: sync_reboot_handler
- ****************************************************************************/
-
-static int sync_reboot_handler(FAR struct notifier_block *nb,
-                               unsigned long action, FAR void *data)
-{
-  if ((action == SYS_POWER_OFF || action == SYS_RESTART) &&
-       !up_interrupt_context())
-    {
-      sync();
-    }
-
-  return 0;
-}
-
-/****************************************************************************
- * Private Data
- ****************************************************************************/
-
-/****************************************************************************
- * Name: fs_sync_reboot_nb
- ****************************************************************************/
-
-static struct notifier_block g_sync_nb =
-{
-  sync_reboot_handler
-};
-
 /****************************************************************************
  * Public Functions
  ****************************************************************************/
@@ -115,6 +81,6 @@ void fs_initialize(void)
   shmfs_initialize();
 #endif
 
-  register_reboot_notifier(&g_sync_nb);
+  fs_reboot_initialize();
   fs_trace_end();
 }
diff --git a/fs/fs_initialize.c b/fs/fs_reboot.c
similarity index 63%
copy from fs/fs_initialize.c
copy to fs/fs_reboot.c
index a5ed0aff789..5880864c1b5 100644
--- a/fs/fs_initialize.c
+++ b/fs/fs_reboot.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * fs/fs_initialize.c
+ * fs/fs_reboot.c
  *
  * SPDX-License-Identifier: Apache-2.0
  *
@@ -25,30 +25,35 @@
  ****************************************************************************/
 
 #include <nuttx/config.h>
-#include <nuttx/reboot_notifier.h>
-#include <nuttx/trace.h>
+
+#include <unistd.h>
+
 #include <nuttx/irq.h>
+#include <nuttx/reboot_notifier.h>
 
-#include "rpmsgfs/rpmsgfs.h"
-#include "inode/inode.h"
-#include "aio/aio.h"
-#include "vfs/vfs.h"
-#include "fs_heap.h"
-#include "shm/shmfs.h"
+#include "fs_reboot.h"
 
 /****************************************************************************
  * Private Functions
  ****************************************************************************/
 
 /****************************************************************************
- * Name: sync_reboot_handler
+ * Name: fs_reboot_handler
+ *
+ * Description:
+ *   Flush the filesystems before power-off or restart.
+ *
  ****************************************************************************/
 
-static int sync_reboot_handler(FAR struct notifier_block *nb,
-                               unsigned long action, FAR void *data)
+static int fs_reboot_handler(FAR struct notifier_block *nb,
+                             unsigned long action, FAR void *data)
 {
+  /* sync() takes filesystem locks, which an interrupt handler cannot wait
+   * for.
+   */
+
   if ((action == SYS_POWER_OFF || action == SYS_RESTART) &&
-       !up_interrupt_context())
+      !up_interrupt_context())
     {
       sync();
     }
@@ -60,13 +65,9 @@ static int sync_reboot_handler(FAR struct notifier_block *nb,
  * Private Data
  ****************************************************************************/
 
-/****************************************************************************
- * Name: fs_sync_reboot_nb
- ****************************************************************************/
-
-static struct notifier_block g_sync_nb =
+static struct notifier_block g_fs_reboot_nb =
 {
-  sync_reboot_handler
+  fs_reboot_handler
 };
 
 /****************************************************************************
@@ -74,47 +75,14 @@ static struct notifier_block g_sync_nb =
  ****************************************************************************/
 
 /****************************************************************************
- * Name: fs_initialize
+ * Name: fs_reboot_initialize
  *
  * Description:
- *   This is called from the OS initialization logic to configure the file
- *   system.
+ *   Register the filesystem reboot notifier.
  *
  ****************************************************************************/
 
-void fs_initialize(void)
+void fs_reboot_initialize(void)
 {
-  fs_trace_begin();
-
-  fs_heap_initialize();
-
-  /* Initial inode, file, and VFS data structures */
-
-  inode_initialize();
-
-  file_initlk();
-
-#ifdef CONFIG_FS_AIO
-  /* Initialize for asynchronous I/O */
-
-  aio_initialize();
-
-#endif
-
-#ifdef CONFIG_FS_RPMSGFS_SERVER
-  rpmsgfs_server_init();
-#endif
-
-#ifdef CONFIG_FS_NOTIFY
-  notify_initialize();
-#endif
-
-#ifdef CONFIG_FS_SHMFS
-  /* The directory of the shared memory objects */
-
-  shmfs_initialize();
-#endif
-
-  register_reboot_notifier(&g_sync_nb);
-  fs_trace_end();
+  register_reboot_notifier(&g_fs_reboot_nb);
 }
diff --git a/fs/fs_reboot.h b/fs/fs_reboot.h
new file mode 100644
index 00000000000..bf4723c6f8e
--- /dev/null
+++ b/fs/fs_reboot.h
@@ -0,0 +1,46 @@
+/****************************************************************************
+ * fs/fs_reboot.h
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __FS_FS_REBOOT_H
+#define __FS_FS_REBOOT_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: fs_reboot_initialize
+ *
+ * Description:
+ *   Register the filesystem reboot notifier.
+ *
+ ****************************************************************************/
+
+void fs_reboot_initialize(void);
+
+#endif /* __FS_FS_REBOOT_H */

Reply via email to