[rtems commit] IMFS: New support functions

Joel Sherrill joel at rtems.org
Thu Mar 29 14:14:29 UTC 2012


Module:    rtems
Branch:    master
Commit:    cce5663a20bf6a5d6d03c22335713b866afff264
Changeset: http://git.rtems.org/rtems/commit/?id=cce5663a20bf6a5d6d03c22335713b866afff264

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Fri Feb 24 16:40:19 2012 +0100

IMFS: New support functions

Add and use IMFS_type() and IMFS_is_directory().

---

 cpukit/libfs/src/imfs/imfs.h           |   10 ++++++++++
 cpukit/libfs/src/imfs/imfs_debug.c     |    8 ++++----
 cpukit/libfs/src/imfs/imfs_eval.c      |   18 ++++++++++--------
 cpukit/libfs/src/imfs/imfs_fsunmount.c |    4 ++--
 cpukit/libfs/src/imfs/imfs_mount.c     |    2 +-
 cpukit/libfs/src/imfs/imfs_ntype.c     |    4 ++--
 cpukit/libfs/src/imfs/imfs_stat.c      |    6 +++---
 cpukit/libfs/src/imfs/imfs_unmount.c   |    2 +-
 cpukit/libfs/src/imfs/memfile.c        |   20 ++++++++++----------
 9 files changed, 43 insertions(+), 31 deletions(-)

diff --git a/cpukit/libfs/src/imfs/imfs.h b/cpukit/libfs/src/imfs/imfs.h
index 94988a0..7c926a8 100644
--- a/cpukit/libfs/src/imfs/imfs.h
+++ b/cpukit/libfs/src/imfs/imfs.h
@@ -499,6 +499,16 @@ static inline void IMFS_remove_from_directory( IMFS_jnode_t *node )
   rtems_chain_extract_unprotected( &node->Node );
 }
 
