From b568ccb7455fa29df50205d5fc13802598ced1d6 Mon Sep 17 00:00:00 2001 From: Joel Sherrill Date: Tue, 2 Nov 1999 20:20:13 +0000 Subject: The object memfile.o was being included in the miniIMFS even though it should not have been. This required that IMFS_rmnod be split into three separate (per file type) routines to avoid dependencies. In the end, a miniIMFS application is 6K smaller than one using the full IMFS. --- c/src/exec/libfs/src/imfs/deviceio.c | 56 +++++++++++++ c/src/exec/libfs/src/imfs/imfs.h | 35 +++++++- c/src/exec/libfs/src/imfs/imfs_directory.c | 76 +++++++++++++++++ c/src/exec/libfs/src/imfs/imfs_handlers_device.c | 2 +- .../exec/libfs/src/imfs/imfs_handlers_directory.c | 2 +- c/src/exec/libfs/src/imfs/imfs_handlers_memfile.c | 2 +- c/src/exec/libfs/src/imfs/imfs_rmnod.c | 98 ---------------------- c/src/exec/libfs/src/imfs/imfs_unlink.c | 4 +- c/src/exec/libfs/src/imfs/memfile.c | 79 ++++++++++++----- c/src/exec/libfs/src/imfs/miniimfs_init.c | 1 - c/src/lib/libc/Makefile.in | 2 +- c/src/lib/libc/deviceio.c | 56 +++++++++++++ c/src/lib/libc/imfs.h | 35 +++++++- c/src/lib/libc/imfs_directory.c | 76 +++++++++++++++++ c/src/lib/libc/imfs_handlers_device.c | 2 +- c/src/lib/libc/imfs_handlers_directory.c | 2 +- c/src/lib/libc/imfs_handlers_memfile.c | 2 +- c/src/lib/libc/imfs_rmnod.c | 98 ---------------------- c/src/lib/libc/imfs_unlink.c | 4 +- c/src/lib/libc/memfile.c | 79 ++++++++++++----- c/src/lib/libc/miniimfs_init.c | 1 - c/src/libfs/src/imfs/deviceio.c | 56 +++++++++++++ c/src/libfs/src/imfs/imfs.h | 35 +++++++- c/src/libfs/src/imfs/imfs_directory.c | 76 +++++++++++++++++ c/src/libfs/src/imfs/imfs_handlers_device.c | 2 +- c/src/libfs/src/imfs/imfs_handlers_directory.c | 2 +- c/src/libfs/src/imfs/imfs_handlers_memfile.c | 2 +- c/src/libfs/src/imfs/imfs_rmnod.c | 98 ---------------------- c/src/libfs/src/imfs/imfs_unlink.c | 4 +- c/src/libfs/src/imfs/memfile.c | 79 ++++++++++++----- c/src/libfs/src/imfs/miniimfs_init.c | 1 - cpukit/libfs/src/imfs/deviceio.c | 56 +++++++++++++ cpukit/libfs/src/imfs/imfs.h | 35 +++++++- cpukit/libfs/src/imfs/imfs_directory.c | 76 +++++++++++++++++ cpukit/libfs/src/imfs/imfs_handlers_device.c | 2 +- cpukit/libfs/src/imfs/imfs_handlers_directory.c | 2 +- cpukit/libfs/src/imfs/imfs_handlers_memfile.c | 2 +- cpukit/libfs/src/imfs/imfs_rmnod.c | 98 ---------------------- cpukit/libfs/src/imfs/imfs_unlink.c | 4 +- cpukit/libfs/src/imfs/memfile.c | 79 ++++++++++++----- cpukit/libfs/src/imfs/miniimfs_init.c | 1 - 41 files changed, 909 insertions(+), 513 deletions(-) delete mode 100644 c/src/exec/libfs/src/imfs/imfs_rmnod.c delete mode 100644 c/src/lib/libc/imfs_rmnod.c delete mode 100644 c/src/libfs/src/imfs/imfs_rmnod.c delete mode 100644 cpukit/libfs/src/imfs/imfs_rmnod.c diff --git a/c/src/exec/libfs/src/imfs/deviceio.c b/c/src/exec/libfs/src/imfs/deviceio.c index f954decf6e..70b9706ada 100644 --- a/c/src/exec/libfs/src/imfs/deviceio.c +++ b/c/src/exec/libfs/src/imfs/deviceio.c @@ -17,6 +17,7 @@ #include #include +#include "libio_.h" #include "imfs.h" @@ -213,3 +214,58 @@ int device_lseek( * * This IMFS_stat() is used. */ + +/* + * device_rmnod + */ + +int device_rmnod( + rtems_filesystem_location_info_t *pathloc /* IN */ +) +{ + IMFS_jnode_t *the_jnode; + + the_jnode = (IMFS_jnode_t *) pathloc->node_access; + + /* + * Take the node out of the parent's chain that contains this node + */ + + if ( the_jnode->Parent != NULL ) { + Chain_Extract( (Chain_Node *) the_jnode ); + the_jnode->Parent = NULL; + } + + /* + * Decrement the link counter and see if we can free the space. + */ + + the_jnode->st_nlink--; + IMFS_update_ctime( the_jnode ); + + /* + * The file cannot be open and the link must be less than 1 to free. + */ + + 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. + */ + + free( the_jnode ); + } + + return 0; + +} + + + diff --git a/c/src/exec/libfs/src/imfs/imfs.h b/c/src/exec/libfs/src/imfs/imfs.h index d1be06bbf4..a88672c4b8 100644 --- a/c/src/exec/libfs/src/imfs/imfs.h +++ b/c/src/exec/libfs/src/imfs/imfs.h @@ -308,10 +308,6 @@ int IMFS_freenodinfo( rtems_filesystem_location_info_t *pathloc /* IN */ ); -int IMFS_rmnod( - rtems_filesystem_location_info_t *pathloc /* IN */ -); - int IMFS_mknod( const char *path, /* IN */ mode_t mode, /* IN */ @@ -353,92 +349,123 @@ int memfile_ftruncate( rtems_libio_t *iop, /* IN */ off_t length /* IN */ ); + int imfs_dir_open( rtems_libio_t *iop, /* IN */ const char *pathname, /* IN */ unsigned32 flag, /* IN */ unsigned32 mode /* IN */ ); + int imfs_dir_close( rtems_libio_t *iop /* IN */ ); + int imfs_dir_read( rtems_libio_t *iop, /* IN */ void *buffer, /* IN */ unsigned32 count /* IN */ ); + int imfs_dir_lseek( rtems_libio_t *iop, /* IN */ off_t offset, /* IN */ int whence /* IN */ ); + int imfs_dir_fstat( rtems_filesystem_location_info_t *loc, /* IN */ struct stat *buf /* OUT */ ); + +int imfs_dir_rmnod( + rtems_filesystem_location_info_t *pathloc /* IN */ +); + int memfile_open( rtems_libio_t *iop, /* IN */ const char *pathname, /* IN */ unsigned32 flag, /* IN */ unsigned32 mode /* IN */ ); + int memfile_close( rtems_libio_t *iop /* IN */ ); + int memfile_read( rtems_libio_t *iop, /* IN */ void *buffer, /* IN */ unsigned32 count /* IN */ ); + int memfile_write( rtems_libio_t *iop, /* IN */ const void *buffer, /* IN */ unsigned32 count /* IN */ ); + int memfile_ioctl( rtems_libio_t *iop, /* IN */ unsigned32 command, /* IN */ void *buffer /* IN */ ); + int memfile_lseek( rtems_libio_t *iop, /* IN */ off_t offset, /* IN */ int whence /* IN */ ); + +int memfile_rmnod( + rtems_filesystem_location_info_t *pathloc /* IN */ +); + int device_open( rtems_libio_t *iop, /* IN */ const char *pathname, /* IN */ unsigned32 flag, /* IN */ unsigned32 mode /* IN */ ); + int device_close( rtems_libio_t *iop /* IN */ ); + int device_read( rtems_libio_t *iop, /* IN */ void *buffer, /* IN */ unsigned32 count /* IN */ ); + int device_write( rtems_libio_t *iop, /* IN */ const void *buffer, /* IN */ unsigned32 count /* IN */ ); + int device_ioctl( rtems_libio_t *iop, /* IN */ unsigned32 command, /* IN */ void *buffer /* IN */ ); + int device_lseek( rtems_libio_t *iop, /* IN */ off_t offset, /* IN */ int whence /* IN */ ); + +int device_rmnod( + rtems_filesystem_location_info_t *pathloc /* IN */ +); + int IMFS_utime( rtems_filesystem_location_info_t *pathloc, /* IN */ time_t actime, /* IN */ time_t modtime /* IN */ ); + int IMFS_fchmod( rtems_filesystem_location_info_t *loc, mode_t mode diff --git a/c/src/exec/libfs/src/imfs/imfs_directory.c b/c/src/exec/libfs/src/imfs/imfs_directory.c index fbf4ba53a3..89672ec9ae 100644 --- a/c/src/exec/libfs/src/imfs/imfs_directory.c +++ b/c/src/exec/libfs/src/imfs/imfs_directory.c @@ -269,4 +269,80 @@ int imfs_dir_fstat( return 0; } +/* + * IMFS_dir_rmnod + * + * This routine is available from the optable to remove a node + * from the IMFS file system. + */ + +int imfs_dir_rmnod( + rtems_filesystem_location_info_t *pathloc /* IN */ +) +{ + IMFS_jnode_t *the_jnode; + + the_jnode = (IMFS_jnode_t *) pathloc->node_access; + + /* + * You cannot remove a node that still has children + */ + + if ( ! Chain_Is_empty( &the_jnode->info.directory.Entries ) ) + set_errno_and_return_minus_one( ENOTEMPTY ); + + /* + * You cannot remove the file system root node. + */ + + if ( pathloc->mt_entry->mt_fs_root.node_access == pathloc->node_access ) + set_errno_and_return_minus_one( EBUSY ); + + /* + * You cannot remove a mountpoint. + */ + + if ( the_jnode->info.directory.mt_fs != NULL ) + set_errno_and_return_minus_one( EBUSY ); + + /* + * Take the node out of the parent's chain that contains this node + */ + + if ( the_jnode->Parent != NULL ) { + Chain_Extract( (Chain_Node *) the_jnode ); + the_jnode->Parent = NULL; + } + + /* + * Decrement the link counter and see if we can free the space. + */ + + the_jnode->st_nlink--; + IMFS_update_ctime( the_jnode ); + + /* + * The file cannot be open and the link must be less than 1 to free. + */ + + 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. + */ + + free( the_jnode ); + } + + return 0; + +} + diff --git a/c/src/exec/libfs/src/imfs/imfs_handlers_device.c b/c/src/exec/libfs/src/imfs/imfs_handlers_device.c index b6b9c808a0..24b7ffa5bb 100644 --- a/c/src/exec/libfs/src/imfs/imfs_handlers_device.c +++ b/c/src/exec/libfs/src/imfs/imfs_handlers_device.c @@ -34,5 +34,5 @@ rtems_filesystem_file_handlers_r IMFS_device_handlers = { NULL, /* fsync */ NULL, /* fdatasync */ NULL, /* fcntl */ - IMFS_rmnod + device_rmnod }; diff --git a/c/src/exec/libfs/src/imfs/imfs_handlers_directory.c b/c/src/exec/libfs/src/imfs/imfs_handlers_directory.c index 364f3cdf26..0ee06d8ebf 100644 --- a/c/src/exec/libfs/src/imfs/imfs_handlers_directory.c +++ b/c/src/exec/libfs/src/imfs/imfs_handlers_directory.c @@ -34,7 +34,7 @@ rtems_filesystem_file_handlers_r IMFS_directory_handlers = { NULL, /* fsync */ IMFS_fdatasync, IMFS_fcntl, - IMFS_rmnod + imfs_dir_rmnod }; diff --git a/c/src/exec/libfs/src/imfs/imfs_handlers_memfile.c b/c/src/exec/libfs/src/imfs/imfs_handlers_memfile.c index f622c99558..20ef3c57b3 100644 --- a/c/src/exec/libfs/src/imfs/imfs_handlers_memfile.c +++ b/c/src/exec/libfs/src/imfs/imfs_handlers_memfile.c @@ -34,5 +34,5 @@ rtems_filesystem_file_handlers_r IMFS_memfile_handlers = { NULL, /* fsync */ IMFS_fdatasync, IMFS_fcntl, - IMFS_rmnod + memfile_rmnod }; diff --git a/c/src/exec/libfs/src/imfs/imfs_rmnod.c b/c/src/exec/libfs/src/imfs/imfs_rmnod.c deleted file mode 100644 index 3768b9543d..0000000000 --- a/c/src/exec/libfs/src/imfs/imfs_rmnod.c +++ /dev/null @@ -1,98 +0,0 @@ -/* - * IMFS_rmnod - * - * This routine is available from the optable to remove a node - * from the IMFS file system. - * - * 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 "libio_.h" -#include "imfs.h" - - -int IMFS_rmnod( - rtems_filesystem_location_info_t *pathloc /* IN */ -) -{ - IMFS_jnode_t *the_jnode; - - the_jnode = (IMFS_jnode_t *) 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 ) ) - set_errno_and_return_minus_one( ENOTEMPTY ); - - /* - * You cannot remove the file system root node. - */ - - if ( pathloc->mt_entry->mt_fs_root.node_access == pathloc->node_access ) - set_errno_and_return_minus_one( EBUSY ); - - /* - * You cannot remove a mountpoint. - */ - - if ( the_jnode->info.directory.mt_fs != NULL ) - set_errno_and_return_minus_one( EBUSY ); - } - - /* - * Take the node out of the parent's chain that contains this node - */ - - if ( the_jnode->Parent != NULL ) { - Chain_Extract( (Chain_Node *) the_jnode ); - the_jnode->Parent = NULL; - } - - /* - * Decrement the link counter and see if we can free the space. - */ - - the_jnode->st_nlink--; - IMFS_update_ctime( the_jnode ); - - /* - * The file cannot be open and the link must be less than 1 to free. - */ - - 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/exec/libfs/src/imfs/imfs_unlink.c b/c/src/exec/libfs/src/imfs/imfs_unlink.c index 4e0ca26b2a..e138064e61 100644 --- a/c/src/exec/libfs/src/imfs/imfs_unlink.c +++ b/c/src/exec/libfs/src/imfs/imfs_unlink.c @@ -55,13 +55,13 @@ int IMFS_unlink( node->info.hard_link.link_node->st_nlink --; IMFS_update_ctime( node->info.hard_link.link_node ); if ( node->info.hard_link.link_node->st_nlink < 1) { - result = IMFS_rmnod( &the_link ); + result = (*loc->handlers->rmnod)( &the_link ); if ( result != 0 ) return -1; } } - result = IMFS_rmnod( loc ); + result = (*loc->handlers->rmnod)( &the_link ); return result; } diff --git a/c/src/exec/libfs/src/imfs/memfile.c b/c/src/exec/libfs/src/imfs/memfile.c index 3468490c90..0a3b30d38f 100644 --- a/c/src/exec/libfs/src/imfs/memfile.c +++ b/c/src/exec/libfs/src/imfs/memfile.c @@ -29,26 +29,6 @@ #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 */ @@ -1056,3 +1036,62 @@ fflush(stdout); memfile_blocks_allocated--; } + +/* + * memfile_rmnod + * + * This routine is available from the optable to remove a node + * from the IMFS file system. + */ + +int memfile_rmnod( + rtems_filesystem_location_info_t *pathloc /* IN */ +) +{ + IMFS_jnode_t *the_jnode; + + the_jnode = (IMFS_jnode_t *) pathloc->node_access; + + /* + * Take the node out of the parent's chain that contains this node + */ + + if ( the_jnode->Parent != NULL ) { + Chain_Extract( (Chain_Node *) the_jnode ); + the_jnode->Parent = NULL; + } + + /* + * Decrement the link counter and see if we can free the space. + */ + + the_jnode->st_nlink--; + IMFS_update_ctime( the_jnode ); + + /* + * The file cannot be open and the link must be less than 1 to free. + */ + + 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. + */ + + IMFS_memfile_remove( the_jnode ); + + free( the_jnode ); + } + + return 0; + +} + + diff --git a/c/src/exec/libfs/src/imfs/miniimfs_init.c b/c/src/exec/libfs/src/imfs/miniimfs_init.c index 983cde9439..865822fbfc 100644 --- a/c/src/exec/libfs/src/imfs/miniimfs_init.c +++ b/c/src/exec/libfs/src/imfs/miniimfs_init.c @@ -37,7 +37,6 @@ rtems_filesystem_operations_table miniIMFS_ops = { 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, */ diff --git a/c/src/lib/libc/Makefile.in b/c/src/lib/libc/Makefile.in index 361f73d085..e91e2dd478 100644 --- a/c/src/lib/libc/Makefile.in +++ b/c/src/lib/libc/Makefile.in @@ -25,7 +25,7 @@ BASE_FS_C_PIECES = base_fs mount unmount ioman libio libio_sockets eval \ IMFS_C_PIECES = imfs_chown imfs_creat imfs_directory imfs_eval imfs_free \ 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_mount imfs_fchmod 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 diff --git a/c/src/lib/libc/deviceio.c b/c/src/lib/libc/deviceio.c index f954decf6e..70b9706ada 100644 --- a/c/src/lib/libc/deviceio.c +++ b/c/src/lib/libc/deviceio.c @@ -17,6 +17,7 @@ #include #include +#include "libio_.h" #include "imfs.h" @@ -213,3 +214,58 @@ int device_lseek( * * This IMFS_stat() is used. */ + +/* + * device_rmnod + */ + +int device_rmnod( + rtems_filesystem_location_info_t *pathloc /* IN */ +) +{ + IMFS_jnode_t *the_jnode; + + the_jnode = (IMFS_jnode_t *) pathloc->node_access; + + /* + * Take the node out of the parent's chain that contains this node + */ + + if ( the_jnode->Parent != NULL ) { + Chain_Extract( (Chain_Node *) the_jnode ); + the_jnode->Parent = NULL; + } + + /* + * Decrement the link counter and see if we can free the space. + */ + + the_jnode->st_nlink--; + IMFS_update_ctime( the_jnode ); + + /* + * The file cannot be open and the link must be less than 1 to free. + */ + + 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. + */ + + free( the_jnode ); + } + + return 0; + +} + + + diff --git a/c/src/lib/libc/imfs.h b/c/src/lib/libc/imfs.h index d1be06bbf4..a88672c4b8 100644 --- a/c/src/lib/libc/imfs.h +++ b/c/src/lib/libc/imfs.h @@ -308,10 +308,6 @@ int IMFS_freenodinfo( rtems_filesystem_location_info_t *pathloc /* IN */ ); -int IMFS_rmnod( - rtems_filesystem_location_info_t *pathloc /* IN */ -); - int IMFS_mknod( const char *path, /* IN */ mode_t mode, /* IN */ @@ -353,92 +349,123 @@ int memfile_ftruncate( rtems_libio_t *iop, /* IN */ off_t length /* IN */ ); + int imfs_dir_open( rtems_libio_t *iop, /* IN */ const char *pathname, /* IN */ unsigned32 flag, /* IN */ unsigned32 mode /* IN */ ); + int imfs_dir_close( rtems_libio_t *iop /* IN */ ); + int imfs_dir_read( rtems_libio_t *iop, /* IN */ void *buffer, /* IN */ unsigned32 count /* IN */ ); + int imfs_dir_lseek( rtems_libio_t *iop, /* IN */ off_t offset, /* IN */ int whence /* IN */ ); + int imfs_dir_fstat( rtems_filesystem_location_info_t *loc, /* IN */ struct stat *buf /* OUT */ ); + +int imfs_dir_rmnod( + rtems_filesystem_location_info_t *pathloc /* IN */ +); + int memfile_open( rtems_libio_t *iop, /* IN */ const char *pathname, /* IN */ unsigned32 flag, /* IN */ unsigned32 mode /* IN */ ); + int memfile_close( rtems_libio_t *iop /* IN */ ); + int memfile_read( rtems_libio_t *iop, /* IN */ void *buffer, /* IN */ unsigned32 count /* IN */ ); + int memfile_write( rtems_libio_t *iop, /* IN */ const void *buffer, /* IN */ unsigned32 count /* IN */ ); + int memfile_ioctl( rtems_libio_t *iop, /* IN */ unsigned32 command, /* IN */ void *buffer /* IN */ ); + int memfile_lseek( rtems_libio_t *iop, /* IN */ off_t offset, /* IN */ int whence /* IN */ ); + +int memfile_rmnod( + rtems_filesystem_location_info_t *pathloc /* IN */ +); + int device_open( rtems_libio_t *iop, /* IN */ const char *pathname, /* IN */ unsigned32 flag, /* IN */ unsigned32 mode /* IN */ ); + int device_close( rtems_libio_t *iop /* IN */ ); + int device_read( rtems_libio_t *iop, /* IN */ void *buffer, /* IN */ unsigned32 count /* IN */ ); + int device_write( rtems_libio_t *iop, /* IN */ const void *buffer, /* IN */ unsigned32 count /* IN */ ); + int device_ioctl( rtems_libio_t *iop, /* IN */ unsigned32 command, /* IN */ void *buffer /* IN */ ); + int device_lseek( rtems_libio_t *iop, /* IN */ off_t offset, /* IN */ int whence /* IN */ ); + +int device_rmnod( + rtems_filesystem_location_info_t *pathloc /* IN */ +); + int IMFS_utime( rtems_filesystem_location_info_t *pathloc, /* IN */ time_t actime, /* IN */ time_t modtime /* IN */ ); + int IMFS_fchmod( rtems_filesystem_location_info_t *loc, mode_t mode diff --git a/c/src/lib/libc/imfs_directory.c b/c/src/lib/libc/imfs_directory.c index fbf4ba53a3..89672ec9ae 100644 --- a/c/src/lib/libc/imfs_directory.c +++ b/c/src/lib/libc/imfs_directory.c @@ -269,4 +269,80 @@ int imfs_dir_fstat( return 0; } +/* + * IMFS_dir_rmnod + * + * This routine is available from the optable to remove a node + * from the IMFS file system. + */ + +int imfs_dir_rmnod( + rtems_filesystem_location_info_t *pathloc /* IN */ +) +{ + IMFS_jnode_t *the_jnode; + + the_jnode = (IMFS_jnode_t *) pathloc->node_access; + + /* + * You cannot remove a node that still has children + */ + + if ( ! Chain_Is_empty( &the_jnode->info.directory.Entries ) ) + set_errno_and_return_minus_one( ENOTEMPTY ); + + /* + * You cannot remove the file system root node. + */ + + if ( pathloc->mt_entry->mt_fs_root.node_access == pathloc->node_access ) + set_errno_and_return_minus_one( EBUSY ); + + /* + * You cannot remove a mountpoint. + */ + + if ( the_jnode->info.directory.mt_fs != NULL ) + set_errno_and_return_minus_one( EBUSY ); + + /* + * Take the node out of the parent's chain that contains this node + */ + + if ( the_jnode->Parent != NULL ) { + Chain_Extract( (Chain_Node *) the_jnode ); + the_jnode->Parent = NULL; + } + + /* + * Decrement the link counter and see if we can free the space. + */ + + the_jnode->st_nlink--; + IMFS_update_ctime( the_jnode ); + + /* + * The file cannot be open and the link must be less than 1 to free. + */ + + 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. + */ + + free( the_jnode ); + } + + return 0; + +} + diff --git a/c/src/lib/libc/imfs_handlers_device.c b/c/src/lib/libc/imfs_handlers_device.c index b6b9c808a0..24b7ffa5bb 100644 --- a/c/src/lib/libc/imfs_handlers_device.c +++ b/c/src/lib/libc/imfs_handlers_device.c @@ -34,5 +34,5 @@ rtems_filesystem_file_handlers_r IMFS_device_handlers = { NULL, /* fsync */ NULL, /* fdatasync */ NULL, /* fcntl */ - IMFS_rmnod + device_rmnod }; diff --git a/c/src/lib/libc/imfs_handlers_directory.c b/c/src/lib/libc/imfs_handlers_directory.c index 364f3cdf26..0ee06d8ebf 100644 --- a/c/src/lib/libc/imfs_handlers_directory.c +++ b/c/src/lib/libc/imfs_handlers_directory.c @@ -34,7 +34,7 @@ rtems_filesystem_file_handlers_r IMFS_directory_handlers = { NULL, /* fsync */ IMFS_fdatasync, IMFS_fcntl, - IMFS_rmnod + imfs_dir_rmnod }; diff --git a/c/src/lib/libc/imfs_handlers_memfile.c b/c/src/lib/libc/imfs_handlers_memfile.c index f622c99558..20ef3c57b3 100644 --- a/c/src/lib/libc/imfs_handlers_memfile.c +++ b/c/src/lib/libc/imfs_handlers_memfile.c @@ -34,5 +34,5 @@ rtems_filesystem_file_handlers_r IMFS_memfile_handlers = { NULL, /* fsync */ IMFS_fdatasync, IMFS_fcntl, - IMFS_rmnod + memfile_rmnod }; diff --git a/c/src/lib/libc/imfs_rmnod.c b/c/src/lib/libc/imfs_rmnod.c deleted file mode 100644 index 3768b9543d..0000000000 --- a/c/src/lib/libc/imfs_rmnod.c +++ /dev/null @@ -1,98 +0,0 @@ -/* - * IMFS_rmnod - * - * This routine is available from the optable to remove a node - * from the IMFS file system. - * - * 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 "libio_.h" -#include "imfs.h" - - -int IMFS_rmnod( - rtems_filesystem_location_info_t *pathloc /* IN */ -) -{ - IMFS_jnode_t *the_jnode; - - the_jnode = (IMFS_jnode_t *) 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 ) ) - set_errno_and_return_minus_one( ENOTEMPTY ); - - /* - * You cannot remove the file system root node. - */ - - if ( pathloc->mt_entry->mt_fs_root.node_access == pathloc->node_access ) - set_errno_and_return_minus_one( EBUSY ); - - /* - * You cannot remove a mountpoint. - */ - - if ( the_jnode->info.directory.mt_fs != NULL ) - set_errno_and_return_minus_one( EBUSY ); - } - - /* - * Take the node out of the parent's chain that contains this node - */ - - if ( the_jnode->Parent != NULL ) { - Chain_Extract( (Chain_Node *) the_jnode ); - the_jnode->Parent = NULL; - } - - /* - * Decrement the link counter and see if we can free the space. - */ - - the_jnode->st_nlink--; - IMFS_update_ctime( the_jnode ); - - /* - * The file cannot be open and the link must be less than 1 to free. - */ - - 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_unlink.c b/c/src/lib/libc/imfs_unlink.c index 4e0ca26b2a..e138064e61 100644 --- a/c/src/lib/libc/imfs_unlink.c +++ b/c/src/lib/libc/imfs_unlink.c @@ -55,13 +55,13 @@ int IMFS_unlink( node->info.hard_link.link_node->st_nlink --; IMFS_update_ctime( node->info.hard_link.link_node ); if ( node->info.hard_link.link_node->st_nlink < 1) { - result = IMFS_rmnod( &the_link ); + result = (*loc->handlers->rmnod)( &the_link ); if ( result != 0 ) return -1; } } - result = IMFS_rmnod( loc ); + result = (*loc->handlers->rmnod)( &the_link ); return result; } diff --git a/c/src/lib/libc/memfile.c b/c/src/lib/libc/memfile.c index 3468490c90..0a3b30d38f 100644 --- a/c/src/lib/libc/memfile.c +++ b/c/src/lib/libc/memfile.c @@ -29,26 +29,6 @@ #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 */ @@ -1056,3 +1036,62 @@ fflush(stdout); memfile_blocks_allocated--; } + +/* + * memfile_rmnod + * + * This routine is available from the optable to remove a node + * from the IMFS file system. + */ + +int memfile_rmnod( + rtems_filesystem_location_info_t *pathloc /* IN */ +) +{ + IMFS_jnode_t *the_jnode; + + the_jnode = (IMFS_jnode_t *) pathloc->node_access; + + /* + * Take the node out of the parent's chain that contains this node + */ + + if ( the_jnode->Parent != NULL ) { + Chain_Extract( (Chain_Node *) the_jnode ); + the_jnode->Parent = NULL; + } + + /* + * Decrement the link counter and see if we can free the space. + */ + + the_jnode->st_nlink--; + IMFS_update_ctime( the_jnode ); + + /* + * The file cannot be open and the link must be less than 1 to free. + */ + + 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. + */ + + IMFS_memfile_remove( the_jnode ); + + free( the_jnode ); + } + + return 0; + +} + + diff --git a/c/src/lib/libc/miniimfs_init.c b/c/src/lib/libc/miniimfs_init.c index 983cde9439..865822fbfc 100644 --- a/c/src/lib/libc/miniimfs_init.c +++ b/c/src/lib/libc/miniimfs_init.c @@ -37,7 +37,6 @@ rtems_filesystem_operations_table miniIMFS_ops = { 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, */ diff --git a/c/src/libfs/src/imfs/deviceio.c b/c/src/libfs/src/imfs/deviceio.c index f954decf6e..70b9706ada 100644 --- a/c/src/libfs/src/imfs/deviceio.c +++ b/c/src/libfs/src/imfs/deviceio.c @@ -17,6 +17,7 @@ #include #include +#include "libio_.h" #include "imfs.h" @@ -213,3 +214,58 @@ int device_lseek( * * This IMFS_stat() is used. */ + +/* + * device_rmnod + */ + +int device_rmnod( + rtems_filesystem_location_info_t *pathloc /* IN */ +) +{ + IMFS_jnode_t *the_jnode; + + the_jnode = (IMFS_jnode_t *) pathloc->node_access; + + /* + * Take the node out of the parent's chain that contains this node + */ + + if ( the_jnode->Parent != NULL ) { + Chain_Extract( (Chain_Node *) the_jnode ); + the_jnode->Parent = NULL; + } + + /* + * Decrement the link counter and see if we can free the space. + */ + + the_jnode->st_nlink--; + IMFS_update_ctime( the_jnode ); + + /* + * The file cannot be open and the link must be less than 1 to free. + */ + + 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. + */ + + free( the_jnode ); + } + + return 0; + +} + + + diff --git a/c/src/libfs/src/imfs/imfs.h b/c/src/libfs/src/imfs/imfs.h index d1be06bbf4..a88672c4b8 100644 --- a/c/src/libfs/src/imfs/imfs.h +++ b/c/src/libfs/src/imfs/imfs.h @@ -308,10 +308,6 @@ int IMFS_freenodinfo( rtems_filesystem_location_info_t *pathloc /* IN */ ); -int IMFS_rmnod( - rtems_filesystem_location_info_t *pathloc /* IN */ -); - int IMFS_mknod( const char *path, /* IN */ mode_t mode, /* IN */ @@ -353,92 +349,123 @@ int memfile_ftruncate( rtems_libio_t *iop, /* IN */ off_t length /* IN */ ); + int imfs_dir_open( rtems_libio_t *iop, /* IN */ const char *pathname, /* IN */ unsigned32 flag, /* IN */ unsigned32 mode /* IN */ ); + int imfs_dir_close( rtems_libio_t *iop /* IN */ ); + int imfs_dir_read( rtems_libio_t *iop, /* IN */ void *buffer, /* IN */ unsigned32 count /* IN */ ); + int imfs_dir_lseek( rtems_libio_t *iop, /* IN */ off_t offset, /* IN */ int whence /* IN */ ); + int imfs_dir_fstat( rtems_filesystem_location_info_t *loc, /* IN */ struct stat *buf /* OUT */ ); + +int imfs_dir_rmnod( + rtems_filesystem_location_info_t *pathloc /* IN */ +); + int memfile_open( rtems_libio_t *iop, /* IN */ const char *pathname, /* IN */ unsigned32 flag, /* IN */ unsigned32 mode /* IN */ ); + int memfile_close( rtems_libio_t *iop /* IN */ ); + int memfile_read( rtems_libio_t *iop, /* IN */ void *buffer, /* IN */ unsigned32 count /* IN */ ); + int memfile_write( rtems_libio_t *iop, /* IN */ const void *buffer, /* IN */ unsigned32 count /* IN */ ); + int memfile_ioctl( rtems_libio_t *iop, /* IN */ unsigned32 command, /* IN */ void *buffer /* IN */ ); + int memfile_lseek( rtems_libio_t *iop, /* IN */ off_t offset, /* IN */ int whence /* IN */ ); + +int memfile_rmnod( + rtems_filesystem_location_info_t *pathloc /* IN */ +); + int device_open( rtems_libio_t *iop, /* IN */ const char *pathname, /* IN */ unsigned32 flag, /* IN */ unsigned32 mode /* IN */ ); + int device_close( rtems_libio_t *iop /* IN */ ); + int device_read( rtems_libio_t *iop, /* IN */ void *buffer, /* IN */ unsigned32 count /* IN */ ); + int device_write( rtems_libio_t *iop, /* IN */ const void *buffer, /* IN */ unsigned32 count /* IN */ ); + int device_ioctl( rtems_libio_t *iop, /* IN */ unsigned32 command, /* IN */ void *buffer /* IN */ ); + int device_lseek( rtems_libio_t *iop, /* IN */ off_t offset, /* IN */ int whence /* IN */ ); + +int device_rmnod( + rtems_filesystem_location_info_t *pathloc /* IN */ +); + int IMFS_utime( rtems_filesystem_location_info_t *pathloc, /* IN */ time_t actime, /* IN */ time_t modtime /* IN */ ); + int IMFS_fchmod( rtems_filesystem_location_info_t *loc, mode_t mode diff --git a/c/src/libfs/src/imfs/imfs_directory.c b/c/src/libfs/src/imfs/imfs_directory.c index fbf4ba53a3..89672ec9ae 100644 --- a/c/src/libfs/src/imfs/imfs_directory.c +++ b/c/src/libfs/src/imfs/imfs_directory.c @@ -269,4 +269,80 @@ int imfs_dir_fstat( return 0; } +/* + * IMFS_dir_rmnod + * + * This routine is available from the optable to remove a node + * from the IMFS file system. + */ + +int imfs_dir_rmnod( + rtems_filesystem_location_info_t *pathloc /* IN */ +) +{ + IMFS_jnode_t *the_jnode; + + the_jnode = (IMFS_jnode_t *) pathloc->node_access; + + /* + * You cannot remove a node that still has children + */ + + if ( ! Chain_Is_empty( &the_jnode->info.directory.Entries ) ) + set_errno_and_return_minus_one( ENOTEMPTY ); + + /* + * You cannot remove the file system root node. + */ + + if ( pathloc->mt_entry->mt_fs_root.node_access == pathloc->node_access ) + set_errno_and_return_minus_one( EBUSY ); + + /* + * You cannot remove a mountpoint. + */ + + if ( the_jnode->info.directory.mt_fs != NULL ) + set_errno_and_return_minus_one( EBUSY ); + + /* + * Take the node out of the parent's chain that contains this node + */ + + if ( the_jnode->Parent != NULL ) { + Chain_Extract( (Chain_Node *) the_jnode ); + the_jnode->Parent = NULL; + } + + /* + * Decrement the link counter and see if we can free the space. + */ + + the_jnode->st_nlink--; + IMFS_update_ctime( the_jnode ); + + /* + * The file cannot be open and the link must be less than 1 to free. + */ + + 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. + */ + + free( the_jnode ); + } + + return 0; + +} + diff --git a/c/src/libfs/src/imfs/imfs_handlers_device.c b/c/src/libfs/src/imfs/imfs_handlers_device.c index b6b9c808a0..24b7ffa5bb 100644 --- a/c/src/libfs/src/imfs/imfs_handlers_device.c +++ b/c/src/libfs/src/imfs/imfs_handlers_device.c @@ -34,5 +34,5 @@ rtems_filesystem_file_handlers_r IMFS_device_handlers = { NULL, /* fsync */ NULL, /* fdatasync */ NULL, /* fcntl */ - IMFS_rmnod + device_rmnod }; diff --git a/c/src/libfs/src/imfs/imfs_handlers_directory.c b/c/src/libfs/src/imfs/imfs_handlers_directory.c index 364f3cdf26..0ee06d8ebf 100644 --- a/c/src/libfs/src/imfs/imfs_handlers_directory.c +++ b/c/src/libfs/src/imfs/imfs_handlers_directory.c @@ -34,7 +34,7 @@ rtems_filesystem_file_handlers_r IMFS_directory_handlers = { NULL, /* fsync */ IMFS_fdatasync, IMFS_fcntl, - IMFS_rmnod + imfs_dir_rmnod }; diff --git a/c/src/libfs/src/imfs/imfs_handlers_memfile.c b/c/src/libfs/src/imfs/imfs_handlers_memfile.c index f622c99558..20ef3c57b3 100644 --- a/c/src/libfs/src/imfs/imfs_handlers_memfile.c +++ b/c/src/libfs/src/imfs/imfs_handlers_memfile.c @@ -34,5 +34,5 @@ rtems_filesystem_file_handlers_r IMFS_memfile_handlers = { NULL, /* fsync */ IMFS_fdatasync, IMFS_fcntl, - IMFS_rmnod + memfile_rmnod }; diff --git a/c/src/libfs/src/imfs/imfs_rmnod.c b/c/src/libfs/src/imfs/imfs_rmnod.c deleted file mode 100644 index 3768b9543d..0000000000 --- a/c/src/libfs/src/imfs/imfs_rmnod.c +++ /dev/null @@ -1,98 +0,0 @@ -/* - * IMFS_rmnod - * - * This routine is available from the optable to remove a node - * from the IMFS file system. - * - * 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 "libio_.h" -#include "imfs.h" - - -int IMFS_rmnod( - rtems_filesystem_location_info_t *pathloc /* IN */ -) -{ - IMFS_jnode_t *the_jnode; - - the_jnode = (IMFS_jnode_t *) 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 ) ) - set_errno_and_return_minus_one( ENOTEMPTY ); - - /* - * You cannot remove the file system root node. - */ - - if ( pathloc->mt_entry->mt_fs_root.node_access == pathloc->node_access ) - set_errno_and_return_minus_one( EBUSY ); - - /* - * You cannot remove a mountpoint. - */ - - if ( the_jnode->info.directory.mt_fs != NULL ) - set_errno_and_return_minus_one( EBUSY ); - } - - /* - * Take the node out of the parent's chain that contains this node - */ - - if ( the_jnode->Parent != NULL ) { - Chain_Extract( (Chain_Node *) the_jnode ); - the_jnode->Parent = NULL; - } - - /* - * Decrement the link counter and see if we can free the space. - */ - - the_jnode->st_nlink--; - IMFS_update_ctime( the_jnode ); - - /* - * The file cannot be open and the link must be less than 1 to free. - */ - - 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/libfs/src/imfs/imfs_unlink.c b/c/src/libfs/src/imfs/imfs_unlink.c index 4e0ca26b2a..e138064e61 100644 --- a/c/src/libfs/src/imfs/imfs_unlink.c +++ b/c/src/libfs/src/imfs/imfs_unlink.c @@ -55,13 +55,13 @@ int IMFS_unlink( node->info.hard_link.link_node->st_nlink --; IMFS_update_ctime( node->info.hard_link.link_node ); if ( node->info.hard_link.link_node->st_nlink < 1) { - result = IMFS_rmnod( &the_link ); + result = (*loc->handlers->rmnod)( &the_link ); if ( result != 0 ) return -1; } } - result = IMFS_rmnod( loc ); + result = (*loc->handlers->rmnod)( &the_link ); return result; } diff --git a/c/src/libfs/src/imfs/memfile.c b/c/src/libfs/src/imfs/memfile.c index 3468490c90..0a3b30d38f 100644 --- a/c/src/libfs/src/imfs/memfile.c +++ b/c/src/libfs/src/imfs/memfile.c @@ -29,26 +29,6 @@ #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 */ @@ -1056,3 +1036,62 @@ fflush(stdout); memfile_blocks_allocated--; } + +/* + * memfile_rmnod + * + * This routine is available from the optable to remove a node + * from the IMFS file system. + */ + +int memfile_rmnod( + rtems_filesystem_location_info_t *pathloc /* IN */ +) +{ + IMFS_jnode_t *the_jnode; + + the_jnode = (IMFS_jnode_t *) pathloc->node_access; + + /* + * Take the node out of the parent's chain that contains this node + */ + + if ( the_jnode->Parent != NULL ) { + Chain_Extract( (Chain_Node *) the_jnode ); + the_jnode->Parent = NULL; + } + + /* + * Decrement the link counter and see if we can free the space. + */ + + the_jnode->st_nlink--; + IMFS_update_ctime( the_jnode ); + + /* + * The file cannot be open and the link must be less than 1 to free. + */ + + 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. + */ + + IMFS_memfile_remove( the_jnode ); + + free( the_jnode ); + } + + return 0; + +} + + diff --git a/c/src/libfs/src/imfs/miniimfs_init.c b/c/src/libfs/src/imfs/miniimfs_init.c index 983cde9439..865822fbfc 100644 --- a/c/src/libfs/src/imfs/miniimfs_init.c +++ b/c/src/libfs/src/imfs/miniimfs_init.c @@ -37,7 +37,6 @@ rtems_filesystem_operations_table miniIMFS_ops = { 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, */ diff --git a/cpukit/libfs/src/imfs/deviceio.c b/cpukit/libfs/src/imfs/deviceio.c index f954decf6e..70b9706ada 100644 --- a/cpukit/libfs/src/imfs/deviceio.c +++ b/cpukit/libfs/src/imfs/deviceio.c @@ -17,6 +17,7 @@ #include #include +#include "libio_.h" #include "imfs.h" @@ -213,3 +214,58 @@ int device_lseek( * * This IMFS_stat() is used. */ + +/* + * device_rmnod + */ + +int device_rmnod( + rtems_filesystem_location_info_t *pathloc /* IN */ +) +{ + IMFS_jnode_t *the_jnode; + + the_jnode = (IMFS_jnode_t *) pathloc->node_access; + + /* + * Take the node out of the parent's chain that contains this node + */ + + if ( the_jnode->Parent != NULL ) { + Chain_Extract( (Chain_Node *) the_jnode ); + the_jnode->Parent = NULL; + } + + /* + * Decrement the link counter and see if we can free the space. + */ + + the_jnode->st_nlink--; + IMFS_update_ctime( the_jnode ); + + /* + * The file cannot be open and the link must be less than 1 to free. + */ + + 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. + */ + + free( the_jnode ); + } + + return 0; + +} + + + diff --git a/cpukit/libfs/src/imfs/imfs.h b/cpukit/libfs/src/imfs/imfs.h index d1be06bbf4..a88672c4b8 100644 --- a/cpukit/libfs/src/imfs/imfs.h +++ b/cpukit/libfs/src/imfs/imfs.h @@ -308,10 +308,6 @@ int IMFS_freenodinfo( rtems_filesystem_location_info_t *pathloc /* IN */ ); -int IMFS_rmnod( - rtems_filesystem_location_info_t *pathloc /* IN */ -); - int IMFS_mknod( const char *path, /* IN */ mode_t mode, /* IN */ @@ -353,92 +349,123 @@ int memfile_ftruncate( rtems_libio_t *iop, /* IN */ off_t length /* IN */ ); + int imfs_dir_open( rtems_libio_t *iop, /* IN */ const char *pathname, /* IN */ unsigned32 flag, /* IN */ unsigned32 mode /* IN */ ); + int imfs_dir_close( rtems_libio_t *iop /* IN */ ); + int imfs_dir_read( rtems_libio_t *iop, /* IN */ void *buffer, /* IN */ unsigned32 count /* IN */ ); + int imfs_dir_lseek( rtems_libio_t *iop, /* IN */ off_t offset, /* IN */ int whence /* IN */ ); + int imfs_dir_fstat( rtems_filesystem_location_info_t *loc, /* IN */ struct stat *buf /* OUT */ ); + +int imfs_dir_rmnod( + rtems_filesystem_location_info_t *pathloc /* IN */ +); + int memfile_open( rtems_libio_t *iop, /* IN */ const char *pathname, /* IN */ unsigned32 flag, /* IN */ unsigned32 mode /* IN */ ); + int memfile_close( rtems_libio_t *iop /* IN */ ); + int memfile_read( rtems_libio_t *iop, /* IN */ void *buffer, /* IN */ unsigned32 count /* IN */ ); + int memfile_write( rtems_libio_t *iop, /* IN */ const void *buffer, /* IN */ unsigned32 count /* IN */ ); + int memfile_ioctl( rtems_libio_t *iop, /* IN */ unsigned32 command, /* IN */ void *buffer /* IN */ ); + int memfile_lseek( rtems_libio_t *iop, /* IN */ off_t offset, /* IN */ int whence /* IN */ ); + +int memfile_rmnod( + rtems_filesystem_location_info_t *pathloc /* IN */ +); + int device_open( rtems_libio_t *iop, /* IN */ const char *pathname, /* IN */ unsigned32 flag, /* IN */ unsigned32 mode /* IN */ ); + int device_close( rtems_libio_t *iop /* IN */ ); + int device_read( rtems_libio_t *iop, /* IN */ void *buffer, /* IN */ unsigned32 count /* IN */ ); + int device_write( rtems_libio_t *iop, /* IN */ const void *buffer, /* IN */ unsigned32 count /* IN */ ); + int device_ioctl( rtems_libio_t *iop, /* IN */ unsigned32 command, /* IN */ void *buffer /* IN */ ); + int device_lseek( rtems_libio_t *iop, /* IN */ off_t offset, /* IN */ int whence /* IN */ ); + +int device_rmnod( + rtems_filesystem_location_info_t *pathloc /* IN */ +); + int IMFS_utime( rtems_filesystem_location_info_t *pathloc, /* IN */ time_t actime, /* IN */ time_t modtime /* IN */ ); + int IMFS_fchmod( rtems_filesystem_location_info_t *loc, mode_t mode diff --git a/cpukit/libfs/src/imfs/imfs_directory.c b/cpukit/libfs/src/imfs/imfs_directory.c index fbf4ba53a3..89672ec9ae 100644 --- a/cpukit/libfs/src/imfs/imfs_directory.c +++ b/cpukit/libfs/src/imfs/imfs_directory.c @@ -269,4 +269,80 @@ int imfs_dir_fstat( return 0; } +/* + * IMFS_dir_rmnod + * + * This routine is available from the optable to remove a node + * from the IMFS file system. + */ + +int imfs_dir_rmnod( + rtems_filesystem_location_info_t *pathloc /* IN */ +) +{ + IMFS_jnode_t *the_jnode; + + the_jnode = (IMFS_jnode_t *) pathloc->node_access; + + /* + * You cannot remove a node that still has children + */ + + if ( ! Chain_Is_empty( &the_jnode->info.directory.Entries ) ) + set_errno_and_return_minus_one( ENOTEMPTY ); + + /* + * You cannot remove the file system root node. + */ + + if ( pathloc->mt_entry->mt_fs_root.node_access == pathloc->node_access ) + set_errno_and_return_minus_one( EBUSY ); + + /* + * You cannot remove a mountpoint. + */ + + if ( the_jnode->info.directory.mt_fs != NULL ) + set_errno_and_return_minus_one( EBUSY ); + + /* + * Take the node out of the parent's chain that contains this node + */ + + if ( the_jnode->Parent != NULL ) { + Chain_Extract( (Chain_Node *) the_jnode ); + the_jnode->Parent = NULL; + } + + /* + * Decrement the link counter and see if we can free the space. + */ + + the_jnode->st_nlink--; + IMFS_update_ctime( the_jnode ); + + /* + * The file cannot be open and the link must be less than 1 to free. + */ + + 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. + */ + + free( the_jnode ); + } + + return 0; + +} + diff --git a/cpukit/libfs/src/imfs/imfs_handlers_device.c b/cpukit/libfs/src/imfs/imfs_handlers_device.c index b6b9c808a0..24b7ffa5bb 100644 --- a/cpukit/libfs/src/imfs/imfs_handlers_device.c +++ b/cpukit/libfs/src/imfs/imfs_handlers_device.c @@ -34,5 +34,5 @@ rtems_filesystem_file_handlers_r IMFS_device_handlers = { NULL, /* fsync */ NULL, /* fdatasync */ NULL, /* fcntl */ - IMFS_rmnod + device_rmnod }; diff --git a/cpukit/libfs/src/imfs/imfs_handlers_directory.c b/cpukit/libfs/src/imfs/imfs_handlers_directory.c index 364f3cdf26..0ee06d8ebf 100644 --- a/cpukit/libfs/src/imfs/imfs_handlers_directory.c +++ b/cpukit/libfs/src/imfs/imfs_handlers_directory.c @@ -34,7 +34,7 @@ rtems_filesystem_file_handlers_r IMFS_directory_handlers = { NULL, /* fsync */ IMFS_fdatasync, IMFS_fcntl, - IMFS_rmnod + imfs_dir_rmnod }; diff --git a/cpukit/libfs/src/imfs/imfs_handlers_memfile.c b/cpukit/libfs/src/imfs/imfs_handlers_memfile.c index f622c99558..20ef3c57b3 100644 --- a/cpukit/libfs/src/imfs/imfs_handlers_memfile.c +++ b/cpukit/libfs/src/imfs/imfs_handlers_memfile.c @@ -34,5 +34,5 @@ rtems_filesystem_file_handlers_r IMFS_memfile_handlers = { NULL, /* fsync */ IMFS_fdatasync, IMFS_fcntl, - IMFS_rmnod + memfile_rmnod }; diff --git a/cpukit/libfs/src/imfs/imfs_rmnod.c b/cpukit/libfs/src/imfs/imfs_rmnod.c deleted file mode 100644 index 3768b9543d..0000000000 --- a/cpukit/libfs/src/imfs/imfs_rmnod.c +++ /dev/null @@ -1,98 +0,0 @@ -/* - * IMFS_rmnod - * - * This routine is available from the optable to remove a node - * from the IMFS file system. - * - * 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 "libio_.h" -#include "imfs.h" - - -int IMFS_rmnod( - rtems_filesystem_location_info_t *pathloc /* IN */ -) -{ - IMFS_jnode_t *the_jnode; - - the_jnode = (IMFS_jnode_t *) 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 ) ) - set_errno_and_return_minus_one( ENOTEMPTY ); - - /* - * You cannot remove the file system root node. - */ - - if ( pathloc->mt_entry->mt_fs_root.node_access == pathloc->node_access ) - set_errno_and_return_minus_one( EBUSY ); - - /* - * You cannot remove a mountpoint. - */ - - if ( the_jnode->info.directory.mt_fs != NULL ) - set_errno_and_return_minus_one( EBUSY ); - } - - /* - * Take the node out of the parent's chain that contains this node - */ - - if ( the_jnode->Parent != NULL ) { - Chain_Extract( (Chain_Node *) the_jnode ); - the_jnode->Parent = NULL; - } - - /* - * Decrement the link counter and see if we can free the space. - */ - - the_jnode->st_nlink--; - IMFS_update_ctime( the_jnode ); - - /* - * The file cannot be open and the link must be less than 1 to free. - */ - - 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/cpukit/libfs/src/imfs/imfs_unlink.c b/cpukit/libfs/src/imfs/imfs_unlink.c index 4e0ca26b2a..e138064e61 100644 --- a/cpukit/libfs/src/imfs/imfs_unlink.c +++ b/cpukit/libfs/src/imfs/imfs_unlink.c @@ -55,13 +55,13 @@ int IMFS_unlink( node->info.hard_link.link_node->st_nlink --; IMFS_update_ctime( node->info.hard_link.link_node ); if ( node->info.hard_link.link_node->st_nlink < 1) { - result = IMFS_rmnod( &the_link ); + result = (*loc->handlers->rmnod)( &the_link ); if ( result != 0 ) return -1; } } - result = IMFS_rmnod( loc ); + result = (*loc->handlers->rmnod)( &the_link ); return result; } diff --git a/cpukit/libfs/src/imfs/memfile.c b/cpukit/libfs/src/imfs/memfile.c index 3468490c90..0a3b30d38f 100644 --- a/cpukit/libfs/src/imfs/memfile.c +++ b/cpukit/libfs/src/imfs/memfile.c @@ -29,26 +29,6 @@ #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 */ @@ -1056,3 +1036,62 @@ fflush(stdout); memfile_blocks_allocated--; } + +/* + * memfile_rmnod + * + * This routine is available from the optable to remove a node + * from the IMFS file system. + */ + +int memfile_rmnod( + rtems_filesystem_location_info_t *pathloc /* IN */ +) +{ + IMFS_jnode_t *the_jnode; + + the_jnode = (IMFS_jnode_t *) pathloc->node_access; + + /* + * Take the node out of the parent's chain that contains this node + */ + + if ( the_jnode->Parent != NULL ) { + Chain_Extract( (Chain_Node *) the_jnode ); + the_jnode->Parent = NULL; + } + + /* + * Decrement the link counter and see if we can free the space. + */ + + the_jnode->st_nlink--; + IMFS_update_ctime( the_jnode ); + + /* + * The file cannot be open and the link must be less than 1 to free. + */ + + 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. + */ + + IMFS_memfile_remove( the_jnode ); + + free( the_jnode ); + } + + return 0; + +} + + diff --git a/cpukit/libfs/src/imfs/miniimfs_init.c b/cpukit/libfs/src/imfs/miniimfs_init.c index 983cde9439..865822fbfc 100644 --- a/cpukit/libfs/src/imfs/miniimfs_init.c +++ b/cpukit/libfs/src/imfs/miniimfs_init.c @@ -37,7 +37,6 @@ rtems_filesystem_operations_table miniIMFS_ops = { 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, */ -- cgit v1.2.3