[PATCH 3/3] IMFS: Simplify ino generation

Sebastian Huber sebastian.huber at embedded-brains.de
Wed Feb 4 13:46:26 UTC 2015


The type of ino_t is unsigned long, so it can store a pointer.  Avoid a
potential integer overflow.
---
 cpukit/libfs/src/imfs/imfs.h           | 7 +++++--
 cpukit/libfs/src/imfs/imfs_creat.c     | 1 -
 cpukit/libfs/src/imfs/imfs_directory.c | 2 +-
 cpukit/libfs/src/imfs/imfs_stat.c      | 2 +-
 4 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/cpukit/libfs/src/imfs/imfs.h b/cpukit/libfs/src/imfs/imfs.h
index c296bff..f258ae0 100644
--- a/cpukit/libfs/src/imfs/imfs.h
+++ b/cpukit/libfs/src/imfs/imfs.h
@@ -244,7 +244,6 @@ struct IMFS_jnode_tt {
   mode_t              st_mode;               /* File mode */
   unsigned short      reference_count;
   nlink_t             st_nlink;              /* Link count */
-  ino_t               st_ino;                /* inode */
 
   uid_t               st_uid;                /* User ID of owner */
   gid_t               st_gid;                /* Group ID of owner */
@@ -372,7 +371,6 @@ static inline void IMFS_mtime_ctime_update( IMFS_jnode_t *jnode )
 }
 
 typedef struct {
-  ino_t ino_count;
   const IMFS_node_control *node_controls [IMFS_TYPE_COUNT];
 } IMFS_fs_info_t;
 
@@ -960,6 +958,11 @@ static inline bool IMFS_is_hard_link( mode_t mode )
   return ( mode & S_IFMT ) == IMFS_STAT_FMT_HARD_LINK;
 }
 
+static inline ino_t IMFS_node_to_ino( const IMFS_jnode_t *node )
+{
+  return (ino_t) node;
+}
+
 /** @} */
 
 /**
diff --git a/cpukit/libfs/src/imfs/imfs_creat.c b/cpukit/libfs/src/imfs/imfs_creat.c
index e6dceae..7d60e66 100644
--- a/cpukit/libfs/src/imfs/imfs_creat.c
+++ b/cpukit/libfs/src/imfs/imfs_creat.c
@@ -76,7 +76,6 @@ IMFS_jnode_t *IMFS_allocate_node(
   node->stat_atime  = (time_t) tv.tv_sec;
   node->stat_mtime  = (time_t) tv.tv_sec;
   node->stat_ctime  = (time_t) tv.tv_sec;
-  node->st_ino = ++fs_info->ino_count;
 
   initialized_node = (*node->control->node_initialize)( node, arg );
   if ( initialized_node == NULL ) {
diff --git a/cpukit/libfs/src/imfs/imfs_directory.c b/cpukit/libfs/src/imfs/imfs_directory.c
index fc35b01..5769e07 100644
--- a/cpukit/libfs/src/imfs/imfs_directory.c
+++ b/cpukit/libfs/src/imfs/imfs_directory.c
@@ -73,7 +73,7 @@ ssize_t imfs_dir_read(
          /* Move the entry to the return buffer */
          dir_ent->d_off = current_entry;
          dir_ent->d_reclen = sizeof( *dir_ent );
-         dir_ent->d_ino = imfs_node->st_ino;
+         dir_ent->d_ino = IMFS_node_to_ino( imfs_node );
          dir_ent->d_namlen = strlen( imfs_node->name );
          memcpy( dir_ent->d_name, imfs_node->name, dir_ent->d_namlen + 1 );
 
diff --git a/cpukit/libfs/src/imfs/imfs_stat.c b/cpukit/libfs/src/imfs/imfs_stat.c
index 3d07fe8..c0298b1 100644
--- a/cpukit/libfs/src/imfs/imfs_stat.c
+++ b/cpukit/libfs/src/imfs/imfs_stat.c
@@ -34,7 +34,7 @@ int IMFS_stat(
   buf->st_dev   = rtems_filesystem_make_dev_t_from_pointer( fs_info );
   buf->st_mode  = the_jnode->st_mode;
   buf->st_nlink = the_jnode->st_nlink;
-  buf->st_ino   = the_jnode->st_ino;
+  buf->st_ino   = IMFS_node_to_ino( the_jnode );
   buf->st_uid   = the_jnode->st_uid;
   buf->st_gid   = the_jnode->st_gid;
 
-- 
1.8.1.4



More information about the devel mailing list