forked from Imagelibrary/rtems
IMFS: Add root directory to FS info
Fix memory leak in IMFS_fsunmount().
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -22,69 +22,6 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
IMFS_jnode_t *IMFS_allocate_node(
|
||||
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_jnode_t *initialized_node;
|
||||
struct timeval tv;
|
||||
|
||||
if ( namelen > IMFS_NAME_MAX ) {
|
||||
errno = ENAMETOOLONG;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
gettimeofday( &tv, 0 );
|
||||
|
||||
/*
|
||||
* Allocate an IMFS jnode
|
||||
*/
|
||||
node = calloc( 1, node_size );
|
||||
if ( !node ) {
|
||||
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,
|
||||
@@ -95,15 +32,24 @@ IMFS_jnode_t *IMFS_create_node(
|
||||
void *arg
|
||||
)
|
||||
{
|
||||
IMFS_jnode_t *node = IMFS_allocate_node(
|
||||
IMFS_jnode_t *allocated_node;
|
||||
IMFS_jnode_t *node;
|
||||
|
||||
allocated_node = calloc( 1, node_size );
|
||||
if ( allocated_node == NULL ) {
|
||||
errno = ENOMEM;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 */
|
||||
|
||||
Reference in New Issue
Block a user