2010-01-19 Joel Sherrill <joel.sherrill@oarcorp.com>

* libfs/src/imfs/imfs.h, libfs/src/imfs/imfs_creat.c,
	libfs/src/imfs/imfs_initsupp.c, libfs/src/imfs/imfs_link.c,
	libfs/src/imfs/imfs_load_tar.c, libfs/src/imfs/imfs_mknod.c,
	libfs/src/imfs/imfs_symlink.c: Create special helper method for
	creating the j-node for the root directory. This lets us assume that
	every j-node created otherwise has a parent node.
This commit is contained in:
Joel Sherrill
2010-01-19 19:31:00 +00:00
parent f1eb199a2e
commit cb4e99201e
8 changed files with 215 additions and 161 deletions

View File

@@ -1,3 +1,12 @@
2010-01-19 Joel Sherrill <joel.sherrill@oarcorp.com>
* libfs/src/imfs/imfs.h, libfs/src/imfs/imfs_creat.c,
libfs/src/imfs/imfs_initsupp.c, libfs/src/imfs/imfs_link.c,
libfs/src/imfs/imfs_load_tar.c, libfs/src/imfs/imfs_mknod.c,
libfs/src/imfs/imfs_symlink.c: Create special helper method for
creating the j-node for the root directory. This lets us assume that
every j-node created otherwise has a parent node.
2010-01-18 Sebastian Huber <sebastian.huber@embedded-brains.de>
* libblock/include/rtems/bdbuf.h: Documentation. Renamed

View File

