summaryrefslogtreecommitdiffstats
path: root/cpukit/libfs/src/imfs/imfs_rmnod.c
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2012-02-23 17:57:27 +0100
committerSebastian Huber <sebastian.huber@embedded-brains.de>2012-03-13 12:24:15 +0100
commit1bdff036acddbbc63aa849741abba6581549f7b6 (patch)
tree8cc1f06ac93045d8a7c35da41fd926c2d9e840f1 /cpukit/libfs/src/imfs/imfs_rmnod.c
parentIMFS: Use unprotected chain operations (diff)
downloadrtems-1bdff036acddbbc63aa849741abba6581549f7b6.tar.bz2
IMFS: Reference counting for nodes
The introduction of reference counting of nodes avoids the removal of open nodes and potential usage of freed memory.
Diffstat (limited to 'cpukit/libfs/src/imfs/imfs_rmnod.c')
-rw-r--r--cpukit/libfs/src/imfs/imfs_rmnod.c40
1 files changed, 6 insertions, 34 deletions
diff --git a/cpukit/libfs/src/imfs/imfs_rmnod.c b/cpukit/libfs/src/imfs/imfs_rmnod.c
index ae4d8fb92b..748a6f7365 100644
--- a/cpukit/libfs/src/imfs/imfs_rmnod.c
+++ b/cpukit/libfs/src/imfs/imfs_rmnod.c
@@ -23,44 +23,13 @@
#include "imfs.h"
-#include <stdlib.h>
-
-void IMFS_create_orphan( IMFS_jnode_t *jnode )
-{
- if ( jnode->Parent != NULL ) {
- IMFS_remove_from_directory( jnode );
- }
-
- --jnode->st_nlink;
-
- IMFS_update_ctime( jnode );
-}
-
-void IMFS_check_node_remove( IMFS_jnode_t *jnode )
-{
- if ( 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;
- }
-
- free( jnode );
- }
-}
-
static int IMFS_rmnod_directory(
const rtems_filesystem_location_info_t *parentloc,
const rtems_filesystem_location_info_t *loc
)
{
- IMFS_jnode_t *node = loc->node_access;
int rv = 0;
+ IMFS_jnode_t *node = loc->node_access;
if ( !rtems_chain_is_empty( &node->info.directory.Entries ) ) {
errno = ENOTEMPTY;
@@ -120,8 +89,11 @@ int IMFS_rmnod(
}
if ( rv == 0 ) {
- IMFS_create_orphan( node );
- IMFS_check_node_remove( node );
+ --node->reference_count;
+ --node->st_nlink;
+ if ( node->Parent != NULL ) {
+ IMFS_remove_from_directory( node );
+ }
}
return rv;