+static inline IMFS_jnode_types_t IMFS_type( const IMFS_jnode_t *node )
+{
+  return node->type;
+}
+
+static inline bool IMFS_is_directory( const IMFS_jnode_t *node )
+{
+  return node->type == IMFS_DIRECTORY;
+}
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/cpukit/libfs/src/imfs/imfs_debug.c b/cpukit/libfs/src/imfs/imfs_debug.c
index 0912372..8ae0bc6 100644
--- a/cpukit/libfs/src/imfs/imfs_debug.c
+++ b/cpukit/libfs/src/imfs/imfs_debug.c
@@ -33,7 +33,7 @@ static void IMFS_print_jnode(
   IMFS_assert( the_jnode );
 
   fprintf(stdout, "%s", the_jnode->name );
-  switch( the_jnode->type ) {
+  switch( IMFS_type( the_jnode ) ) {
     case IMFS_DIRECTORY:
       fprintf(stdout, "/" );
       break;
@@ -78,7 +78,7 @@ static void IMFS_print_jnode(
       return;
 
     default:
-      fprintf(stdout, " bad type %d\n", the_jnode->type );
+      fprintf(stdout, " bad type %d\n", IMFS_type( the_jnode ) );
       return;
   }
   puts("");
@@ -103,7 +103,7 @@ static void IMFS_dump_directory(
 
   IMFS_assert( the_directory );
   IMFS_assert( level >= 0 );
-  IMFS_assert( the_directory->type == IMFS_DIRECTORY );
+  IMFS_assert( IMFS_is_directory( the_directory ) );
 
   the_chain = &the_directory->info.directory.Entries;
 
@@ -116,7 +116,7 @@ static void IMFS_dump_directory(
     for ( i=0 ; i<=level ; i++ )
       fprintf(stdout, "...." );
     IMFS_print_jnode( the_jnode );
-    if ( the_jnode->type == IMFS_DIRECTORY )
+    if ( IMFS_is_directory( the_jnode ) )
       IMFS_dump_directory( the_jnode, level + 1 );
   }
 }
diff --git a/cpukit/libfs/src/imfs/imfs_eval.c b/cpukit/libfs/src/imfs/imfs_eval.c
index 5b1ccfb..a65569a 100644
--- a/cpukit/libfs/src/imfs/imfs_eval.c
+++ b/cpukit/libfs/src/imfs/imfs_eval.c
@@ -50,7 +50,7 @@ void IMFS_Set_handlers( rtems_filesystem_location_info_t *loc )
   loc->handlers = handlers;
 }
 
-static bool IMFS_is_directory(
+static bool IMFS_eval_is_directory(
   rtems_filesystem_eval_path_context_t *ctx,
   void *arg
 )
@@ -59,7 +59,7 @@ static bool IMFS_is_directory(
     rtems_filesystem_eval_path_get_currentloc( ctx );
   IMFS_jnode_t *node = currentloc->node_access;
 
-  return node->type == IMFS_DIRECTORY;
+  return IMFS_is_directory( node );
 }
 
 static IMFS_jnode_t *IMFS_search_in_directory(
@@ -96,12 +96,13 @@ static IMFS_jnode_t *IMFS_search_in_directory(
 }
 
 static rtems_filesystem_global_location_t **IMFS_is_mount_point(
-  IMFS_jnode_t *node
+  IMFS_jnode_t *node,
+  IMFS_jnode_types_t type
 )
 {
   rtems_filesystem_global_location_t **fs_root_ptr = NULL;
 
-  if ( node->type == IMFS_DIRECTORY ) {
+  if ( type == IMFS_DIRECTORY ) {
     if ( node->info.directory.mt_fs != NULL ) {
       fs_root_ptr = &node->info.directory.mt_fs->mt_fs_root;
     }
@@ -138,20 +139,21 @@ static rtems_filesystem_eval_path_generic_status IMFS_eval_token(
       int eval_flags = rtems_filesystem_eval_path_get_flags( ctx );
       bool follow_hard_link = (eval_flags & RTEMS_FS_FOLLOW_HARD_LINK) != 0;
       bool follow_sym_link = (eval_flags & RTEMS_FS_FOLLOW_SYM_LINK) != 0;
+      IMFS_jnode_types_t type = IMFS_type( entry );
 
       rtems_filesystem_eval_path_clear_token( ctx );
 
-      if ( entry->type == IMFS_HARD_LINK && (follow_hard_link || !terminal)) {
+      if ( type == IMFS_HARD_LINK && (follow_hard_link || !terminal)) {
         entry = entry->info.hard_link.link_node;
       }
 
-      if ( entry->type == IMFS_SYM_LINK && (follow_sym_link || !terminal)) {
+      if ( type == IMFS_SYM_LINK && (follow_sym_link || !terminal)) {
         const char *target = entry->info.sym_link.name;
 
         rtems_filesystem_eval_path_recursive( ctx, target, strlen( target ) );
       } else {
         rtems_filesystem_global_location_t **fs_root_ptr =
-          IMFS_is_mount_point( entry );
+          IMFS_is_mount_point( entry, type );
 
         if ( fs_root_ptr == NULL ) {
           --dir->reference_count;
@@ -184,7 +186,7 @@ static rtems_filesystem_eval_path_generic_status IMFS_eval_token(
 }
 
 static const rtems_filesystem_eval_path_generic_config IMFS_eval_config = {
-  .is_directory = IMFS_is_directory,
+  .is_directory = IMFS_eval_is_directory,
   .eval_token = IMFS_eval_token
 };
 
diff --git a/cpukit/libfs/src/imfs/imfs_fsunmount.c b/cpukit/libfs/src/imfs/imfs_fsunmount.c
index 6f9388e..acce212 100644
--- a/cpukit/libfs/src/imfs/imfs_fsunmount.c
+++ b/cpukit/libfs/src/imfs/imfs_fsunmount.c
@@ -61,7 +61,7 @@ void IMFS_fsunmount(
      loc.node_access = (void *)jnode;
      IMFS_Set_handlers( &loc );
 
-     if ( jnode->type != IMFS_DIRECTORY || jnode_has_no_children( jnode ) ) {
+     if ( !IMFS_is_directory( jnode ) || jnode_has_no_children( jnode ) ) {
         result = IMFS_rmnod( NULL, &loc );
         if ( result != 0 )
 	  rtems_fatal_error_occurred( 0xdeadbeef );
@@ -69,7 +69,7 @@ void IMFS_fsunmount(
         jnode = next;
      }
      if ( jnode != NULL ) {
-       if ( jnode->type == IMFS_DIRECTORY ) {
+       if ( IMFS_is_directory( jnode ) ) {
          if ( jnode_has_children( jnode ) )
            jnode = jnode_get_first_child( jnode );
        }
diff --git a/cpukit/libfs/src/imfs/imfs_mount.c b/cpukit/libfs/src/imfs/imfs_mount.c
index 243e5a0..ca53d95 100644
--- a/cpukit/libfs/src/imfs/imfs_mount.c
+++ b/cpukit/libfs/src/imfs/imfs_mount.c
@@ -25,7 +25,7 @@ int IMFS_mount( rtems_filesystem_mount_table_entry_t *mt_entry )
   int rv = 0;
   IMFS_jnode_t *node = mt_entry->mt_point_node->location.node_access;
 
-  if ( node->type == IMFS_DIRECTORY ) {
+  if ( IMFS_is_directory( node ) ) {
     if ( node->info.directory.mt_fs == NULL ) {
       node->info.directory.mt_fs = mt_entry;
     } else {
diff --git a/cpukit/libfs/src/imfs/imfs_ntype.c b/cpukit/libfs/src/imfs/imfs_ntype.c
index f399707..fa9a37d 100644
--- a/cpukit/libfs/src/imfs/imfs_ntype.c
+++ b/cpukit/libfs/src/imfs/imfs_ntype.c
@@ -28,12 +28,12 @@ rtems_filesystem_node_types_t IMFS_node_type(
 )
 {
   const IMFS_jnode_t *node = loc->node_access;
-  IMFS_jnode_types_t imfs_type = node->type;
+  IMFS_jnode_types_t imfs_type = IMFS_type( node );
   rtems_filesystem_node_types_t type;
 
   switch ( imfs_type ) {
     case IMFS_HARD_LINK:
-      type = node->info.hard_link.link_node->type;
+      type = IMFS_type( node->info.hard_link.link_node );
       break;
     case IMFS_LINEAR_FILE:
       type = RTEMS_FILESYSTEM_MEMORY_FILE;
diff --git a/cpukit/libfs/src/imfs/imfs_stat.c b/cpukit/libfs/src/imfs/imfs_stat.c
index 66d1ca2..42185f3 100644
--- a/cpukit/libfs/src/imfs/imfs_stat.c
+++ b/cpukit/libfs/src/imfs/imfs_stat.c
@@ -49,11 +49,11 @@ int IMFS_stat(
   IMFS_jnode_t *the_jnode = loc->node_access;
   IMFS_device_t *io = &the_jnode->info.device;
 
-  if ( the_jnode->type == IMFS_HARD_LINK ) {
+  if ( IMFS_type( the_jnode ) == IMFS_HARD_LINK ) {
     the_jnode = the_jnode->info.hard_link.link_node;
   }
 
-  switch ( the_jnode->type ) {
+  switch ( IMFS_type( the_jnode ) ) {
 
     case IMFS_DEVICE:
       buf->st_rdev = rtems_filesystem_make_dev_t( io->major, io->minor );
@@ -97,7 +97,7 @@ int IMFS_stat(
   buf->st_mtime = the_jnode->stat_mtime;
   buf->st_ctime = the_jnode->stat_ctime;
 
-  if ( the_jnode->type != IMFS_DIRECTORY ) {
+  if ( !IMFS_is_directory( the_jnode ) ) {
     buf->st_blksize = imfs_rq_memfile_bytes_per_block;
   }
 
diff --git a/cpukit/libfs/src/imfs/imfs_unmount.c b/cpukit/libfs/src/imfs/imfs_unmount.c
index 47acec9..f6315ab 100644
--- a/cpukit/libfs/src/imfs/imfs_unmount.c
+++ b/cpukit/libfs/src/imfs/imfs_unmount.c
@@ -25,7 +25,7 @@ int IMFS_unmount( rtems_filesystem_mount_table_entry_t *mt_entry )
   int rv = 0;
   IMFS_jnode_t *node = mt_entry->mt_point_node->location.node_access;
 
-  if ( node->type == IMFS_DIRECTORY ) {
+  if ( IMFS_is_directory( node ) ) {
     if ( node->info.directory.mt_fs == mt_entry ) {
       node->info.directory.mt_fs = NULL;
     } else {
diff --git a/cpukit/libfs/src/imfs/memfile.c b/cpukit/libfs/src/imfs/memfile.c
index fed8914..aa3f8a7 100644
--- a/cpukit/libfs/src/imfs/memfile.c
+++ b/cpukit/libfs/src/imfs/memfile.c
@@ -93,7 +93,7 @@ int memfile_open(
    * Perform 'copy on write' for linear files
    */
   if ((iop->flags & (LIBIO_FLAGS_WRITE | LIBIO_FLAGS_APPEND))
-   && (the_jnode->type == IMFS_LINEAR_FILE)) {
+   && (IMFS_type( the_jnode ) == IMFS_LINEAR_FILE)) {
     uint32_t   count = the_jnode->info.linearfile.size;
     const unsigned char *buffer = the_jnode->info.linearfile.direct;
 
@@ -184,7 +184,7 @@ off_t memfile_lseek(
 
   the_jnode = iop->pathinfo.node_access;
 
-  if (the_jnode->type == IMFS_LINEAR_FILE) {
+  if (IMFS_type( the_jnode ) == IMFS_LINEAR_FILE) {
     if (iop->offset > the_jnode->info.linearfile.size)
       iop->offset = the_jnode->info.linearfile.size;
   }
@@ -259,7 +259,7 @@ MEMFILE_STATIC int IMFS_memfile_extend(
    *  Perform internal consistency checks
    */
   IMFS_assert( the_jnode );
-    IMFS_assert( the_jnode->type == IMFS_MEMORY_FILE );
+    IMFS_assert( IMFS_type( the_jnode ) == IMFS_MEMORY_FILE );
 
   /*
    *  Verify new file size is supported
@@ -315,7 +315,7 @@ MEMFILE_STATIC int IMFS_memfile_addblock(
   block_p *block_entry_ptr;
 
   IMFS_assert( the_jnode );
-  IMFS_assert( the_jnode->type == IMFS_MEMORY_FILE );
+  IMFS_assert( IMFS_type( the_jnode ) == IMFS_MEMORY_FILE );
 
   /*
    * Obtain the pointer for the specified block number
@@ -434,7 +434,7 @@ int IMFS_memfile_remove(
    *  Perform internal consistency checks
    */
   IMFS_assert( the_jnode );
-  IMFS_assert( the_jnode->type == IMFS_MEMORY_FILE );
+  IMFS_assert( IMFS_type( the_jnode ) == IMFS_MEMORY_FILE );
 
   /*
    *  Eventually this could be set smarter at each call to
@@ -518,8 +518,8 @@ MEMFILE_STATIC ssize_t IMFS_memfile_read(
    *  Perform internal consistency checks
    */
   IMFS_assert( the_jnode );
-  IMFS_assert( the_jnode->type == IMFS_MEMORY_FILE ||
-       the_jnode->type == IMFS_LINEAR_FILE );
+  IMFS_assert( IMFS_type( the_jnode ) == IMFS_MEMORY_FILE ||
+    IMFS_type( the_jnode ) == IMFS_LINEAR_FILE );
   IMFS_assert( dest );
 
   /*
@@ -528,7 +528,7 @@ MEMFILE_STATIC ssize_t IMFS_memfile_read(
    */
   my_length = length;
 
-  if (the_jnode->type == IMFS_LINEAR_FILE) {
+  if ( IMFS_type( the_jnode ) == IMFS_LINEAR_FILE ) {
     unsigned char  *file_ptr;
 
     file_ptr = (unsigned char *)the_jnode->info.linearfile.direct;
@@ -642,7 +642,7 @@ MEMFILE_STATIC ssize_t IMFS_memfile_write(
    */
   IMFS_assert( source );
   IMFS_assert( the_jnode );
-  IMFS_assert( the_jnode->type == IMFS_MEMORY_FILE );
+  IMFS_assert( IMFS_type( the_jnode ) == IMFS_MEMORY_FILE );
 
   my_length = length;
   /*
@@ -787,7 +787,7 @@ block_p *IMFS_memfile_get_block_pointer(
    *  Perform internal consistency checks
    */
   IMFS_assert( the_jnode );
-  IMFS_assert( the_jnode->type == IMFS_MEMORY_FILE );
+  IMFS_assert( IMFS_type( the_jnode ) == IMFS_MEMORY_FILE );
 
   info = &the_jnode->info.file;
   my_block = block;




More information about the vc mailing list