Filesystem: Reject removal of root nodes

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.
This commit is contained in:
Sebastian Huber
2012-10-07 17:03:20 +02:00
parent 9b83a66546
commit c17d0b315b
10 changed files with 23 additions and 34 deletions
+6 -1
View File
@@ -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;
+8 -2
View File
@@ -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 );
-8
View File
@@ -50,14 +50,6 @@ msdos_rmnod(const rtems_filesystem_location_info_t *parent_pathloc,
rtems_set_errno_and_return_minus_one(EBUSY);
}
/*
* 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.
+2 -4
View File
@@ -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 );
@@ -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;
}
+2 -3
View File
@@ -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;
}
+1 -2
View File
@@ -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;
+1 -4
View File
@@ -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;
-3
View File
@@ -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 -4
View File
@@ -233,10 +233,7 @@ static IMFS_jnode_t *node_initialize(
return node;
}
static IMFS_jnode_t *node_remove(
IMFS_jnode_t *node,
const IMFS_jnode_t *root_node
)
static IMFS_jnode_t *node_remove(IMFS_jnode_t *node)
{
test_state *state = IMFS_generic_get_context_by_node(node);