[PATCH 4/7] IMFS: Add root directory to FS info
Sebastian Huber
sebastian.huber at embedded-brains.de
Mon Feb 9 20:35:54 UTC 2015
Fix memory leak in IMFS_fsunmount().
---
cpukit/libfs/src/imfs/imfs.h | 10 ++--
cpukit/libfs/src/imfs/imfs_creat.c | 72 ++++-----------------------
cpukit/libfs/src/imfs/imfs_fsunmount.c | 6 ---
cpukit/libfs/src/imfs/imfs_initsupp.c | 69 ++++++++++++++++++++-----
testsuites/fstests/mimfs_support/fs_support.c | 7 +++
5 files changed, 76 insertions(+), 88 deletions(-)
diff --git a/cpukit/libfs/src/imfs/imfs.h b/cpukit/libfs/src/imfs/imfs.h
index 12881c4..5479791 100644
--- a/cpukit/libfs/src/imfs/imfs.h
+++ b/cpukit/libfs/src/imfs/imfs.h
@@ -375,6 +375,7 @@ static inline void IMFS_mtime_ctime_update( IMFS_jnode_t *jnode )
}
typedef struct {
+ IMFS_directory_t Root_directory;
const IMFS_mknod_control *mknod_controls[ IMFS_TYPE_COUNT ];
} IMFS_fs_info_t;
@@ -562,14 +563,9 @@ extern int IMFS_mknod(
dev_t dev
);
-/**
- * @brief Create a new IMFS node.
- *
- * Routine to create a new in memory file system node.
- */
-extern IMFS_jnode_t *IMFS_allocate_node(
+extern IMFS_jnode_t *IMFS_initialize_node(
+ IMFS_jnode_t *node,
const IMFS_node_control *node_control,
- size_t node_size,
const char *name,
size_t namelen,
mode_t mode,
diff --git a/cpukit/libfs/src/imfs/imfs_creat.c b/cpukit/libfs/src/imfs/imfs_creat.c
index c0fc2e1..9675ca3 100644
--- a/cpukit/libfs/src/imfs/imfs_creat.c
+++ b/cpukit/libfs/src/imfs/imfs_creat.c
@@ -22,7 +22,8 @@
#include <stdlib.h>
#include <string.h>
-IMFS_jnode_t *IMFS_allocate_node(
+IMFS_jnode_t *IMFS_create_node(
+ const rtems_filesystem_location_info_t *parentloc,
const IMFS_node_control *node_control,
size_t node_size,
const char *name,
@@ -31,79 +32,24 @@ IMFS_jnode_t *IMFS_allocate_node(
void *arg
)
{
- IMFS_jnode_t *node;
- IMFS_jnode_t *initialized_node;
- struct timeval tv;
-
- if ( namelen > IMFS_NAME_MAX ) {
- errno = ENAMETOOLONG;
-
- return NULL;
- }
-
- gettimeofday( &tv, 0 );
+ IMFS_jnode_t *allocated_node;
+ IMFS_jnode_t *node;
- /*
- * Allocate an IMFS jnode
- */
- node = calloc( 1, node_size );
- if ( !node ) {
+ allocated_node = calloc( 1, node_size );
+ if ( allocated_node == NULL ) {
errno = ENOMEM;
return NULL;
}
- /*
- * Fill in the basic information
- */
- node->reference_count = 1;
- node->st_nlink = 1;
- memcpy( node->name, name, namelen );
- node->name [namelen] = '\0';
- node->control = node_control;
-
- /*
- * Fill in the mode and permission information for the jnode structure.
- */
- node->st_mode = mode;
- node->st_uid = geteuid();
- node->st_gid = getegid();
-
- /*
- * Now set all the times.
- */
-
- node->stat_atime = (time_t) tv.tv_sec;
- node->stat_mtime = (time_t) tv.tv_sec;
- node->stat_ctime = (time_t) tv.tv_sec;
-
- initialized_node = (*node->control->node_initialize)( node, arg );
- if ( initialized_node == NULL ) {
- free( node );
- }
-
- return initialized_node;
-}
-
-IMFS_jnode_t *IMFS_create_node(
- const rtems_filesystem_location_info_t *parentloc,
- const IMFS_node_control *node_control,
- size_t node_size,
- const char *name,
- size_t namelen,
- mode_t mode,
- void *arg
-)
-{
- IMFS_jnode_t *node = IMFS_allocate_node(
+ node = IMFS_initialize_node(
+ allocated_node,
node_control,
- node_size,
name,
namelen,
mode,
arg
);
-
if ( node != NULL ) {
IMFS_jnode_t *parent = parentloc->node_access;
@@ -112,6 +58,8 @@ IMFS_jnode_t *IMFS_create_node(
*/
IMFS_assert( parent != NULL );
IMFS_add_to_directory( parent, node );
+ } else {
+ free( allocated_node );
}
return node;
diff --git a/cpukit/libfs/src/imfs/imfs_fsunmount.c b/cpukit/libfs/src/imfs/imfs_fsunmount.c
index 629818f..1546927 100644
--- a/cpukit/libfs/src/imfs/imfs_fsunmount.c
+++ b/cpukit/libfs/src/imfs/imfs_fsunmount.c
@@ -49,12 +49,6 @@ void IMFS_fsunmount(
loc = temp_mt_entry->mt_fs_root->location;
jnode = (IMFS_jnode_t *)loc.node_access;
- /*
- * Set this to null to indicate that it is being unmounted.
- */
-
- temp_mt_entry->mt_fs_root->location.node_access = NULL;
-
do {
next = jnode->Parent;
loc.node_access = (void *)jnode;
diff --git a/cpukit/libfs/src/imfs/imfs_initsupp.c b/cpukit/libfs/src/imfs/imfs_initsupp.c
index 9881d84..fee4990 100644
--- a/cpukit/libfs/src/imfs/imfs_initsupp.c
+++ b/cpukit/libfs/src/imfs/imfs_initsupp.c
@@ -23,6 +23,7 @@
#include <errno.h>
#include <stdlib.h>
#include <string.h>
+#include <unistd.h>
/*
* IMFS_determine_bytes_per_block
@@ -55,6 +56,52 @@ static int IMFS_determine_bytes_per_block(
return 0;
}
+IMFS_jnode_t *IMFS_initialize_node(
+ IMFS_jnode_t *node,
+ const IMFS_node_control *node_control,
+ const char *name,
+ size_t namelen,
+ mode_t mode,
+ void *arg
+)
+{
+ struct timeval tv;
+
+ if ( namelen > IMFS_NAME_MAX ) {
+ errno = ENAMETOOLONG;
+
+ return NULL;
+ }
+
+ gettimeofday( &tv, 0 );
+
+ /*
+ * Fill in the basic information
+ */
+ node->reference_count = 1;
+ node->st_nlink = 1;
+ memcpy( node->name, name, namelen );
+ node->name [namelen] = '\0';
+ node->control = node_control;
+
+ /*
+ * Fill in the mode and permission information for the jnode structure.
+ */
+ node->st_mode = mode;
+ node->st_uid = geteuid();
+ node->st_gid = getegid();
+
+ /*
+ * Now set all the times.
+ */
+
+ node->stat_atime = (time_t) tv.tv_sec;
+ node->stat_mtime = (time_t) tv.tv_sec;
+ node->stat_ctime = (time_t) tv.tv_sec;
+
+ return (*node_control->node_initialize)( node, arg );
+}
+
int IMFS_initialize_support(
rtems_filesystem_mount_table_entry_t *mt_entry,
const rtems_filesystem_operations_table *op_table,
@@ -73,25 +120,21 @@ int IMFS_initialize_support(
sizeof( fs_info->mknod_controls )
);
- root_node = IMFS_allocate_node(
+ root_node = IMFS_initialize_node(
+ &fs_info->Root_directory.Node,
&fs_info->mknod_controls[ IMFS_DIRECTORY ]->node_control,
- fs_info->mknod_controls[ IMFS_DIRECTORY ]->node_size,
"",
0,
(S_IFDIR | 0755),
NULL
);
- if ( root_node != NULL ) {
- mt_entry->fs_info = fs_info;
- mt_entry->ops = op_table;
- mt_entry->pathconf_limits_and_options = &IMFS_LIMITS_AND_OPTIONS;
- mt_entry->mt_fs_root->location.node_access = root_node;
- IMFS_Set_handlers( &mt_entry->mt_fs_root->location );
- } else {
- free(fs_info);
- errno = ENOMEM;
- rv = -1;
- }
+ IMFS_assert( root_node != NULL );
+
+ mt_entry->fs_info = fs_info;
+ mt_entry->ops = op_table;
+ mt_entry->pathconf_limits_and_options = &IMFS_LIMITS_AND_OPTIONS;
+ mt_entry->mt_fs_root->location.node_access = root_node;
+ IMFS_Set_handlers( &mt_entry->mt_fs_root->location );
} else {
errno = ENOMEM;
rv = -1;
diff --git a/testsuites/fstests/mimfs_support/fs_support.c b/testsuites/fstests/mimfs_support/fs_support.c
index 5a50d82..849d856 100644
--- a/testsuites/fstests/mimfs_support/fs_support.c
+++ b/testsuites/fstests/mimfs_support/fs_support.c
@@ -14,10 +14,13 @@
#include <sys/stat.h>
#include <rtems/libio.h>
+#include <rtems/libcsupport.h>
#include "fstest.h"
#include "fstest_support.h"
+static rtems_resource_snapshot before_mount;
+
void
test_initialize_filesystem (void)
{
@@ -25,6 +28,8 @@ test_initialize_filesystem (void)
rc = mkdir (BASE_FOR_TEST,S_IRWXU|S_IRWXG|S_IRWXO);
rtems_test_assert (rc == 0);
+ rtems_resource_snapshot_take(&before_mount);
+
rc = mount (NULL, BASE_FOR_TEST, "imfs", RTEMS_FILESYSTEM_READ_WRITE, NULL);
rtems_test_assert (rc == 0);
}
@@ -36,6 +41,8 @@ test_shutdown_filesystem (void)
int rc = 0;
rc = unmount (BASE_FOR_TEST);
rtems_test_assert (rc == 0);
+
+ rtems_test_assert(rtems_resource_snapshot_check(&before_mount));
}
/* configuration information */
--
2.1.4
More information about the devel
mailing list