[PATCH] Filesystem: Reject removal of root nodes

Sebastian Huber sebastian.huber at embedded-brains.de
Tue Oct 2 13:44:59 UTC 2012


Reject the removal of file system instance root nodes in rmdir() and
unlink() and return the EBUSY error status.  File system instances can
be removed with unmount().  Remove root node special cases in IMFS,
DOSFS, and RFS.
---
 cpukit/libcsupport/src/rmdir.c                  |    7 ++++++-
 cpukit/libcsupport/src/unlink.c                 |   10 ++++++++--
 cpukit/libfs/src/dosfs/msdos_rmnod.c            |    8 --------
 cpukit/libfs/src/imfs/imfs.h                    |    6 ++----
 cpukit/libfs/src/imfs/imfs_handlers_directory.c |    5 ++---
 cpukit/libfs/src/imfs/imfs_handlers_link.c      |    5 ++---
 cpukit/libfs/src/imfs/imfs_initsupp.c           |    3 +--
 cpukit/libfs/src/imfs/imfs_rmnod.c              |    5 +----
 cpukit/libfs/src/rfs/rtems-rfs-rtems.c          |    3 ---
 9 files changed, 22 insertions(+), 30 deletions(-)

diff --git a/cpukit/libcsupport/src/rmdir.c b/cpukit/libcsupport/src/rmdir.c
index 4e7baf5..f2bc16e 100644
--- a/cpukit/libcsupport/src/rmdir.c
+++ b/cpukit/libcsupport/src/rmdir.c
@@ -38,7 +38,12 @@ int rmdir( const char *path )
   rtems_filesystem_node_types_t type = (*ops->node_type_h)( currentloc );
 
   if ( type == RTEMS_FILESYSTEM_DIRECTORY ) {
-    rv = (*ops->rmnod_h)( &parentloc, currentloc );
+    if ( !rtems_filesystem_location_is_root( currentloc ) ) {
+      rv = (*ops->rmnod_h)( &parentloc, currentloc );
+    } else {
+      rtems_filesystem_eval_path_error( &ctx, EBUSY );
+      rv = -1;
+    }
   } else {
     rtems_filesystem_eval_path_error( &ctx, ENOTDIR );
     rv = -1;
diff --git a/cpukit/libcsupport/src/unlink.c b/cpukit/libcsupport/src/unlink.c
index 9817ad9..2a3b1c7 100644
--- a/cpukit/libcsupport/src/unlink.c
+++ b/cpukit/libcsupport/src/unlink.c
@@ -34,9 +34,15 @@ int unlink( const char *path )
       &parentloc,
       parent_eval_flags
     );
-  const rtems_filesystem_operations_table *ops = currentloc->mt_entry->ops;
 
-  rv = (*ops->rmnod_h)( &parentloc, currentloc );
+  if ( !rtems_filesystem_location_is_root( currentloc ) ) {
+    const rtems_filesystem_operations_table *ops = currentloc->mt_entry->ops;
+
+    rv = (*ops->rmnod_h)( &parentloc, currentloc );
+  } else {
+    rtems_filesystem_eval_path_error( &ctx, EBUSY );
+    rv = -1;
+  }
 
   rtems_filesystem_eval_path_cleanup_with_parent( &ctx, &parentloc );
 
diff --git a/cpukit/libfs/src/dosfs/msdos_rmnod.c b/cpukit/libfs/src/dosfs/msdos_rmnod.c
index db08352..099b928 100644
--- a/cpukit/libfs/src/dosfs/msdos_rmnod.c
+++ b/cpukit/libfs/src/dosfs/msdos_rmnod.c
@@ -51,14 +51,6 @@ msdos_rmnod(const rtems_filesystem_location_info_t *parent_pathloc,
         }
 
         /*
-         * You cannot remove the file system root node.
-         */
-        if (rtems_filesystem_location_is_root(pathloc))
-        {
-            rtems_set_errno_and_return_minus_one(EBUSY);
-        }
-
-        /*
          * You cannot remove a mountpoint.
          * not used - mount() not implemenetd yet.
          */
diff --git a/cpukit/libfs/src/imfs/imfs.h b/cpukit/libfs/src/imfs/imfs.h
index 7c0cbe5..aed0077 100644
--- a/cpukit/libfs/src/imfs/imfs.h
+++ b/cpukit/libfs/src/imfs/imfs.h
@@ -169,13 +169,11 @@ IMFS_jnode_t *IMFS_node_initialize_generic(
 );
 
 typedef IMFS_jnode_t *(*IMFS_node_control_remove)(
-  IMFS_jnode_t *node,
-  const IMFS_jnode_t *root_node
+  IMFS_jnode_t *node
 );
 
 IMFS_jnode_t *IMFS_node_remove_default(
-  IMFS_jnode_t *node,
-  const IMFS_jnode_t *root_node
+  IMFS_jnode_t *node
 );
 
 typedef IMFS_jnode_t *(*IMFS_node_control_destroy)( IMFS_jnode_t *node );
