Index: cpukit/ChangeLog
===================================================================
--- cpukit/ChangeLog	(revision 78f4d6d72ef51e9bdd33e2ed258fb6af5701153e)
+++ cpukit/ChangeLog	(revision 5b5772ae313eb2dd8d211749bc2eb3fea63758f8)
@@ -1,2 +1,13 @@
+2010-06-08	Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+	* 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().
+
 2010-06-08	Sebastian Huber <sebastian.huber@embedded-brains.de>
 
Index: cpukit/libfs/src/imfs/deviceio.c
===================================================================
--- cpukit/libfs/src/imfs/deviceio.c	(revision 78f4d6d72ef51e9bdd33e2ed258fb6af5701153e)
+++ cpukit/libfs/src/imfs/deviceio.c	(revision 5b5772ae313eb2dd8d211749bc2eb3fea63758f8)
@@ -82,4 +82,6 @@
     (void *) &args
   );
+
+  IMFS_check_node_remove( the_jnode );
 
   return rtems_deviceio_errno( status );
Index: cpukit/libfs/src/imfs/imfs.h
===================================================================
--- cpukit/libfs/src/imfs/imfs.h	(revision 78f4d6d72ef51e9bdd33e2ed258fb6af5701153e)
+++ cpukit/libfs/src/imfs/imfs.h	(revision 5b5772ae313eb2dd8d211749bc2eb3fea63758f8)
@@ -471,9 +471,4 @@
 );
 
-extern int memfile_rmnod(
-  rtems_filesystem_location_info_t  *parent_pathloc, /* IN */
-  rtems_filesystem_location_info_t  *pathloc         /* IN */
-);
-
 extern int device_open(
   rtems_libio_t *iop,            /* IN  */
@@ -555,4 +550,12 @@
 );
 
+extern void IMFS_create_orphan(
+  IMFS_jnode_t *jnode
+);
+
+extern void IMFS_check_node_remove(
+  IMFS_jnode_t *jnode
+);
+
 extern int IMFS_rmnod(
   rtems_filesystem_location_info_t  *parent_pathloc, /* IN */
Index: cpukit/libfs/src/imfs/imfs_directory.c
===================================================================
--- cpukit/libfs/src/imfs/imfs_directory.c	(revision 78f4d6d72ef51e9bdd33e2ed258fb6af5701153e)
+++ cpukit/libfs/src/imfs/imfs_directory.c	(revision 5b5772ae313eb2dd8d211749bc2eb3fea63758f8)
@@ -312,41 +312,7 @@
      rtems_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 ) {
-    rtems_chain_extract( (rtems_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 );
-  }
+  IMFS_create_orphan( the_jnode );
+  IMFS_check_node_remove( the_jnode );
 
   return 0;
-
-}
+}
Index: cpukit/libfs/src/imfs/imfs_fifo.c
===================================================================
--- cpukit/libfs/src/imfs/imfs_fifo.c	(revision 78f4d6d72ef51e9bdd33e2ed258fb6af5701153e)
+++ cpukit/libfs/src/imfs/imfs_fifo.c	(revision 5b5772ae313eb2dd8d211749bc2eb3fea63758f8)
@@ -54,9 +54,7 @@
   int err = pipe_release(&JNODE2PIPE(jnode), iop);
 
-  if (! err) {
+  if (err == 0) {
     iop->flags &= ~LIBIO_FLAGS_OPEN;
-    /* Free jnode if file is already unlinked and no one opens it */
-    if (! rtems_libio_is_file_open(jnode) && jnode->st_nlink < 1)
-      free(jnode);
+    IMFS_check_node_remove(jnode);
   }
 
Index: cpukit/libfs/src/imfs/imfs_handlers_memfile.c
===================================================================
--- cpukit/libfs/src/imfs/imfs_handlers_memfile.c	(revision 78f4d6d72ef51e9bdd33e2ed258fb6af5701153e)
+++ cpukit/libfs/src/imfs/imfs_handlers_memfile.c	(revision 5b5772ae313eb2dd8d211749bc2eb3fea63758f8)
@@ -38,4 +38,4 @@
   IMFS_fdatasync,
   IMFS_fcntl,
-  memfile_rmnod
+  IMFS_rmnod
 };
Index: cpukit/libfs/src/imfs/imfs_rmnod.c
===================================================================
--- cpukit/libfs/src/imfs/imfs_rmnod.c	(revision 78f4d6d72ef51e9bdd33e2ed258fb6af5701153e)
+++ cpukit/libfs/src/imfs/imfs_rmnod.c	(revision 5b5772ae313eb2dd8d211749bc2eb3fea63758f8)
@@ -27,4 +27,37 @@
 #include "imfs.h"
 
+void IMFS_create_orphan( IMFS_jnode_t *jnode )
+{
+  if ( jnode->Parent != NULL ) {
+    rtems_chain_extract( &jnode->Node );
+    jnode->Parent = NULL;
+  }
+
+  --jnode->st_nlink;
+
+  IMFS_update_ctime( jnode );
+}
+
+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;
+
+    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 );
+  }
+}
+
 /*
  *  IMFS_rmnod
@@ -36,49 +69,9 @@
 )
 {
-  IMFS_jnode_t *the_jnode;
+  IMFS_jnode_t *jnode = (IMFS_jnode_t *) pathloc->node_access;
 
-  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;
-  }
-
-  /*
-   * 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 rtems_filesystem_current 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_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;
-
 }
Index: cpukit/libfs/src/imfs/memfile.c
===================================================================
--- cpukit/libfs/src/imfs/memfile.c	(revision 78f4d6d72ef51e9bdd33e2ed258fb6af5701153e)
+++ cpukit/libfs/src/imfs/memfile.c	(revision 5b5772ae313eb2dd8d211749bc2eb3fea63758f8)
@@ -73,6 +73,4 @@
    unsigned int           length
 );
-
-int  memfile_check_rmnod( IMFS_jnode_t *the_jnode );
 
 void *memfile_alloc_block(void);
@@ -142,5 +140,6 @@
     iop->offset = the_jnode->info.file.size;
 
-  memfile_check_rmnod( the_jnode );
+  IMFS_check_node_remove( the_jnode );
+
   return 0;
 }
@@ -1098,66 +1097,2 @@
   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  *parent_pathloc,  /* IN */
-  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 ) {
-    rtems_chain_extract( (rtems_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 );
-
-  return memfile_check_rmnod( the_jnode );
-}
-
-
-int  memfile_check_rmnod( IMFS_jnode_t *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 == the_jnode )
-       rtems_filesystem_current.node_access = NULL;
-
-    /*
-     * Free memory associated with a memory file.
-     */
-    if (the_jnode->type != IMFS_LINEAR_FILE)
-      IMFS_memfile_remove( the_jnode );
-
-    free( the_jnode );
-  }
-
-  return 0;
-}
