From 2e0ce55bf04861e9f80bf51621286b9a1a2c5af1 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Tue, 21 Feb 2012 17:24:10 +0100 Subject: IMFS: Use unprotected chain operations Directory entry add or removal operations are protected by the file system instance lock. There is no need for protected chain operations. --- cpukit/libfs/src/imfs/imfs.h | 15 +++++++++++++++ cpukit/libfs/src/imfs/imfs_creat.c | 17 ++++++++++------- cpukit/libfs/src/imfs/imfs_rename.c | 10 ++-------- cpukit/libfs/src/imfs/imfs_rmnod.c | 3 +-- 4 files changed, 28 insertions(+), 17 deletions(-) (limited to 'cpukit') diff --git a/cpukit/libfs/src/imfs/imfs.h b/cpukit/libfs/src/imfs/imfs.h index 8d68c07590..c2d95f0f8e 100644 --- a/cpukit/libfs/src/imfs/imfs.h +++ b/cpukit/libfs/src/imfs/imfs.h @@ -489,6 +489,21 @@ extern int IMFS_rmnod( const rtems_filesystem_location_info_t *loc ); +static inline void IMFS_add_to_directory( + IMFS_jnode_t *dir, + IMFS_jnode_t *node +) +{ + node->Parent = dir; + rtems_chain_append_unprotected( &dir->info.directory.Entries, &node->Node ); +} + +static inline void IMFS_remove_from_directory( IMFS_jnode_t *node ) +{ + node->Parent = NULL; + rtems_chain_extract_unprotected( &node->Node ); +} + /* * Turn on IMFS assertions when RTEMS_DEBUG is defined. */ diff --git a/cpukit/libfs/src/imfs/imfs_creat.c b/cpukit/libfs/src/imfs/imfs_creat.c index 4c030a210f..caf82be250 100644 --- a/cpukit/libfs/src/imfs/imfs_creat.c +++ b/cpukit/libfs/src/imfs/imfs_creat.c @@ -22,6 +22,11 @@ #include #include +static void IMFS_initialize_directory( IMFS_jnode_t *dir ) +{ + rtems_chain_initialize_empty( &dir->info.directory.Entries ); +} + /* * Create an IMFS filesystem node of an arbitrary type that is NOT * the root directory node. @@ -39,8 +44,6 @@ IMFS_jnode_t *IMFS_create_node( IMFS_jnode_t *parent; IMFS_fs_info_t *fs_info; - IMFS_assert( parent_loc != NULL ); - parent = parent_loc->node_access; fs_info = parent_loc->mt_entry->fs_info; @@ -55,7 +58,7 @@ IMFS_jnode_t *IMFS_create_node( * Set the type specific information */ if ( type == IMFS_DIRECTORY ) { - rtems_chain_initialize_empty(&node->info.directory.Entries); + IMFS_initialize_directory( node ); } else if ( type == IMFS_HARD_LINK ) { node->info.hard_link.link_node = info->hard_link.link_node; } else if ( type == IMFS_SYM_LINK ) { @@ -80,10 +83,10 @@ IMFS_jnode_t *IMFS_create_node( /* * This node MUST have a parent, so put it in that directory list. */ - node->Parent = parent; - node->st_ino = ++fs_info->ino_count; + IMFS_assert( parent != NULL ); + IMFS_add_to_directory( parent, node ); - rtems_chain_append( &parent->info.directory.Entries, &node->Node ); + node->st_ino = ++fs_info->ino_count; return node; } @@ -165,7 +168,7 @@ IMFS_jnode_t *IMFS_create_root_node(void) * * NOTE: Root node is always a directory. */ - rtems_chain_initialize_empty(&node->info.directory.Entries); + IMFS_initialize_directory( node ); return node; } diff --git a/cpukit/libfs/src/imfs/imfs_rename.c b/cpukit/libfs/src/imfs/imfs_rename.c index 855d026c36..57d1957be7 100644 --- a/cpukit/libfs/src/imfs/imfs_rename.c +++ b/cpukit/libfs/src/imfs/imfs_rename.c @@ -42,14 +42,8 @@ int IMFS_rename( memcpy( node->name, name, namelen ); node->name [namelen] = '\0'; - rtems_chain_extract( &node->Node ); - - node->Parent = new_parent; - rtems_chain_append( - &new_parent->info.directory.Entries, - &node->Node - ); - + IMFS_remove_from_directory( node ); + IMFS_add_to_directory( new_parent, node ); IMFS_update_ctime( node ); } else { errno = ENAMETOOLONG; diff --git a/cpukit/libfs/src/imfs/imfs_rmnod.c b/cpukit/libfs/src/imfs/imfs_rmnod.c index c50041942f..ae4d8fb92b 100644 --- a/cpukit/libfs/src/imfs/imfs_rmnod.c +++ b/cpukit/libfs/src/imfs/imfs_rmnod.c @@ -28,8 +28,7 @@ void IMFS_create_orphan( IMFS_jnode_t *jnode ) { if ( jnode->Parent != NULL ) { - rtems_chain_extract( &jnode->Node ); - jnode->Parent = NULL; + IMFS_remove_from_directory( jnode ); } --jnode->st_nlink; -- cgit v1.2.3