summaryrefslogtreecommitdiffstats
path: root/cpukit/libfs/src/imfs/imfs_creat.c
diff options
context:
space:
mode:
Diffstat (limited to 'cpukit/libfs/src/imfs/imfs_creat.c')
-rw-r--r--cpukit/libfs/src/imfs/imfs_creat.c138
1 files changed, 43 insertions, 95 deletions
diff --git a/cpukit/libfs/src/imfs/imfs_creat.c b/cpukit/libfs/src/imfs/imfs_creat.c
index 2fe3c7dba1..103320fe85 100644
--- a/cpukit/libfs/src/imfs/imfs_creat.c
+++ b/cpukit/libfs/src/imfs/imfs_creat.c
@@ -22,83 +22,13 @@
#include <stdlib.h>
#include <string.h>
-static void IMFS_initialize_directory( IMFS_jnode_t *dir )
-{
- rtems_chain_initialize_empty( &dir->info.directory.Entries );
-}
-
-/*
- * Create an IMFS filesystem node of an arbitrary type that is NOT
- * the root directory node.
- */
-IMFS_jnode_t *IMFS_create_node(
- const rtems_filesystem_location_info_t *parent_loc,
- IMFS_jnode_types_t type,
- const char *name,
- size_t namelen,
- mode_t mode,
- const IMFS_types_union *info
-)
-{
- IMFS_jnode_t *node;
- IMFS_jnode_t *parent;
- IMFS_fs_info_t *fs_info;
-
- parent = parent_loc->node_access;
- fs_info = parent_loc->mt_entry->fs_info;
-
- /*
- * Allocate filesystem node and fill in basic information
- */
- node = IMFS_allocate_node( type, name, namelen, mode );
- if ( !node )
- return NULL;
-
- /*
- * Set the type specific information
- */
- if ( type == IMFS_DIRECTORY ) {
- IMFS_initialize_directory( node );
- } else if ( type == IMFS_HARD_LINK ) {
- node->info.hard_link.link_node = info->hard_link.link_node;
- } else if ( type == IMFS_SYM_LINK ) {
- node->info.sym_link.name = info->sym_link.name;
- } else if ( type == IMFS_DEVICE ) {
- node->info.device.major = info->device.major;
- node->info.device.minor = info->device.minor;
- } else if ( type == IMFS_LINEAR_FILE ) {
- node->info.linearfile.size = 0;
- node->info.linearfile.direct = 0;
- } else if ( type == IMFS_MEMORY_FILE ) {
- node->info.file.size = 0;
- node->info.file.indirect = 0;
- node->info.file.doubly_indirect = 0;
- node->info.file.triply_indirect = 0;
- } else if ( type == IMFS_FIFO ) {
- node->info.fifo.pipe = NULL;
- } else {
- IMFS_assert(0);
- }
-
- /*
- * This node MUST have a parent, so put it in that directory list.
- */
- IMFS_assert( parent != NULL );
- IMFS_add_to_directory( parent, node );
-
- node->st_ino = ++fs_info->ino_count;
-
- return node;
-}
-
-/*
- * Allocate filesystem node and fill in basic information
- */
IMFS_jnode_t *IMFS_allocate_node(
- IMFS_jnode_types_t type,
- const char *name,
- size_t namelen,
- mode_t mode
+ IMFS_fs_info_t *fs_info,
+ const IMFS_node_control *node_control,
+ const char *name,
+ size_t namelen,
+ mode_t mode,
+ const IMFS_types_union *info
)
{
IMFS_jnode_t *node;
@@ -110,6 +40,8 @@ IMFS_jnode_t *IMFS_allocate_node(
return NULL;
}
+ gettimeofday( &tv, 0 );
+
/*
* Allocate an IMFS jnode
*/
@@ -125,9 +57,9 @@ IMFS_jnode_t *IMFS_allocate_node(
*/
node->reference_count = 1;
node->st_nlink = 1;
- node->type = type;
memcpy( node->name, name, namelen );
node->name [namelen] = '\0';
+ node->control = node_control;
/*
* Fill in the mode and permission information for the jnode structure.
@@ -144,32 +76,48 @@ IMFS_jnode_t *IMFS_allocate_node(
/*
* 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;
+ node->st_ino = ++fs_info->ino_count;
- return node;
+ return (*node->control->node_initialize)( node, info );
}
-IMFS_jnode_t *IMFS_create_root_node(void)
+/*
+ * Create an IMFS filesystem node of an arbitrary type that is NOT
+ * the root directory node.
+ */
+IMFS_jnode_t *IMFS_create_node_with_control(
+ const rtems_filesystem_location_info_t *parentloc,
+ const IMFS_node_control *node_control,
+ const char *name,
+ size_t namelen,
+ mode_t mode,
+ const IMFS_types_union *info
+)
{
- IMFS_jnode_t *node;
-
- /*
- * Allocate filesystem node and fill in basic information
- */
- node = IMFS_allocate_node( IMFS_DIRECTORY, "", 0, (S_IFDIR | 0755) );
- if ( !node )
- return NULL;
-
- /*
- * Set the type specific information
- *
- * NOTE: Root node is always a directory.
- */
- IMFS_initialize_directory( node );
+ IMFS_fs_info_t *fs_info = parentloc->mt_entry->fs_info;
+ IMFS_jnode_t *node = IMFS_allocate_node(
+ fs_info,
+ node_control,
+ name,
+ namelen,
+ mode,
+ info
+ );
+
+ if ( node != NULL ) {
+ IMFS_jnode_t *parent = parentloc->node_access;
+
+ /*
+ * This node MUST have a parent, so put it in that directory list.
+ */
+ IMFS_assert( parent != NULL );
+ IMFS_add_to_directory( parent, node );
+ }
return node;
}
+