From 5b5772ae313eb2dd8d211749bc2eb3fea63758f8 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Tue, 8 Jun 2010 08:50:57 +0000 Subject: 2010-06-08 Sebastian Huber * libfs/src/imfs/imfs.h, libfs/src/imfs/imfs_rmnod.c: Added and use IMFS_create_orphan() and IMFS_check_node_remove(). * libfs/src/imfs/deviceio.c, libfs/src/imfs/imfs_directory.c, libfs/src/imfs/imfs_fifo.c: Use IMFS_create_orphan() and IMFS_check_node_remove(). * libfs/src/imfs/imfs_handlers_memfile.c, libfs/src/imfs/memfile.c: Use IMFS_rmnod() and IMFS_check_node_remove() instead of memfile_rmnod() and memfile_check_rmnod(). --- cpukit/libfs/src/imfs/imfs_rmnod.c | 79 +++++++++++++++++--------------------- 1 file changed, 36 insertions(+), 43 deletions(-) (limited to 'cpukit/libfs/src/imfs/imfs_rmnod.c') diff --git a/cpukit/libfs/src/imfs/imfs_rmnod.c b/cpukit/libfs/src/imfs/imfs_rmnod.c index ed6001a691..25c7cde084 100644 --- a/cpukit/libfs/src/imfs/imfs_rmnod.c +++ b/cpukit/libfs/src/imfs/imfs_rmnod.c @@ -26,59 +26,52 @@ #include "imfs.h" -/* - * IMFS_rmnod - */ - -int IMFS_rmnod( - rtems_filesystem_location_info_t *parent_pathloc, /* IN */ - rtems_filesystem_location_info_t *pathloc /* IN */ -) +void IMFS_create_orphan( IMFS_jnode_t *jnode ) { - 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 ) { - rtems_chain_extract( (rtems_chain_node *) the_jnode ); - the_jnode->Parent = NULL; + if ( jnode->Parent != NULL ) { + rtems_chain_extract( &jnode->Node ); + jnode->Parent = NULL; } - /* - * Decrement the link counter and see if we can free the space. - */ + --jnode->st_nlink; - the_jnode->st_nlink--; - IMFS_update_ctime( the_jnode ); + IMFS_update_ctime( jnode ); +} - /* - * The file cannot be open and the link must be less than 1 to free. - */ +void IMFS_check_node_remove( IMFS_jnode_t *jnode ) +{ + if ( !rtems_libio_is_file_open( jnode ) && jnode->st_nlink < 1 ) { + if ( rtems_filesystem_current.node_access == jnode ) + rtems_filesystem_current.node_access = NULL; - if ( !rtems_libio_is_file_open( the_jnode ) && (the_jnode->st_nlink < 1) ) { + switch ( jnode->type ) { + case IMFS_MEMORY_FILE: + IMFS_memfile_remove( jnode ); + break; + case IMFS_SYM_LINK: + free( jnode->info.sym_link.name ); + break; + default: + break; + } - /* - * Is rtems_filesystem_current this node? - */ + free( jnode ); + } +} - if ( rtems_filesystem_current.node_access == pathloc->node_access ) - rtems_filesystem_current.node_access = NULL; +/* + * IMFS_rmnod + */ - /* - * Free memory associated with a memory file. - */ +int IMFS_rmnod( + rtems_filesystem_location_info_t *parent_pathloc, /* IN */ + rtems_filesystem_location_info_t *pathloc /* IN */ +) +{ + IMFS_jnode_t *jnode = (IMFS_jnode_t *) pathloc->node_access; - if ( the_jnode->type == IMFS_SYM_LINK ) { - if ( the_jnode->info.sym_link.name ) - free( (void*) the_jnode->info.sym_link.name ); - } - free( the_jnode ); - } + IMFS_create_orphan( jnode ); + IMFS_check_node_remove( jnode ); return 0; - } -- cgit v1.2.3