Added initial cut at miniIMFS which leaves out memfile and directory

readdir support.  The next step is to add a mount table and configure
either the miniIMFS or the full IMFS at the application level.
This commit is contained in:
Joel Sherrill
1999-10-26 20:17:13 +00:00
parent e54a7d33d2
commit 657e1bf66b
41 changed files with 906 additions and 1089 deletions

View File

@@ -306,7 +306,7 @@ typedef struct {
* Structure for a mount table entry.
*/
struct rtems_filesystem_mount_table_entry_tt{
struct rtems_filesystem_mount_table_entry_tt {
Chain_Node Node;
rtems_filesystem_location_info_t mt_point_node;
rtems_filesystem_location_info_t mt_fs_root;

View File

@@ -24,10 +24,11 @@ BASE_FS_C_PIECES = base_fs mount unmount ioman libio libio_sockets eval \
fs_null_handlers
IMFS_C_PIECES = imfs_chown imfs_creat imfs_directory imfs_eval imfs_free \
imfs_gtkn imfs_init imfs_link imfs_mknod imfs_mount imfs_fchmod \
imfs_rmnod imfs_unlink imfs_unmount imfs_utime imfs_ntype imfs_stat \
imfs_getchild memfile deviceio imfs_handlers imfs_debug imfs_symlink \
imfs_readlink imfs_fdatasync imfs_fcntl
imfs_fsunmount imfs_gtkn imfs_init imfs_initsupp imfs_link imfs_mknod \
imfs_mount imfs_fchmod imfs_rmnod imfs_unlink imfs_unmount imfs_utime \
imfs_ntype imfs_stat imfs_getchild memfile deviceio imfs_handlers_device \
imfs_handlers_directory imfs_handlers_memfile imfs_debug imfs_symlink \
imfs_readlink imfs_fdatasync imfs_fcntl miniimfs_init
TERMIOS_C_PIECES = cfgetispeed cfgetospeed cfsetispeed cfsetospeed tcgetattr \
tcsetattr tcdrain tcflow tcflush termios \

View File

@@ -52,6 +52,13 @@ void rtems_filesystem_initialize( void )
init_fs_mount_table();
/*
* mount the first filesystem.
*
* NOTE: XXX This really needs to be read from a table of filesystems
* to mount initially and the miniIMFS needs to be shaken out.
*/
status = mount(
&first_entry,
&IMFS_ops,

View File

@@ -183,7 +183,9 @@ struct IMFS_jnode_tt {
} while (0)
typedef struct {
ino_t ino_count;
ino_t ino_count;
rtems_filesystem_file_handlers_r *memfile_handlers;
rtems_filesystem_file_handlers_r *directory_handlers;
} IMFS_fs_info_t;
#define increment_and_check_linkcounts( _fs_info ) \
@@ -214,6 +216,7 @@ extern rtems_filesystem_file_handlers_r IMFS_device_handlers;
extern rtems_filesystem_file_handlers_r IMFS_memfile_handlers;
extern rtems_filesystem_file_handlers_r IMFS_directory_handlers;
extern rtems_filesystem_operations_table IMFS_ops;
extern rtems_filesystem_operations_table miniIMFS_ops;
extern rtems_filesystem_limits_and_options_t IMFS_LIMITS_AND_OPTIONS;
/*
@@ -224,6 +227,17 @@ int IMFS_initialize(
rtems_filesystem_mount_table_entry_t *mt_entry
);
int miniIMFS_initialize(
rtems_filesystem_mount_table_entry_t *mt_entry
);
int IMFS_initialize_support(
rtems_filesystem_mount_table_entry_t *mt_entry,
rtems_filesystem_operations_table *op_table,
rtems_filesystem_file_handlers_r *memfile_handlers,
rtems_filesystem_file_handlers_r *directory_handlers
);
int IMFS_fsunmount(
rtems_filesystem_mount_table_entry_t *mt_entry
);

View File

@@ -32,11 +32,13 @@ int IMFS_Set_handlers(
rtems_filesystem_location_info_t *loc
)
{
IMFS_jnode_t *node = loc->node_access;
IMFS_jnode_t *node = loc->node_access;
IMFS_fs_info_t *fs_info;
fs_info = loc->mt_entry->fs_info;
switch( node->type ) {
case IMFS_DIRECTORY:
loc->handlers = &IMFS_directory_handlers;
loc->handlers = fs_info->directory_handlers;
break;
case IMFS_DEVICE:
loc->handlers = &IMFS_device_handlers;
@@ -46,7 +48,7 @@ int IMFS_Set_handlers(
loc->handlers = &rtems_filesystem_null_handlers;
break;
case IMFS_MEMORY_FILE:
loc->handlers = &IMFS_memfile_handlers;
loc->handlers = fs_info->memfile_handlers;
break;
}

View File

@@ -35,65 +35,3 @@ int IMFS_freenodinfo(
return 0;
}
/*
* IMFS_freenod
*
* The following routine frees a node if possible.
*
* The routine returns 0 if the node was not freed and 1 if it was.
*
* NOTE: This routine is for INTERNAL IMFS use only.
*/
int IMFS_freenod(
rtems_filesystem_location_info_t *pathloc
)
{
IMFS_jnode_t *the_jnode;
the_jnode = pathloc->node_access;
if ( the_jnode->type == IMFS_DIRECTORY ) {
/*
* You cannot remove a node that still has children
*/
if ( ! Chain_Is_empty( &the_jnode->info.directory.Entries ) )
return ENOTEMPTY;
/*
* You cannot remove the file system root node.
*/
if ( pathloc->mt_entry->mt_fs_root.node_access == pathloc->node_access )
return EBUSY;
/*
* You cannot remove a mountpoint.
*/
if ( the_jnode->info.directory.mt_fs != NULL )
return EBUSY;
}
if ( !rtems_libio_is_file_open( the_jnode ) &&
(the_jnode->st_nlink < 1) ) {
/*
* Is the rtems_filesystem_current is this node?
*/
if ( rtems_filesystem_current.node_access == pathloc->node_access ) {
rtems_filesystem_current.node_access = NULL;
}
/*
* Free memory associated with a memory file.
*/
if ( the_jnode->type == IMFS_MEMORY_FILE )
IMFS_memfile_remove( the_jnode );
free( the_jnode );
}
return 0;
}

View File

@@ -0,0 +1,90 @@
/*
* IMFS Initialization
*
* COPYRIGHT (c) 1989-1998.
* On-Line Applications Research Corporation (OAR).
* Copyright assigned to U.S. Government, 1994.
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.OARcorp.com/rtems/license.html.
*
* $Id$
*/
#include <sys/types.h> /* for mkdir */
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <assert.h>
#include "imfs.h"
#include "libio_.h"
#if defined(IMFS_DEBUG)
#include <stdio.h>
#endif
/*
* IMFS_fsunmount
*/
#define jnode_get_control( jnode ) \
(&jnode->info.directory.Entries)
#define jnode_has_no_children( jnode ) \
Chain_Is_empty( jnode_get_control( jnode ) )
#define jnode_has_children( jnode ) \
( ! jnode_has_no_children( jnode ) )
#define jnode_get_first_child( jnode ) \
((IMFS_jnode_t *)( Chain_Head( jnode_get_control( jnode ) )->next))
int IMFS_fsunmount(
rtems_filesystem_mount_table_entry_t *temp_mt_entry
)
{
IMFS_jnode_t *jnode;
IMFS_jnode_t *next;
rtems_filesystem_location_info_t loc;
int result = 0;
/*
* Traverse tree that starts at the mt_fs_root and deallocate memory
* associated memory space
*/
jnode = (IMFS_jnode_t *)temp_mt_entry->mt_fs_root.node_access;
do {
next = jnode->Parent;
loc.node_access = (void *)jnode;
if ( jnode->type != IMFS_DIRECTORY ) {
result = IMFS_unlink( &loc );
if (result != 0)
return -1;
jnode = next;
} else if ( jnode_has_no_children( jnode ) ) {
result = IMFS_unlink( &loc );
if (result != 0)
return -1;
jnode = next;
}
if ( jnode != NULL ) {
if ( jnode->type == IMFS_DIRECTORY ) {
if ( jnode_has_children( jnode ) )
jnode = jnode_get_first_child( jnode );
}
}
} while (jnode != NULL);
return 0;
}

View File

@@ -1,77 +0,0 @@
/*
* Operations Tables for the IMFS
*
* COPYRIGHT (c) 1989-1998.
* On-Line Applications Research Corporation (OAR).
* Copyright assigned to U.S. Government, 1994.
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.OARcorp.com/rtems/license.html.
*
* $Id$
*/
#include <errno.h>
#include "imfs.h"
/*
* Set of operations handlers for operations on memfile entities.
*/
rtems_filesystem_file_handlers_r IMFS_memfile_handlers = {
memfile_open,
memfile_close,
memfile_read,
memfile_write,
memfile_ioctl,
memfile_lseek,
IMFS_stat,
IMFS_fchmod,
memfile_ftruncate,
NULL, /* fpathconf */
NULL, /* fsync */
IMFS_fdatasync,
IMFS_fcntl
};
/*
* Set of operations handlers for operations on directories.
*/
rtems_filesystem_file_handlers_r IMFS_directory_handlers = {
imfs_dir_open,
imfs_dir_close,
imfs_dir_read,
NULL, /* write */
NULL, /* ioctl */
imfs_dir_lseek,
imfs_dir_fstat,
IMFS_fchmod,
NULL, /* ftruncate */
NULL, /* fpathconf */
NULL, /* fsync */
IMFS_fdatasync,
IMFS_fcntl
};
/*
* Handler table for IMFS device nodes
*/
rtems_filesystem_file_handlers_r IMFS_device_handlers = {
device_open,
device_close,
device_read,
device_write,
device_ioctl,
device_lseek,
IMFS_stat,
IMFS_fchmod,
NULL, /* ftruncate */
NULL, /* fpathconf */
NULL, /* fsync */
NULL, /* fdatasync */
NULL /* fcntl */
};

View File

@@ -26,7 +26,7 @@
#include <stdio.h>
#endif
/*
/*
* IMFS file system operations table
*/
@@ -44,7 +44,7 @@ rtems_filesystem_operations_table IMFS_ops = {
IMFS_initialize,
IMFS_unmount,
IMFS_fsunmount,
IMFS_utime,
IMFS_utime,
IMFS_evaluate_link,
IMFS_symlink,
IMFS_readlink
@@ -58,101 +58,11 @@ int IMFS_initialize(
rtems_filesystem_mount_table_entry_t *temp_mt_entry
)
{
IMFS_fs_info_t *fs_info;
IMFS_jnode_t *jnode;
/*
* Create the root node
*/
temp_mt_entry->mt_fs_root.node_access = IMFS_create_node(
NULL,
IMFS_DIRECTORY,
"",
( S_IRWXO | S_IRWXG| S_IRWXU ),
NULL
);
temp_mt_entry->mt_fs_root.handlers = &IMFS_directory_handlers;
temp_mt_entry->mt_fs_root.ops = &IMFS_ops;
temp_mt_entry->pathconf_limits_and_options = IMFS_LIMITS_AND_OPTIONS;
/*
* Create custom file system data.
*/
fs_info = calloc( 1, sizeof( IMFS_fs_info_t ) );
if ( !fs_info ){
free(temp_mt_entry->mt_fs_root.node_access);
return 1;
}
temp_mt_entry->fs_info = fs_info;
/*
* Set st_ino for the root to 1.
*/
fs_info->ino_count = 1;
jnode = temp_mt_entry->mt_fs_root.node_access;
jnode->st_ino = fs_info->ino_count;
return 0;
}
#define jnode_get_control( jnode ) \
(&jnode->info.directory.Entries)
#define jnode_has_no_children( jnode ) \
Chain_Is_empty( jnode_get_control( jnode ) )
#define jnode_has_children( jnode ) \
( ! jnode_has_no_children( jnode ) )
#define jnode_get_first_child( jnode ) \
((IMFS_jnode_t *)( Chain_Head( jnode_get_control( jnode ) )->next))
int IMFS_fsunmount(
rtems_filesystem_mount_table_entry_t *temp_mt_entry
)
{
IMFS_jnode_t *jnode;
IMFS_jnode_t *next;
rtems_filesystem_location_info_t loc;
int result = 0;
/*
* Traverse tree that starts at the mt_fs_root and deallocate memory
* associated memory space
*/
jnode = (IMFS_jnode_t *)temp_mt_entry->mt_fs_root.node_access;
do {
next = jnode->Parent;
loc.node_access = (void *)jnode;
if ( jnode->type != IMFS_DIRECTORY ) {
result = IMFS_unlink( &loc );
if (result != 0)
return -1;
jnode = next;
} else if ( jnode_has_no_children( jnode ) ) {
result = IMFS_unlink( &loc );
if (result != 0)
return -1;
jnode = next;
}
if ( jnode != NULL ) {
if ( jnode->type == IMFS_DIRECTORY ) {
if ( jnode_has_children( jnode ) )
jnode = jnode_get_first_child( jnode );
}
}
} while (jnode != NULL);
IMFS_initialize_support(
temp_mt_entry,
&IMFS_ops,
&IMFS_memfile_handlers,
&IMFS_directory_handlers
);
return 0;
}

View File

@@ -26,36 +26,15 @@
#include <stdio.h>
#endif
/*
* IMFS file system operations table
*/
rtems_filesystem_operations_table IMFS_ops = {
IMFS_eval_path,
IMFS_evaluate_for_make,
IMFS_link,
IMFS_unlink,
IMFS_node_type,
IMFS_mknod,
IMFS_rmnod,
IMFS_chown,
IMFS_freenodinfo,
IMFS_mount,
IMFS_initialize,
IMFS_unmount,
IMFS_fsunmount,
IMFS_utime,
IMFS_evaluate_link,
IMFS_symlink,
IMFS_readlink
};
/*
* IMFS_initialize
*/
int IMFS_initialize(
rtems_filesystem_mount_table_entry_t *temp_mt_entry
int IMFS_initialize_support(
rtems_filesystem_mount_table_entry_t *temp_mt_entry,
rtems_filesystem_operations_table *op_table,
rtems_filesystem_file_handlers_r *memfile_handlers,
rtems_filesystem_file_handlers_r *directory_handlers
)
{
IMFS_fs_info_t *fs_info;
@@ -73,8 +52,8 @@ int IMFS_initialize(
NULL
);
temp_mt_entry->mt_fs_root.handlers = &IMFS_directory_handlers;
temp_mt_entry->mt_fs_root.ops = &IMFS_ops;
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;
/*
@@ -91,68 +70,12 @@ int IMFS_initialize(
* Set st_ino for the root to 1.
*/
fs_info->ino_count = 1;
fs_info->ino_count = 1;
fs_info->memfile_handlers = memfile_handlers;
fs_info->memfile_handlers = directory_handlers;
jnode = temp_mt_entry->mt_fs_root.node_access;
jnode->st_ino = fs_info->ino_count;
return 0;
}
#define jnode_get_control( jnode ) \
(&jnode->info.directory.Entries)
#define jnode_has_no_children( jnode ) \
Chain_Is_empty( jnode_get_control( jnode ) )
#define jnode_has_children( jnode ) \
( ! jnode_has_no_children( jnode ) )
#define jnode_get_first_child( jnode ) \
((IMFS_jnode_t *)( Chain_Head( jnode_get_control( jnode ) )->next))
int IMFS_fsunmount(
rtems_filesystem_mount_table_entry_t *temp_mt_entry
)
{
IMFS_jnode_t *jnode;
IMFS_jnode_t *next;
rtems_filesystem_location_info_t loc;
int result = 0;
/*
* Traverse tree that starts at the mt_fs_root and deallocate memory
* associated memory space
*/
jnode = (IMFS_jnode_t *)temp_mt_entry->mt_fs_root.node_access;
do {
next = jnode->Parent;
loc.node_access = (void *)jnode;
if ( jnode->type != IMFS_DIRECTORY ) {
result = IMFS_unlink( &loc );
if (result != 0)
return -1;
jnode = next;
} else if ( jnode_has_no_children( jnode ) ) {
result = IMFS_unlink( &loc );
if (result != 0)
return -1;
jnode = next;
}
if ( jnode != NULL ) {
if ( jnode->type == IMFS_DIRECTORY ) {
if ( jnode_has_children( jnode ) )
jnode = jnode_get_first_child( jnode );
}
}
} while (jnode != NULL);
return 0;
}

View File

@@ -306,7 +306,7 @@ typedef struct {
* Structure for a mount table entry.
*/
struct rtems_filesystem_mount_table_entry_tt{
struct rtems_filesystem_mount_table_entry_tt {
Chain_Node Node;
rtems_filesystem_location_info_t mt_point_node;
rtems_filesystem_location_info_t mt_fs_root;

View File

@@ -29,6 +29,26 @@
#define MEMFILE_STATIC
/*
* Set of operations handlers for operations on memfile entities.
*/
rtems_filesystem_file_handlers_r IMFS_memfile_handlers = {
memfile_open,
memfile_close,
memfile_read,
memfile_write,
memfile_ioctl,
memfile_lseek,
IMFS_stat,
IMFS_fchmod,
memfile_ftruncate,
NULL, /* fpathconf */
NULL, /* fsync */
IMFS_fdatasync,
IMFS_fcntl
};
/*
* Prototypes of private routines
*/

View File

@@ -0,0 +1,71 @@
/*
* Mini-IMFS Initialization
*
* COPYRIGHT (c) 1989-1998.
* On-Line Applications Research Corporation (OAR).
* Copyright assigned to U.S. Government, 1994.
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.OARcorp.com/rtems/license.html.
*
* $Id$
*/
#include <sys/types.h> /* for mkdir */
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <assert.h>
#include "imfs.h"
#include "libio_.h"
#if defined(IMFS_DEBUG)
#include <stdio.h>
#endif
/*
* miniIMFS file system operations table
*/
rtems_filesystem_operations_table miniIMFS_ops = {
IMFS_eval_path,
IMFS_evaluate_for_make,
NULL, /* XXX IMFS_link, */
NULL, /* XXX IMFS_unlink, */
IMFS_node_type,
IMFS_mknod,
NULL, /* XXX IMFS_rmnod, */
NULL, /* XXX IMFS_chown, */
NULL, /* XXX IMFS_freenodinfo, */
NULL, /* XXX IMFS_mount, */
miniIMFS_initialize,
NULL, /* XXX IMFS_unmount, */
NULL, /* XXX IMFS_fsunmount, */
NULL, /* XXX IMFS_utime, */
NULL, /* XXX IMFS_evaluate_link, */
NULL, /* XXX IMFS_symlink, */
NULL /* XXX IMFS_readlink */
};
/*
* miniIMFS_initialize
*/
int miniIMFS_initialize(
rtems_filesystem_mount_table_entry_t *temp_mt_entry
)
{
IMFS_initialize_support(
temp_mt_entry,
&miniIMFS_ops,
&rtems_filesystem_null_handlers, /* for memfiles */
&rtems_filesystem_null_handlers /* for directories */
);
return 0;
}