@@ -1,7 +1,7 @@
/*
* Header file for the In-Memory File System
*
* COPYRIGHT (c) 1989-2007.
* COPYRIGHT (c) 1989-2010.
* On-Line Applications Research Corporation (OAR).
*
* The license and distribution terms for this file may be
@@ -322,7 +322,6 @@ extern int IMFS_eval_path(
rtems_filesystem_location_info_t *pathloc /* IN/OUT */
);
extern int IMFS_link(
rtems_filesystem_location_info_t *to_loc, /* IN */
rtems_filesystem_location_info_t *parent_loc, /* IN */
@@ -351,6 +350,14 @@ extern int IMFS_mknod(
rtems_filesystem_location_info_t *pathloc /* IN/OUT */
);
extern IMFS_jnode_t *IMFS_allocate_node(
IMFS_jnode_types_t type, /* IN */
const char *name, /* IN */
mode_t mode /* IN */
);
extern IMFS_jnode_t *IMFS_create_root_node(void);
extern IMFS_jnode_t *IMFS_create_node(
rtems_filesystem_location_info_t *parent_loc, /* IN */
IMFS_jnode_types_t type, /* IN */

View File

@@ -3,7 +3,7 @@
*
* Routine to create a new in memory file system node.
*
* COPYRIGHT (c) 1989-1999.
* COPYRIGHT (c) 1989-2010.
* On-Line Applications Research Corporation (OAR).
*
* The license and distribution terms for this file may be
@@ -23,6 +23,10 @@
#include "imfs.h"
#include <rtems/libio_.h>
/*
* Create an IMFS filesystem node of an arbitrary type that is NOT
* the root directory node.
*/
IMFS_jnode_t *IMFS_create_node(
rtems_filesystem_location_info_t *parent_loc,
IMFS_jnode_types_t type,
@@ -32,57 +36,25 @@ IMFS_jnode_t *IMFS_create_node(
)
{
IMFS_jnode_t *node;
struct timeval tv;
IMFS_jnode_t *parent = NULL;
IMFS_jnode_t *parent;
IMFS_fs_info_t *fs_info;
if ( parent_loc != NULL )
parent = parent_loc->node_access;
/*
* MUST have a parent node to call this routine.
*/
if ( parent_loc == NULL )
return NULL;
/*
* Allocate an IMFS jnode
* Allocate filesystem node and fill in basic information
*/
node = calloc( 1, sizeof( IMFS_jnode_t ) );
node = IMFS_allocate_node( type, name, mode & ~rtems_filesystem_umask );
if ( !node )
return NULL;
/*
* Fill in the basic information
*/
node->st_nlink = 1;
node->type = type;
strncpy( node->name, name, IMFS_NAME_MAX );
/*
* Fill in the mode and permission information for the jnode structure.
*/
node->st_mode = mode & ~rtems_filesystem_umask;
#if defined(RTEMS_POSIX_API)
node->st_uid = geteuid();
node->st_gid = getegid();
#else
node->st_uid = 0;
node->st_gid = 0;
#endif
/*
* Now set all the times.
*/
gettimeofday( &tv, 0 );
node->stat_atime = (time_t) tv.tv_sec;
node->stat_mtime = (time_t) tv.tv_sec;
node->stat_ctime = (time_t) tv.tv_sec;
/*
* Set the type specific information
*/
switch (type) {
case IMFS_DIRECTORY:
rtems_chain_initialize_empty(&node->info.directory.Entries);
@@ -122,17 +94,86 @@ IMFS_jnode_t *IMFS_create_node(
}
/*
* If this node has a parent, then put it in that directory list.
* This node MUST have a parent, so put it in that directory list.
*/
if ( parent ) {
rtems_chain_append( &parent->info.directory.Entries, &node->Node );
node->Parent = parent;
parent = parent_loc->node_access;
fs_info = parent_loc->mt_entry->fs_info;
node->st_ino = ++fs_info->ino_count;
}
node->Parent = parent;
node->st_ino = ++fs_info->ino_count;
rtems_chain_append( &parent->info.directory.Entries, &node->Node );
return node;
}
/*
* Allocate filesystem node and fill in basic information
*/
IMFS_jnode_t *IMFS_allocate_node(
IMFS_jnode_types_t type,
const char *name,
mode_t mode
)
{
IMFS_jnode_t *node;
struct timeval tv;
/*
* Allocate an IMFS jnode
*/
node = calloc( 1, sizeof( IMFS_jnode_t ) );
if ( !node )
return NULL;
/*
* Fill in the basic information
*/
node->st_nlink = 1;
node->type = type;
strncpy( node->name, name, IMFS_NAME_MAX );
/*
* Fill in the mode and permission information for the jnode structure.
*/
node->st_mode = mode;
#if defined(RTEMS_POSIX_API)
node->st_uid = geteuid();
node->st_gid = getegid();
#else
node->st_uid = 0;
node->st_gid = 0;
#endif
/*
* Now set all the times.
*/
gettimeofday( &tv, 0 );
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;
}
IMFS_jnode_t *IMFS_create_root_node(void)
{
IMFS_jnode_t *node;
/*
* Allocate filesystem node and fill in basic information
*/
node = IMFS_allocate_node( IMFS_DIRECTORY, "", (S_IFDIR | 0755) );
if ( !node )
return NULL;
/*
* Set the type specific information
*
* NOTE: Root node is always a directory.
*/
rtems_chain_initialize_empty(&node->info.directory.Entries);
return node;
}

View File

@@ -1,7 +1,7 @@
/*
* IMFS Initialization
*
* COPYRIGHT (c) 1989-1999.
* COPYRIGHT (c) 1989-2010.
* On-Line Applications Research Corporation (OAR).
*
* The license and distribution terms for this file may be
@@ -43,12 +43,11 @@ static int IMFS_determine_bytes_per_block(
{
bool is_valid = false;
int bit_mask;
/*
* check, whether requested bytes per block is valid
*/
for (bit_mask = 16;
!is_valid && (bit_mask <= 512);
bit_mask <<= 1) {
for (bit_mask = 16; !is_valid && (bit_mask <= 512); bit_mask <<= 1) {
if (bit_mask == requested_bytes_per_block) {
is_valid = true;
}
@@ -57,14 +56,12 @@ static int IMFS_determine_bytes_per_block(
? requested_bytes_per_block
: default_bytes_per_block);
return 0;
}
/*
* IMFS_initialize
*/
int IMFS_initialize_support(
rtems_filesystem_mount_table_entry_t *temp_mt_entry,
const rtems_filesystem_operations_table *op_table,
@@ -87,15 +84,7 @@ int IMFS_initialize_support(
*
* NOTE: UNIX root is 755 and owned by root/root (0/0).
*/
temp_mt_entry->mt_fs_root.node_access = IMFS_create_node(
NULL,
IMFS_DIRECTORY,
"",
( S_IFDIR | 0755 ),
NULL
);
temp_mt_entry->mt_fs_root.node_access = IMFS_create_root_node();
temp_mt_entry->mt_fs_root.handlers = directory_handlers;
temp_mt_entry->mt_fs_root.ops = op_table;
temp_mt_entry->pathconf_limits_and_options = IMFS_LIMITS_AND_OPTIONS;
@@ -104,7 +93,7 @@ int IMFS_initialize_support(
* Create custom file system data.
*/
fs_info = calloc( 1, sizeof( IMFS_fs_info_t ) );
if ( !fs_info ){
if ( !fs_info ) {
free(temp_mt_entry->mt_fs_root.node_access);
rtems_set_errno_and_return_minus_one(ENOMEM);
}

View File

@@ -38,7 +38,6 @@ int IMFS_link(
/*
* Verify this node can be linked to.
*/
info.hard_link.link_node = to_loc->node_access;
if ( info.hard_link.link_node->st_nlink >= LINK_MAX )
rtems_set_errno_and_return_minus_one( EMLINK );
@@ -46,17 +45,18 @@ int IMFS_link(
/*
* Remove any separators at the end of the string.
*/
IMFS_get_token( token, strlen( token ), new_name, &i );
/*
* Create a new link node.
*
* NOTE: Coverity thinks this is a resource leak since a node
* is created but never deleted. The scope of the allocation
* is that of a file -- not this method. Coverity Id 19.
* NOTE: Coverity Id 19 reports this as a leak
* While technically not a leak, it indicated that IMFS_create_node
* was ONLY passed a NULL when we created the root node. We
* added a new IMFS_create_root_node() so this path no longer
* existed. The result was simpler code which should not have
* this path.
*/
new_node = IMFS_create_node(
parent_loc,
IMFS_HARD_LINK,
@@ -71,7 +71,6 @@ int IMFS_link(
/*
* Increment the link count of the node being pointed to.
*/
info.hard_link.link_node->st_nlink++;
IMFS_update_ctime( info.hard_link.link_node );

View File

@@ -98,10 +98,15 @@ int rtems_tarfs_load(
IMFS_jnode_t *node;
int status;
status = rtems_filesystem_evaluate_path(mountpoint, strlen(mountpoint),
0, &root_loc, 0);
status = rtems_filesystem_evaluate_path(
mountpoint,
strlen(mountpoint),
0,
&root_loc,
0
);
if (status != 0)
return(-1);
return -1;
if (root_loc.ops != &IMFS_ops)
return -1;
@@ -149,19 +154,24 @@ int rtems_tarfs_load(
/*
* Create a LINEAR_FILE node
*
* NOTE: Coverity thinks this is a resource leak since a node
* is created but never deleted. The scope of the allocation
* is that of a file -- not this method. Coverity Id 20.
* NOTE: Coverity Id 20 reports this as a leak.
* While technically not a leak, it indicated that
* IMFS_create_node was ONLY passed a NULL when we created the
* root node. We added a new IMFS_create_root_node() so this
* path no longer existed. The result was simpler code which
* should not have this path.
*/
else if (linkflag == REGTYPE) {
const char *name;
loc = root_loc;
if (IMFS_evaluate_for_make(filename, &loc, &name) == 0) {
node = IMFS_create_node(&loc,
node = IMFS_create_node(
&loc,
IMFS_LINEAR_FILE, (char *)name,
(file_mode & (S_IRWXU | S_IRWXG | S_IRWXO)) | S_IFREG,
NULL);
NULL
);
node->info.linearfile.size = file_size;
node->info.linearfile.direct = &tar_image[offset];
}
@@ -170,7 +180,6 @@ int rtems_tarfs_load(
offset += 512 * nblocks;
}
}
return status;
}

View File

@@ -46,7 +46,6 @@ int IMFS_mknod(
/*
* Figure out what type of IMFS node this is.
*/
if ( S_ISDIR(mode) )
type = IMFS_DIRECTORY;
else if ( S_ISREG(mode) )
@@ -64,9 +63,12 @@ int IMFS_mknod(
/*
* Allocate and fill in an IMFS jnode
*
* NOTE: Coverity thinks this is a resource leak since a node
* is created but never deleted. The scope of the allocation
* is that of a file -- not this method. Coverity Id 21.
* NOTE: Coverity Id 21 reports this as a leak.
* While technically not a leak, it indicated that IMFS_create_node
* was ONLY passed a NULL when we created the root node. We
* added a new IMFS_create_root_node() so this path no longer
* existed. The result was simpler code which should not have
* this path.
*/
new_node = IMFS_create_node(
pathloc,

View File

@@ -40,13 +40,11 @@ int IMFS_symlink(
/*
* Remove any separators at the end of the string.
*/
IMFS_get_token( node_name, strlen( node_name ), new_name, &i );
/*
* Duplicate link name
*/
info.sym_link.name = strdup(link_name);
if (info.sym_link.name == NULL) {
rtems_set_errno_and_return_minus_one(ENOMEM);
@@ -55,13 +53,13 @@ int IMFS_symlink(
/*
* Create a new link node.
*
* NOTE: Coverity CID 22 notes this as a resource leak. We are ignoring
* this analysis because in this particular case it is wrong. This
* method creates a symbolic link node for the IMFS. The memory
* allocated must persist for the life of the symbolic link not
* the life of the method.
* NOTE: Coverity CID 22 notes this as a resource leak.
* While technically not a leak, it indicated that IMFS_create_node
* was ONLY passed a NULL when we created the root node. We
* added a new IMFS_create_root_node() so this path no longer
* existed. The result was simpler code which should not have
* this path.
*/
new_node = IMFS_create_node(
parent_loc,
IMFS_SYM_LINK,