From 5b687c4da51f2dc54bf898dff74024590beeb7e1 Mon Sep 17 00:00:00 2001 From: Chris Johns Date: Fri, 30 May 2025 10:31:12 +1000 Subject: [PATCH] cpukit/libfs: Clean up the libfs mount handlers - Remove the `fsmount_me_t` handler moving its signature to `mount_t`. - The `mount_t` signature with the `data` lets file systems handle options and that means the shell `mount` command can mount more file systems. - Clean up the `mount` call's handling of the `mount_t` and `fsmount_me_t` structures. --- cpukit/include/rtems/imfs.h | 3 ++- cpukit/include/rtems/libio.h | 29 ++++++----------------- cpukit/libcsupport/src/__usrenv.c | 3 ++- cpukit/libcsupport/src/mount-mgr.c | 8 +++---- cpukit/libcsupport/src/mount.c | 8 +++---- cpukit/libfs/src/defaults/default_mount.c | 3 ++- cpukit/libfs/src/dosfs/msdos_init.c | 2 +- cpukit/libfs/src/imfs/imfs_mount.c | 4 +++- cpukit/libfs/src/rfs/rtems-rfs-rtems.c | 2 +- 9 files changed, 26 insertions(+), 36 deletions(-) diff --git a/cpukit/include/rtems/imfs.h b/cpukit/include/rtems/imfs.h index e4b403e947..cb41bd198a 100644 --- a/cpukit/include/rtems/imfs.h +++ b/cpukit/include/rtems/imfs.h @@ -855,7 +855,8 @@ extern int IMFS_make_generic_node( * @brief Mount an IMFS. */ extern int IMFS_mount( - rtems_filesystem_mount_table_entry_t *mt_entry /* IN */ + rtems_filesystem_mount_table_entry_t *mt_entry, /* IN */ + const void *data ); /** diff --git a/cpukit/include/rtems/libio.h b/cpukit/include/rtems/libio.h index 5424a2a03c..aa2b1782d9 100644 --- a/cpukit/include/rtems/libio.h +++ b/cpukit/include/rtems/libio.h @@ -278,22 +278,6 @@ typedef void (*rtems_filesystem_freenode_t)( * @see rtems_filesystem_default_mount(). */ typedef int (*rtems_filesystem_mount_t) ( - rtems_filesystem_mount_table_entry_t *mt_entry -); - -/** - * @brief Initializes a file system instance. - * - * This function must initialize the file system root node in the mount table - * entry. - * - * @param[in] mt_entry The mount table entry. - * @param[in] data The data provided by the user. - * - * @retval 0 Successful operation. - * @retval -1 An error occurred. The errno is set to indicate the error. - */ -typedef int (*rtems_filesystem_fsmount_me_t)( rtems_filesystem_mount_table_entry_t *mt_entry, const void *data ); @@ -637,7 +621,8 @@ void rtems_filesystem_default_freenode( * @see rtems_filesystem_mount_t. */ int rtems_filesystem_default_mount ( - rtems_filesystem_mount_table_entry_t *mt_entry /* IN */ + rtems_filesystem_mount_table_entry_t *mt_entry, /* IN */ + const void *data ); /** @@ -1295,7 +1280,7 @@ typedef off_t rtems_off64_t __attribute__((deprecated)); * @return The file system mount handler associated with the @a type, or * @c NULL if no such association exists. */ -rtems_filesystem_fsmount_me_t +rtems_filesystem_mount_t rtems_filesystem_get_mount_handler( const char *type ); @@ -1673,8 +1658,8 @@ typedef enum { * @brief File system table entry. */ typedef struct rtems_filesystem_table_t { - const char *type; - rtems_filesystem_fsmount_me_t mount_h; + const char *type; + rtems_filesystem_mount_t mount_h; } rtems_filesystem_table_t; /** @@ -1695,8 +1680,8 @@ extern rtems_chain_control rtems_filesystem_mount_table; * @retval -1 An error occurred. The @c errno indicates the error. */ int rtems_filesystem_register( - const char *type, - rtems_filesystem_fsmount_me_t mount_h + const char *type, + rtems_filesystem_mount_t mount_h ); /** diff --git a/cpukit/libcsupport/src/__usrenv.c b/cpukit/libcsupport/src/__usrenv.c index 59ee7cc31f..b9ae5c509b 100644 --- a/cpukit/libcsupport/src/__usrenv.c +++ b/cpukit/libcsupport/src/__usrenv.c @@ -143,7 +143,8 @@ static int null_op_clonenode( } static int null_op_mount( - rtems_filesystem_mount_table_entry_t *mt_entry + rtems_filesystem_mount_table_entry_t *mt_entry, + const void *data ) { return -1; diff --git a/cpukit/libcsupport/src/mount-mgr.c b/cpukit/libcsupport/src/mount-mgr.c index ac567c510d..4658e7ad0b 100644 --- a/cpukit/libcsupport/src/mount-mgr.c +++ b/cpukit/libcsupport/src/mount-mgr.c @@ -89,7 +89,7 @@ bool rtems_filesystem_iterate( typedef struct { const char *type; - rtems_filesystem_fsmount_me_t mount_h; + rtems_filesystem_mount_t mount_h; } find_arg; static bool find_handler(const rtems_filesystem_table_t *entry, void *arg) @@ -105,7 +105,7 @@ static bool find_handler(const rtems_filesystem_table_t *entry, void *arg) } } -rtems_filesystem_fsmount_me_t +rtems_filesystem_mount_t rtems_filesystem_get_mount_handler( const char *type ) @@ -124,8 +124,8 @@ rtems_filesystem_get_mount_handler( int rtems_filesystem_register( - const char *type, - rtems_filesystem_fsmount_me_t mount_h + const char *type, + rtems_filesystem_mount_t mount_h ) { rtems_chain_control *chain = &filesystem_chain; diff --git a/cpukit/libcsupport/src/mount.c b/cpukit/libcsupport/src/mount.c index 7590eda737..36ab29386a 100644 --- a/cpukit/libcsupport/src/mount.c +++ b/cpukit/libcsupport/src/mount.c @@ -136,7 +136,7 @@ static int register_subordinate_file_system( rtems_filesystem_eval_path_extract_currentloc( &ctx, &targetloc ); mt_point_node = rtems_filesystem_location_transform_to_global( &targetloc ); mt_entry->mt_point_node = mt_point_node; - rv = (*mt_point_node->location.mt_entry->ops->mount_h)( mt_entry ); + rv = (*mt_point_node->location.mt_entry->ops->mount_h)( mt_entry, target ); if ( rv == 0 ) { rtems_filesystem_mt_lock(); rtems_chain_append_unprotected( @@ -208,10 +208,10 @@ int mount( options == RTEMS_FILESYSTEM_READ_ONLY || options == RTEMS_FILESYSTEM_READ_WRITE ) { - rtems_filesystem_fsmount_me_t fsmount_me_h = + rtems_filesystem_mount_t mount_h = rtems_filesystem_get_mount_handler( filesystemtype ); - if ( fsmount_me_h != NULL ) { + if ( mount_h != NULL ) { size_t target_length = 0; rtems_filesystem_mount_table_entry_t *mt_entry = alloc_mount_table_entry( source, @@ -223,7 +223,7 @@ int mount( if ( mt_entry != NULL ) { mt_entry->writeable = options == RTEMS_FILESYSTEM_READ_WRITE; - rv = (*fsmount_me_h)( mt_entry, data ); + rv = (*mount_h)( mt_entry, data ); if ( rv == 0 ) { if ( target != NULL ) { rv = register_subordinate_file_system( mt_entry, target ); diff --git a/cpukit/libfs/src/defaults/default_mount.c b/cpukit/libfs/src/defaults/default_mount.c index 16c9fced02..9516b2154a 100644 --- a/cpukit/libfs/src/defaults/default_mount.c +++ b/cpukit/libfs/src/defaults/default_mount.c @@ -39,7 +39,8 @@ #include int rtems_filesystem_default_mount ( - rtems_filesystem_mount_table_entry_t *mt_entry /* IN */ + rtems_filesystem_mount_table_entry_t *mt_entry, /* IN */ + const void *data ) { rtems_set_errno_and_return_minus_one( ENOTSUP ); diff --git a/cpukit/libfs/src/dosfs/msdos_init.c b/cpukit/libfs/src/dosfs/msdos_init.c index 2ea3c025c7..07e6d613f7 100644 --- a/cpukit/libfs/src/dosfs/msdos_init.c +++ b/cpukit/libfs/src/dosfs/msdos_init.c @@ -63,7 +63,7 @@ const rtems_filesystem_operations_table msdos_ops = { .chown_h = rtems_filesystem_default_chown, .clonenod_h = msdos_clone_node_info, .freenod_h = msdos_free_node_info, - .mount_h = rtems_filesystem_default_mount, + .mount_h = rtems_dosfs_initialize, .unmount_h = rtems_filesystem_default_unmount, .fsunmount_me_h = msdos_shut_down, .utimens_h = msdos_utimens, diff --git a/cpukit/libfs/src/imfs/imfs_mount.c b/cpukit/libfs/src/imfs/imfs_mount.c index c35f9f96f4..f2aba954c0 100644 --- a/cpukit/libfs/src/imfs/imfs_mount.c +++ b/cpukit/libfs/src/imfs/imfs_mount.c @@ -43,11 +43,13 @@ #include -int IMFS_mount( rtems_filesystem_mount_table_entry_t *mt_entry ) +int IMFS_mount( rtems_filesystem_mount_table_entry_t *mt_entry, const void *data ) { int rv = 0; IMFS_jnode_t *node = mt_entry->mt_point_node->location.node_access; + (void) data; /* runtime options checks can be added here */ + if ( IMFS_is_directory( node ) ) { IMFS_directory_t *dir = (IMFS_directory_t *) node; diff --git a/cpukit/libfs/src/rfs/rtems-rfs-rtems.c b/cpukit/libfs/src/rfs/rtems-rfs-rtems.c index 58c082f2ee..39c4d29b5d 100644 --- a/cpukit/libfs/src/rfs/rtems-rfs-rtems.c +++ b/cpukit/libfs/src/rfs/rtems-rfs-rtems.c @@ -749,7 +749,7 @@ const rtems_filesystem_operations_table rtems_rfs_ops = .chown_h = rtems_rfs_rtems_chown, .clonenod_h = rtems_filesystem_default_clonenode, .freenod_h = rtems_filesystem_default_freenode, - .mount_h = rtems_filesystem_default_mount, + .mount_h = rtems_rfs_rtems_initialise, .unmount_h = rtems_filesystem_default_unmount, .fsunmount_me_h = rtems_rfs_rtems_shutdown, .utimens_h = rtems_rfs_rtems_utimens,