[rtems commit] IMFS: Node specific stat handlers

Sebastian Huber sebh at rtems.org
Tue Mar 13 11:31:32 UTC 2012


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

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Mon Mar  5 11:51:23 2012 +0100

IMFS: Node specific stat handlers

---

 cpukit/libfs/src/imfs/imfs_handlers_device.c    |   15 ++++++-
 cpukit/libfs/src/imfs/imfs_handlers_directory.c |   31 +++++++++++++-
 cpukit/libfs/src/imfs/imfs_handlers_link.c      |   24 ++++++++++-
 cpukit/libfs/src/imfs/imfs_handlers_memfile.c   |   15 ++++++-
 cpukit/libfs/src/imfs/imfs_stat.c               |   54 -----------------------
 5 files changed, 81 insertions(+), 58 deletions(-)

diff --git a/cpukit/libfs/src/imfs/imfs_handlers_device.c b/cpukit/libfs/src/imfs/imfs_handlers_device.c
index 625bc39..dfbd894 100644
--- a/cpukit/libfs/src/imfs/imfs_handlers_device.c
+++ b/cpukit/libfs/src/imfs/imfs_handlers_device.c
@@ -17,6 +17,19 @@
 
 #include "imfs.h"
 
+static int IMFS_stat_device(
+  const rtems_filesystem_location_info_t *loc,
+  struct stat *buf
+)
+{
+  const IMFS_jnode_t *node = loc->node_access;
+  const IMFS_device_t *io = &node->info.device;
+
+  buf->st_rdev = rtems_filesystem_make_dev_t( io->major, io->minor );
+
+  return IMFS_stat( loc, buf );
+}
+
 static const rtems_filesystem_file_handlers_r IMFS_device_handlers = {
   device_open,
   device_close,
@@ -24,7 +37,7 @@ static const rtems_filesystem_file_handlers_r IMFS_device_handlers = {
   device_write,
   device_ioctl,
   device_lseek,
-  IMFS_stat,
+  IMFS_stat_device,
   device_ftruncate,
   rtems_filesystem_default_fsync_or_fdatasync,
   rtems_filesystem_default_fsync_or_fdatasync,
diff --git a/cpukit/libfs/src/imfs/imfs_handlers_directory.c b/cpukit/libfs/src/imfs/imfs_handlers_directory.c
index 56b1461..9c3f774 100644
--- a/cpukit/libfs/src/imfs/imfs_handlers_directory.c
+++ b/cpukit/libfs/src/imfs/imfs_handlers_directory.c
@@ -17,6 +17,35 @@
 
 #include "imfs.h"
 
+#include <dirent.h>
+
+static size_t IMFS_directory_size( const IMFS_jnode_t *node )
+{
+  size_t size = 0;
+  const rtems_chain_control *chain = &node->info.directory.Entries;
+  const rtems_chain_node *current = rtems_chain_immutable_first( chain );
+  const rtems_chain_node *tail = rtems_chain_immutable_tail( chain );
+
+  while ( current != tail ) {
+    size += sizeof( struct dirent );
+    current = rtems_chain_immutable_next( current );
+  }
+
+  return size;
+}
+
+static int IMFS_stat_directory(
+  const rtems_filesystem_location_info_t *loc,
+  struct stat *buf
+)
+{
+  const IMFS_jnode_t *node = loc->node_access;
+
+  buf->st_size = IMFS_directory_size( node );
+
+  return IMFS_stat( loc, buf );
+}
+
 static const rtems_filesystem_file_handlers_r IMFS_directory_handlers = {
   rtems_filesystem_default_open,
   rtems_filesystem_default_close,
@@ -24,7 +53,7 @@ static const rtems_filesystem_file_handlers_r IMFS_directory_handlers = {
   rtems_filesystem_default_write,
   rtems_filesystem_default_ioctl,
   imfs_dir_lseek,
-  IMFS_stat,
+  IMFS_stat_directory,
   rtems_filesystem_default_ftruncate_directory,
   rtems_filesystem_default_fsync_or_fdatasync_success,
   rtems_filesystem_default_fsync_or_fdatasync_success,
diff --git a/cpukit/libfs/src/imfs/imfs_handlers_link.c b/cpukit/libfs/src/imfs/imfs_handlers_link.c
index 08dddb7..c1d772c 100644
--- a/cpukit/libfs/src/imfs/imfs_handlers_link.c
+++ b/cpukit/libfs/src/imfs/imfs_handlers_link.c
@@ -18,6 +18,28 @@
 #include "imfs.h"
 
 #include <stdlib.h>
+#include <string.h>
+
+static int IMFS_stat_link(
+  const rtems_filesystem_location_info_t *loc,
+  struct stat *buf
+)
+{
+  const IMFS_jnode_t *node = loc->node_access;
+
+  if ( IMFS_type( node ) != IMFS_HARD_LINK ) {
+    buf->st_size = strlen( node->info.sym_link.name );
+
+    return IMFS_stat( loc, buf );
+  } else {
+    rtems_filesystem_location_info_t targetloc = *loc;
+
+    targetloc.node_access = node->info.hard_link.link_node;
+    IMFS_Set_handlers( &targetloc );
+
+    return (targetloc.handlers->fstat_h)( &targetloc, buf );
+  }
+}
 
 static const rtems_filesystem_file_handlers_r IMFS_link_handlers = {
   rtems_filesystem_default_open,
@@ -26,7 +48,7 @@ static const rtems_filesystem_file_handlers_r IMFS_link_handlers = {
   rtems_filesystem_default_write,
   rtems_filesystem_default_ioctl,
   rtems_filesystem_default_lseek,
-  IMFS_stat,  /* stat */
+  IMFS_stat_link,
   rtems_filesystem_default_ftruncate,
   rtems_filesystem_default_fsync_or_fdatasync,
   rtems_filesystem_default_fsync_or_fdatasync,
diff --git a/cpukit/libfs/src/imfs/imfs_handlers_memfile.c b/cpukit/libfs/src/imfs/imfs_handlers_memfile.c
index 0e32291..57d488a 100644
--- a/cpukit/libfs/src/imfs/imfs_handlers_memfile.c
+++ b/cpukit/libfs/src/imfs/imfs_handlers_memfile.c
@@ -17,6 +17,19 @@
 
 #include "imfs.h"
 
+static int IMFS_stat_file(
+  const rtems_filesystem_location_info_t *loc,
+  struct stat *buf
+)
+{
+  const IMFS_jnode_t *node = loc->node_access;
+
+  buf->st_size = node->info.file.size;
+  buf->st_blksize = imfs_rq_memfile_bytes_per_block;
+
+  return IMFS_stat( loc, buf );
+}
+
 static const rtems_filesystem_file_handlers_r IMFS_memfile_handlers = {
   memfile_open,
   rtems_filesystem_default_close,
@@ -24,7 +37,7 @@ static const rtems_filesystem_file_handlers_r IMFS_memfile_handlers = {
   memfile_write,
   memfile_ioctl,
   memfile_lseek,
-  IMFS_stat,
+  IMFS_stat_file,
   memfile_ftruncate,
   rtems_filesystem_default_fsync_or_fdatasync_success,
   rtems_filesystem_default_fsync_or_fdatasync_success,
diff --git a/cpukit/libfs/src/imfs/imfs_stat.c b/cpukit/libfs/src/imfs/imfs_stat.c
index 42185f3..d0ebc4c 100644
--- a/cpukit/libfs/src/imfs/imfs_stat.c
+++ b/cpukit/libfs/src/imfs/imfs_stat.c
@@ -22,24 +22,6 @@
 
 #include "imfs.h"
 
-#include <dirent.h>
-#include <string.h>
-
-static size_t IMFS_directory_size( const IMFS_jnode_t *the_jnode )
-{
-  size_t size = 0;
-  const rtems_chain_control *chain = &the_jnode->info.directory.Entries;
-  const rtems_chain_node *current = rtems_chain_immutable_first( chain );
-  const rtems_chain_node *tail = rtems_chain_immutable_tail( chain );
-
-  while ( current != tail ) {
-    size += sizeof(struct dirent);
-    current = rtems_chain_immutable_next( current );
-  }
-
-  return size;
-}
-
 int IMFS_stat(
   const rtems_filesystem_location_info_t *loc,
   struct stat *buf
@@ -47,38 +29,6 @@ int IMFS_stat(
 {
   IMFS_fs_info_t *fs_info = loc->mt_entry->fs_info;
   IMFS_jnode_t *the_jnode = loc->node_access;
-  IMFS_device_t *io = &the_jnode->info.device;
-
-  if ( IMFS_type( the_jnode ) == IMFS_HARD_LINK ) {
-    the_jnode = the_jnode->info.hard_link.link_node;
-  }
-
-  switch ( IMFS_type( the_jnode ) ) {
-
-    case IMFS_DEVICE:
-      buf->st_rdev = rtems_filesystem_make_dev_t( io->major, io->minor );
-      break;
-
-    case IMFS_LINEAR_FILE:
-    case IMFS_MEMORY_FILE:
-      buf->st_size = the_jnode->info.file.size;
-      break;
-
-    case IMFS_DIRECTORY:
-      buf->st_size = IMFS_directory_size( the_jnode );
-      break;
-
-    case IMFS_SYM_LINK:
-      buf->st_size = strlen( the_jnode->info.sym_link.name );
-      break;
-
-    case IMFS_FIFO:
-      break;
-
-    default:
-      rtems_set_errno_and_return_minus_one( ENOTSUP );
-      break;
-  }
 
   /*
    * The device number of the IMFS is the major number and the minor is the
@@ -97,9 +47,5 @@ int IMFS_stat(
   buf->st_mtime = the_jnode->stat_mtime;
   buf->st_ctime = the_jnode->stat_ctime;
 
-  if ( !IMFS_is_directory( the_jnode ) ) {
-    buf->st_blksize = imfs_rq_memfile_bytes_per_block;
-  }
-
   return 0;
 }




More information about the vc mailing list