From 657e1bf66b9406cd4c18af1265443e9ebf006f39 Mon Sep 17 00:00:00 2001 From: Joel Sherrill Date: Tue, 26 Oct 1999 20:17:13 +0000 Subject: Added initial cut at miniIMFS which leaves out memfile and directory readdir support. The next step is to add a mount table and configure either the miniIMFS or the full IMFS at the application level. --- c/src/lib/libc/Makefile.in | 9 ++-- c/src/lib/libc/base_fs.c | 7 +++ c/src/lib/libc/imfs.h | 16 +++++- c/src/lib/libc/imfs_eval.c | 8 +-- c/src/lib/libc/imfs_free.c | 62 ----------------------- c/src/lib/libc/imfs_fsunmount.c | 90 ++++++++++++++++++++++++++++++++++ c/src/lib/libc/imfs_handlers.c | 77 ----------------------------- c/src/lib/libc/imfs_init.c | 106 +++------------------------------------- c/src/lib/libc/imfs_initsupp.c | 97 ++++-------------------------------- c/src/lib/libc/libio.h | 2 +- c/src/lib/libc/memfile.c | 20 ++++++++ c/src/lib/libc/miniimfs_init.c | 71 +++++++++++++++++++++++++++ 12 files changed, 232 insertions(+), 333 deletions(-) create mode 100644 c/src/lib/libc/imfs_fsunmount.c delete mode 100644 c/src/lib/libc/imfs_handlers.c create mode 100644 c/src/lib/libc/miniimfs_init.c (limited to 'c/src/lib/libc') diff --git a/c/src/lib/libc/Makefile.in b/c/src/lib/libc/Makefile.in index 663fd2d5a9..9de6662ce5 100644 --- a/c/src/lib/libc/Makefile.in +++ b/c/src/lib/libc/Makefile.in @@ -24,10 +24,11 @@ BASE_FS_C_PIECES = base_fs mount unmount ioman libio libio_sockets eval \ fs_null_handlers IMFS_C_PIECES = imfs_chown imfs_creat imfs_directory imfs_eval imfs_free \ - imfs_gtkn imfs_init imfs_link imfs_mknod imfs_mount imfs_fchmod \ - imfs_rmnod imfs_unlink imfs_unmount imfs_utime imfs_ntype imfs_stat \ - imfs_getchild memfile deviceio imfs_handlers imfs_debug imfs_symlink \ - imfs_readlink imfs_fdatasync imfs_fcntl + imfs_fsunmount imfs_gtkn imfs_init imfs_initsupp imfs_link imfs_mknod \ + imfs_mount imfs_fchmod imfs_rmnod imfs_unlink imfs_unmount imfs_utime \ + imfs_ntype imfs_stat imfs_getchild memfile deviceio imfs_handlers_device \ + imfs_handlers_directory imfs_handlers_memfile imfs_debug imfs_symlink \ + imfs_readlink imfs_fdatasync imfs_fcntl miniimfs_init TERMIOS_C_PIECES = cfgetispeed cfgetospeed cfsetispeed cfsetospeed tcgetattr \ tcsetattr tcdrain tcflow tcflush termios \ diff --git a/c/src/lib/libc/base_fs.c b/c/src/lib/libc/base_fs.c index e5f53c042b..ee342afad6 100644 --- a/c/src/lib/libc/base_fs.c +++ b/c/src/lib/libc/base_fs.c @@ -52,6 +52,13 @@ void rtems_filesystem_initialize( void ) init_fs_mount_table(); + /* + * mount the first filesystem. + * + * NOTE: XXX This really needs to be read from a table of filesystems + * to mount initially and the miniIMFS needs to be shaken out. + */ + status = mount( &first_entry, &IMFS_ops, diff --git a/c/src/lib/libc/imfs.h b/c/src/lib/libc/imfs.h index 4aaa923982..d1be06bbf4 100644 --- a/c/src/lib/libc/imfs.h +++ b/c/src/lib/libc/imfs.h @@ -183,7 +183,9 @@ struct IMFS_jnode_tt { } while (0) typedef struct { - ino_t ino_count; + ino_t ino_count; + rtems_filesystem_file_handlers_r *memfile_handlers; + rtems_filesystem_file_handlers_r *directory_handlers; } IMFS_fs_info_t; #define increment_and_check_linkcounts( _fs_info ) \ @@ -214,6 +216,7 @@ extern rtems_filesystem_file_handlers_r IMFS_device_handlers; extern rtems_filesystem_file_handlers_r IMFS_memfile_handlers; extern rtems_filesystem_file_handlers_r IMFS_directory_handlers; extern rtems_filesystem_operations_table IMFS_ops; +extern rtems_filesystem_operations_table miniIMFS_ops; extern rtems_filesystem_limits_and_options_t IMFS_LIMITS_AND_OPTIONS; /* @@ -224,6 +227,17 @@ int IMFS_initialize( rtems_filesystem_mount_table_entry_t *mt_entry ); +int miniIMFS_initialize( + rtems_filesystem_mount_table_entry_t *mt_entry +); + +int IMFS_initialize_support( + rtems_filesystem_mount_table_entry_t *mt_entry, + rtems_filesystem_operations_table *op_table, + rtems_filesystem_file_handlers_r *memfile_handlers, + rtems_filesystem_file_handlers_r *directory_handlers +); + int IMFS_fsunmount( rtems_filesystem_mount_table_entry_t *mt_entry ); diff --git a/c/src/lib/libc/imfs_eval.c b/c/src/lib/libc/imfs_eval.c index e06301029f..ee488f1a19 100644 --- a/c/src/lib/libc/imfs_eval.c +++ b/c/src/lib/libc/imfs_eval.c @@ -32,11 +32,13 @@ int IMFS_Set_handlers( rtems_filesystem_location_info_t *loc ) { - IMFS_jnode_t *node = loc->node_access; + IMFS_jnode_t *node = loc->node_access; + IMFS_fs_info_t *fs_info; + fs_info = loc->mt_entry->fs_info; switch( node->type ) { case IMFS_DIRECTORY: - loc->handlers = &IMFS_directory_handlers; + loc->handlers = fs_info->directory_handlers; break; case IMFS_DEVICE: loc->handlers = &IMFS_device_handlers; @@ -46,7 +48,7 @@ int IMFS_Set_handlers( loc->handlers = &rtems_filesystem_null_handlers; break; case IMFS_MEMORY_FILE: - loc->handlers = &IMFS_memfile_handlers; + loc->handlers = fs_info->memfile_handlers; break; } diff --git a/c/src/lib/libc/imfs_free.c b/c/src/lib/libc/imfs_free.c index 8216547c12..1dc6fd9425 100644 --- a/c/src/lib/libc/imfs_free.c +++ b/c/src/lib/libc/imfs_free.c @@ -35,65 +35,3 @@ int IMFS_freenodinfo( return 0; } - -/* - * IMFS_freenod - * - * The following routine frees a node if possible. - * - * The routine returns 0 if the node was not freed and 1 if it was. - * - * NOTE: This routine is for INTERNAL IMFS use only. - */ - -int IMFS_freenod( - rtems_filesystem_location_info_t *pathloc -) -{ - IMFS_jnode_t *the_jnode; - - the_jnode = pathloc->node_access; - - if ( the_jnode->type == IMFS_DIRECTORY ) { - - /* - * You cannot remove a node that still has children - */ - - if ( ! Chain_Is_empty( &the_jnode->info.directory.Entries ) ) - return ENOTEMPTY; - - /* - * You cannot remove the file system root node. - */ - if ( pathloc->mt_entry->mt_fs_root.node_access == pathloc->node_access ) - return EBUSY; - - /* - * You cannot remove a mountpoint. - */ - if ( the_jnode->info.directory.mt_fs != NULL ) - return EBUSY; - } - - if ( !rtems_libio_is_file_open( the_jnode ) && - (the_jnode->st_nlink < 1) ) { - - /* - * Is the rtems_filesystem_current is this node? - */ - if ( rtems_filesystem_current.node_access == pathloc->node_access ) { - rtems_filesystem_current.node_access = NULL; - } - - /* - * Free memory associated with a memory file. - */ - if ( the_jnode->type == IMFS_MEMORY_FILE ) - IMFS_memfile_remove( the_jnode ); - - free( the_jnode ); - } - - return 0; -} diff --git a/c/src/lib/libc/imfs_fsunmount.c b/c/src/lib/libc/imfs_fsunmount.c new file mode 100644 index 0000000000..aa41b6c454 --- /dev/null +++ b/c/src/lib/libc/imfs_fsunmount.c @@ -0,0 +1,90 @@ +/* + * IMFS Initialization + * + * COPYRIGHT (c) 1989-1998. + * On-Line Applications Research Corporation (OAR). + * Copyright assigned to U.S. Government, 1994. + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.OARcorp.com/rtems/license.html. + * + * $Id$ + */ + +#include /* for mkdir */ +#include +#include +#include + +#include + +#include "imfs.h" +#include "libio_.h" + +#if defined(IMFS_DEBUG) +#include +#endif + +/* + * IMFS_fsunmount + */ + +#define jnode_get_control( jnode ) \ + (&jnode->info.directory.Entries) + +#define jnode_has_no_children( jnode ) \ + Chain_Is_empty( jnode_get_control( jnode ) ) + +#define jnode_has_children( jnode ) \ + ( ! jnode_has_no_children( jnode ) ) + +#define jnode_get_first_child( jnode ) \ + ((IMFS_jnode_t *)( Chain_Head( jnode_get_control( jnode ) )->next)) + + +int IMFS_fsunmount( + rtems_filesystem_mount_table_entry_t *temp_mt_entry +) +{ + IMFS_jnode_t *jnode; + IMFS_jnode_t *next; + rtems_filesystem_location_info_t loc; + int result = 0; + + /* + * Traverse tree that starts at the mt_fs_root and deallocate memory + * associated memory space + */ + + jnode = (IMFS_jnode_t *)temp_mt_entry->mt_fs_root.node_access; + + do { + next = jnode->Parent; + loc.node_access = (void *)jnode; + + if ( jnode->type != IMFS_DIRECTORY ) { + result = IMFS_unlink( &loc ); + if (result != 0) + return -1; + jnode = next; + } else if ( jnode_has_no_children( jnode ) ) { + result = IMFS_unlink( &loc ); + if (result != 0) + return -1; + jnode = next; + } + if ( jnode != NULL ) { + if ( jnode->type == IMFS_DIRECTORY ) { + if ( jnode_has_children( jnode ) ) + jnode = jnode_get_first_child( jnode ); + } + } + } while (jnode != NULL); + + return 0; +} + + + + diff --git a/c/src/lib/libc/imfs_handlers.c b/c/src/lib/libc/imfs_handlers.c deleted file mode 100644 index b7466a5072..0000000000 --- a/c/src/lib/libc/imfs_handlers.c +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Operations Tables for the IMFS - * - * COPYRIGHT (c) 1989-1998. - * On-Line Applications Research Corporation (OAR). - * Copyright assigned to U.S. Government, 1994. - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.OARcorp.com/rtems/license.html. - * - * $Id$ - */ - -#include - -#include "imfs.h" - -/* - * Set of operations handlers for operations on memfile entities. - */ - -rtems_filesystem_file_handlers_r IMFS_memfile_handlers = { - memfile_open, - memfile_close, - memfile_read, - memfile_write, - memfile_ioctl, - memfile_lseek, - IMFS_stat, - IMFS_fchmod, - memfile_ftruncate, - NULL, /* fpathconf */ - NULL, /* fsync */ - IMFS_fdatasync, - IMFS_fcntl -}; - -/* - * Set of operations handlers for operations on directories. - */ - -rtems_filesystem_file_handlers_r IMFS_directory_handlers = { - imfs_dir_open, - imfs_dir_close, - imfs_dir_read, - NULL, /* write */ - NULL, /* ioctl */ - imfs_dir_lseek, - imfs_dir_fstat, - IMFS_fchmod, - NULL, /* ftruncate */ - NULL, /* fpathconf */ - NULL, /* fsync */ - IMFS_fdatasync, - IMFS_fcntl -}; - -/* - * Handler table for IMFS device nodes - */ - -rtems_filesystem_file_handlers_r IMFS_device_handlers = { - device_open, - device_close, - device_read, - device_write, - device_ioctl, - device_lseek, - IMFS_stat, - IMFS_fchmod, - NULL, /* ftruncate */ - NULL, /* fpathconf */ - NULL, /* fsync */ - NULL, /* fdatasync */ - NULL /* fcntl */ -}; diff --git a/c/src/lib/libc/imfs_init.c b/c/src/lib/libc/imfs_init.c index a38fa89c33..8f44a4e2cd 100644 --- a/c/src/lib/libc/imfs_init.c +++ b/c/src/lib/libc/imfs_init.c @@ -26,7 +26,7 @@ #include #endif -/* +/* * IMFS file system operations table */ @@ -44,7 +44,7 @@ rtems_filesystem_operations_table IMFS_ops = { IMFS_initialize, IMFS_unmount, IMFS_fsunmount, - IMFS_utime, + IMFS_utime, IMFS_evaluate_link, IMFS_symlink, IMFS_readlink @@ -58,101 +58,11 @@ int IMFS_initialize( rtems_filesystem_mount_table_entry_t *temp_mt_entry ) { - IMFS_fs_info_t *fs_info; - IMFS_jnode_t *jnode; - - /* - * Create the root node - */ - - temp_mt_entry->mt_fs_root.node_access = IMFS_create_node( - NULL, - IMFS_DIRECTORY, - "", - ( S_IRWXO | S_IRWXG| S_IRWXU ), - NULL - ); - - temp_mt_entry->mt_fs_root.handlers = &IMFS_directory_handlers; - temp_mt_entry->mt_fs_root.ops = &IMFS_ops; - temp_mt_entry->pathconf_limits_and_options = IMFS_LIMITS_AND_OPTIONS; - - /* - * Create custom file system data. - */ - fs_info = calloc( 1, sizeof( IMFS_fs_info_t ) ); - if ( !fs_info ){ - free(temp_mt_entry->mt_fs_root.node_access); - return 1; - } - temp_mt_entry->fs_info = fs_info; - - /* - * Set st_ino for the root to 1. - */ - - fs_info->ino_count = 1; - - jnode = temp_mt_entry->mt_fs_root.node_access; - jnode->st_ino = fs_info->ino_count; - - return 0; -} - -#define jnode_get_control( jnode ) \ - (&jnode->info.directory.Entries) - -#define jnode_has_no_children( jnode ) \ - Chain_Is_empty( jnode_get_control( jnode ) ) - -#define jnode_has_children( jnode ) \ - ( ! jnode_has_no_children( jnode ) ) - -#define jnode_get_first_child( jnode ) \ - ((IMFS_jnode_t *)( Chain_Head( jnode_get_control( jnode ) )->next)) - - -int IMFS_fsunmount( - rtems_filesystem_mount_table_entry_t *temp_mt_entry -) -{ - IMFS_jnode_t *jnode; - IMFS_jnode_t *next; - rtems_filesystem_location_info_t loc; - int result = 0; - - /* - * Traverse tree that starts at the mt_fs_root and deallocate memory - * associated memory space - */ - - jnode = (IMFS_jnode_t *)temp_mt_entry->mt_fs_root.node_access; - - do { - next = jnode->Parent; - loc.node_access = (void *)jnode; - - if ( jnode->type != IMFS_DIRECTORY ) { - result = IMFS_unlink( &loc ); - if (result != 0) - return -1; - jnode = next; - } else if ( jnode_has_no_children( jnode ) ) { - result = IMFS_unlink( &loc ); - if (result != 0) - return -1; - jnode = next; - } - if ( jnode != NULL ) { - if ( jnode->type == IMFS_DIRECTORY ) { - if ( jnode_has_children( jnode ) ) - jnode = jnode_get_first_child( jnode ); - } - } - } while (jnode != NULL); - + IMFS_initialize_support( + temp_mt_entry, + &IMFS_ops, + &IMFS_memfile_handlers, + &IMFS_directory_handlers + ); return 0; } - - - diff --git a/c/src/lib/libc/imfs_initsupp.c b/c/src/lib/libc/imfs_initsupp.c index a38fa89c33..7b5d5fcc6a 100644 --- a/c/src/lib/libc/imfs_initsupp.c +++ b/c/src/lib/libc/imfs_initsupp.c @@ -26,36 +26,15 @@ #include #endif -/* - * IMFS file system operations table - */ - -rtems_filesystem_operations_table IMFS_ops = { - IMFS_eval_path, - IMFS_evaluate_for_make, - IMFS_link, - IMFS_unlink, - IMFS_node_type, - IMFS_mknod, - IMFS_rmnod, - IMFS_chown, - IMFS_freenodinfo, - IMFS_mount, - IMFS_initialize, - IMFS_unmount, - IMFS_fsunmount, - IMFS_utime, - IMFS_evaluate_link, - IMFS_symlink, - IMFS_readlink -}; - /* * IMFS_initialize */ -int IMFS_initialize( - rtems_filesystem_mount_table_entry_t *temp_mt_entry +int IMFS_initialize_support( + rtems_filesystem_mount_table_entry_t *temp_mt_entry, + rtems_filesystem_operations_table *op_table, + rtems_filesystem_file_handlers_r *memfile_handlers, + rtems_filesystem_file_handlers_r *directory_handlers ) { IMFS_fs_info_t *fs_info; @@ -73,8 +52,8 @@ int IMFS_initialize( NULL ); - temp_mt_entry->mt_fs_root.handlers = &IMFS_directory_handlers; - temp_mt_entry->mt_fs_root.ops = &IMFS_ops; + temp_mt_entry->mt_fs_root.handlers = directory_handlers; + temp_mt_entry->mt_fs_root.ops = op_table; temp_mt_entry->pathconf_limits_and_options = IMFS_LIMITS_AND_OPTIONS; /* @@ -91,68 +70,12 @@ int IMFS_initialize( * Set st_ino for the root to 1. */ - fs_info->ino_count = 1; + fs_info->ino_count = 1; + fs_info->memfile_handlers = memfile_handlers; + fs_info->memfile_handlers = directory_handlers; jnode = temp_mt_entry->mt_fs_root.node_access; jnode->st_ino = fs_info->ino_count; return 0; } - -#define jnode_get_control( jnode ) \ - (&jnode->info.directory.Entries) - -#define jnode_has_no_children( jnode ) \ - Chain_Is_empty( jnode_get_control( jnode ) ) - -#define jnode_has_children( jnode ) \ - ( ! jnode_has_no_children( jnode ) ) - -#define jnode_get_first_child( jnode ) \ - ((IMFS_jnode_t *)( Chain_Head( jnode_get_control( jnode ) )->next)) - - -int IMFS_fsunmount( - rtems_filesystem_mount_table_entry_t *temp_mt_entry -) -{ - IMFS_jnode_t *jnode; - IMFS_jnode_t *next; - rtems_filesystem_location_info_t loc; - int result = 0; - - /* - * Traverse tree that starts at the mt_fs_root and deallocate memory - * associated memory space - */ - - jnode = (IMFS_jnode_t *)temp_mt_entry->mt_fs_root.node_access; - - do { - next = jnode->Parent; - loc.node_access = (void *)jnode; - - if ( jnode->type != IMFS_DIRECTORY ) { - result = IMFS_unlink( &loc ); - if (result != 0) - return -1; - jnode = next; - } else if ( jnode_has_no_children( jnode ) ) { - result = IMFS_unlink( &loc ); - if (result != 0) - return -1; - jnode = next; - } - if ( jnode != NULL ) { - if ( jnode->type == IMFS_DIRECTORY ) { - if ( jnode_has_children( jnode ) ) - jnode = jnode_get_first_child( jnode ); - } - } - } while (jnode != NULL); - - return 0; -} - - - diff --git a/c/src/lib/libc/libio.h b/c/src/lib/libc/libio.h index 4cd1f3f6f6..a8c2c09090 100644 --- a/c/src/lib/libc/libio.h +++ b/c/src/lib/libc/libio.h @@ -306,7 +306,7 @@ typedef struct { * Structure for a mount table entry. */ -struct rtems_filesystem_mount_table_entry_tt{ +struct rtems_filesystem_mount_table_entry_tt { Chain_Node Node; rtems_filesystem_location_info_t mt_point_node; rtems_filesystem_location_info_t mt_fs_root; diff --git a/c/src/lib/libc/memfile.c b/c/src/lib/libc/memfile.c index 3abaeb8f17..3468490c90 100644 --- a/c/src/lib/libc/memfile.c +++ b/c/src/lib/libc/memfile.c @@ -29,6 +29,26 @@ #define MEMFILE_STATIC +/* + * Set of operations handlers for operations on memfile entities. + */ + +rtems_filesystem_file_handlers_r IMFS_memfile_handlers = { + memfile_open, + memfile_close, + memfile_read, + memfile_write, + memfile_ioctl, + memfile_lseek, + IMFS_stat, + IMFS_fchmod, + memfile_ftruncate, + NULL, /* fpathconf */ + NULL, /* fsync */ + IMFS_fdatasync, + IMFS_fcntl +}; + /* * Prototypes of private routines */ diff --git a/c/src/lib/libc/miniimfs_init.c b/c/src/lib/libc/miniimfs_init.c new file mode 100644 index 0000000000..983cde9439 --- /dev/null +++ b/c/src/lib/libc/miniimfs_init.c @@ -0,0 +1,71 @@ +/* + * Mini-IMFS Initialization + * + * COPYRIGHT (c) 1989-1998. + * On-Line Applications Research Corporation (OAR). + * Copyright assigned to U.S. Government, 1994. + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.OARcorp.com/rtems/license.html. + * + * $Id$ + */ + +#include /* for mkdir */ +#include +#include +#include + +#include + +#include "imfs.h" +#include "libio_.h" + +#if defined(IMFS_DEBUG) +#include +#endif + +/* + * miniIMFS file system operations table + */ + +rtems_filesystem_operations_table miniIMFS_ops = { + IMFS_eval_path, + IMFS_evaluate_for_make, + NULL, /* XXX IMFS_link, */ + NULL, /* XXX IMFS_unlink, */ + IMFS_node_type, + IMFS_mknod, + NULL, /* XXX IMFS_rmnod, */ + NULL, /* XXX IMFS_chown, */ + NULL, /* XXX IMFS_freenodinfo, */ + NULL, /* XXX IMFS_mount, */ + miniIMFS_initialize, + NULL, /* XXX IMFS_unmount, */ + NULL, /* XXX IMFS_fsunmount, */ + NULL, /* XXX IMFS_utime, */ + NULL, /* XXX IMFS_evaluate_link, */ + NULL, /* XXX IMFS_symlink, */ + NULL /* XXX IMFS_readlink */ +}; + +/* + * miniIMFS_initialize + */ + +int miniIMFS_initialize( + rtems_filesystem_mount_table_entry_t *temp_mt_entry +) +{ + IMFS_initialize_support( + temp_mt_entry, + &miniIMFS_ops, + &rtems_filesystem_null_handlers, /* for memfiles */ + &rtems_filesystem_null_handlers /* for directories */ + ); + return 0; +} + + + -- cgit v1.2.3