diff --git a/cpukit/libfs/src/imfs/imfs_handlers_directory.c b/cpukit/libfs/src/imfs/imfs_handlers_directory.c
index 0663e7a..9dcdcf2 100644
--- a/cpukit/libfs/src/imfs/imfs_handlers_directory.c
+++ b/cpukit/libfs/src/imfs/imfs_handlers_directory.c
@@ -74,14 +74,13 @@ static bool IMFS_is_mount_point( const IMFS_jnode_t *node )
 }
 
 static IMFS_jnode_t *IMFS_node_remove_directory(
-  IMFS_jnode_t *node,
-  const IMFS_jnode_t *root_node
+  IMFS_jnode_t *node
 )
 {
   if ( !rtems_chain_is_empty( &node->info.directory.Entries ) ) {
     errno = ENOTEMPTY;
     node = NULL;
-  } else if ( node == root_node || IMFS_is_mount_point( node ) ) {
+  } else if ( IMFS_is_mount_point( node ) ) {
     errno = EBUSY;
     node = NULL;
   }
diff --git a/cpukit/libfs/src/imfs/imfs_handlers_link.c b/cpukit/libfs/src/imfs/imfs_handlers_link.c
index baf5831..2c4ad3f 100644
--- a/cpukit/libfs/src/imfs/imfs_handlers_link.c
+++ b/cpukit/libfs/src/imfs/imfs_handlers_link.c
@@ -64,14 +64,13 @@ static IMFS_jnode_t *IMFS_node_initialize_hard_link(
 }
 
 static IMFS_jnode_t *IMFS_node_remove_hard_link(
-  IMFS_jnode_t *node,
-  const IMFS_jnode_t *root_node
+  IMFS_jnode_t *node
 )
 {
   IMFS_jnode_t *target = node->info.hard_link.link_node;
 
   if ( target->st_nlink == 1) {
-    target = (*target->control->node_remove)( target, root_node );
+    target = (*target->control->node_remove)( target );
     if ( target == NULL ) {
       node = NULL;
     }
diff --git a/cpukit/libfs/src/imfs/imfs_initsupp.c b/cpukit/libfs/src/imfs/imfs_initsupp.c
index 26152d8..3bb8a97 100644
--- a/cpukit/libfs/src/imfs/imfs_initsupp.c
+++ b/cpukit/libfs/src/imfs/imfs_initsupp.c
@@ -141,8 +141,7 @@ IMFS_jnode_t *IMFS_node_initialize_default(
 }
 
 IMFS_jnode_t *IMFS_node_remove_default(
-  IMFS_jnode_t *node,
-  const IMFS_jnode_t *root_node
+  IMFS_jnode_t *node
 )
 {
   return node;
diff --git a/cpukit/libfs/src/imfs/imfs_rmnod.c b/cpukit/libfs/src/imfs/imfs_rmnod.c
index a0fa1d6..90e61d9 100644
--- a/cpukit/libfs/src/imfs/imfs_rmnod.c
+++ b/cpukit/libfs/src/imfs/imfs_rmnod.c
@@ -29,10 +29,7 @@ int IMFS_rmnod(
   int rv = 0;
   IMFS_jnode_t *node = loc->node_access;
 
-  node = (*node->control->node_remove)(
-    node,
-    loc->mt_entry->mt_fs_root->location.node_access
-  );
+  node = (*node->control->node_remove)( node );
   if ( node != NULL ) {
     --node->reference_count;
     --node->st_nlink;
diff --git a/cpukit/libfs/src/rfs/rtems-rfs-rtems.c b/cpukit/libfs/src/rfs/rtems-rfs-rtems.c
index ba6c905..6ff9793 100644
--- a/cpukit/libfs/src/rfs/rtems-rfs-rtems.c
+++ b/cpukit/libfs/src/rfs/rtems-rfs-rtems.c
@@ -678,9 +678,6 @@ rtems_rfs_rtems_rmnod (const rtems_filesystem_location_info_t* parent_pathloc,
     printf ("rtems-rfs: rmnod: parent:%" PRId32 " doff:%" PRIu32 ", ino:%" PRId32 "\n",
             parent, doff, ino);
 
-  if (ino == RTEMS_RFS_ROOT_INO)
-    return rtems_rfs_rtems_error ("rmnod: root inode", EBUSY);
-
   rc = rtems_rfs_unlink (fs, parent, ino, doff, rtems_rfs_unlink_dir_if_empty);
   if (rc)
   {
-- 
1.7.7




More information about the devel mailing list