diff options
author | Joel Sherrill <joel.sherrill@OARcorp.com> | 2010-01-19 19:31:00 +0000 |
---|---|---|
committer | Joel Sherrill <joel.sherrill@OARcorp.com> | 2010-01-19 19:31:00 +0000 |
commit | cb4e99201e1702a62af73debe342ea289f0d8362 (patch) | |
tree | 59ce92a3f4280b556c1456896b77a3ea3e57dbab /cpukit/libfs/src/imfs/imfs_creat.c | |
parent | f1eb199a2e39585944a5ed376bd185c9576ffb52 (diff) |
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.
Diffstat (limited to 'cpukit/libfs/src/imfs/imfs_creat.c')
-rw-r--r-- | cpukit/libfs/src/imfs/imfs_creat.c | 135 |
1 files changed, 88 insertions, 47 deletions
diff --git a/cpukit/libfs/src/imfs/imfs_creat.c b/cpukit/libfs/src/imfs/imfs_creat.c index 946e71d729..9313d6c6f5 100644 --- a/cpukit/libfs/src/imfs/imfs_creat.c +++ b/cpukit/libfs/src/imfs/imfs_creat.c @@ -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; - /* - * Allocate an IMFS jnode + * MUST have a parent node to call this routine. */ - - node = calloc( 1, sizeof( IMFS_jnode_t ) ); - if ( !node ) + if ( parent_loc == NULL ) 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. + * Allocate filesystem node and fill in basic information */ - - 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; + node = IMFS_allocate_node( type, name, mode & ~rtems_filesystem_umask ); + if ( !node ) + return NULL; /* * 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. */ + parent = parent_loc->node_access; + fs_info = parent_loc->mt_entry->fs_info; - if ( parent ) { - rtems_chain_append( &parent->info.directory.Entries, &node->Node ); - node->Parent = parent; + node->Parent = parent; + node->st_ino = ++fs_info->ino_count; - fs_info = parent_loc->mt_entry->fs_info; - 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; } |