[rtems commit] IMFS: Allow static initialization of FS info
Sebastian Huber
sebh at rtems.org
Thu Feb 12 20:48:07 UTC 2015
Module: rtems
Branch: master
Commit: a2f5c7e1a70f88eec73fb15e2fcd2c111b52c0ea
Changeset: http://git.rtems.org/rtems/commit/?id=a2f5c7e1a70f88eec73fb15e2fcd2c111b52c0ea
Author: Sebastian Huber <sebastian.huber at embedded-brains.de>
Date: Sun Feb 8 16:09:27 2015 +0100
IMFS: Allow static initialization of FS info
---
cpukit/libfs/src/imfs/fifoimfs_init.c | 32 ++++++++++------
cpukit/libfs/src/imfs/imfs.h | 34 ++++++++---------
cpukit/libfs/src/imfs/imfs_init.c | 32 ++++++++++------
cpukit/libfs/src/imfs/imfs_initsupp.c | 71 ++++++++++++++---------------------
cpukit/libfs/src/imfs/imfs_mknod.c | 17 +++++----
cpukit/libfs/src/imfs/miniimfs_init.c | 32 ++++++++++------
6 files changed, 118 insertions(+), 100 deletions(-)
diff --git a/cpukit/libfs/src/imfs/fifoimfs_init.c b/cpukit/libfs/src/imfs/fifoimfs_init.c
index 3b87f19..4063557 100644
--- a/cpukit/libfs/src/imfs/fifoimfs_init.c
+++ b/cpukit/libfs/src/imfs/fifoimfs_init.c
@@ -25,6 +25,10 @@
#include "imfs.h"
+#include <stdlib.h>
+
+#include <rtems/seterr.h>
+
const rtems_filesystem_operations_table fifoIMFS_ops = {
.lock_h = rtems_filesystem_default_lock,
.unlock_h = rtems_filesystem_default_unlock,
@@ -47,12 +51,11 @@ const rtems_filesystem_operations_table fifoIMFS_ops = {
.statvfs_h = rtems_filesystem_default_statvfs
};
-static const IMFS_mknod_control *const
- IMFS_fifo_mknod_controls[IMFS_TYPE_COUNT] = {
- [IMFS_DIRECTORY] = &IMFS_mknod_control_directory,
- [IMFS_DEVICE] = &IMFS_mknod_control_device,
- [IMFS_MEMORY_FILE] = &IMFS_mknod_control_memfile,
- [IMFS_FIFO] = &IMFS_mknod_control_fifo
+static const IMFS_mknod_controls IMFS_fifo_mknod_controls = {
+ .directory = &IMFS_mknod_control_directory,
+ .device = &IMFS_mknod_control_device,
+ .file = &IMFS_mknod_control_memfile,
+ .fifo = &IMFS_mknod_control_fifo
};
int fifoIMFS_initialize(
@@ -60,9 +63,16 @@ int fifoIMFS_initialize(
const void *data
)
{
- return IMFS_initialize_support(
- mt_entry,
- &fifoIMFS_ops,
- IMFS_fifo_mknod_controls
- );
+ IMFS_fs_info_t *fs_info = calloc( 1, sizeof( *fs_info ) );
+ IMFS_mount_data mount_data = {
+ .fs_info = fs_info,
+ .ops = &fifoIMFS_ops,
+ .mknod_controls = &IMFS_fifo_mknod_controls
+ };
+
+ if ( fs_info == NULL ) {
+ rtems_set_errno_and_return_minus_one( ENOMEM );
+ }
+
+ return IMFS_initialize_support( mt_entry, &mount_data );
}
diff --git a/cpukit/libfs/src/imfs/imfs.h b/cpukit/libfs/src/imfs/imfs.h
index 5479791..00fc179 100644
--- a/cpukit/libfs/src/imfs/imfs.h
+++ b/cpukit/libfs/src/imfs/imfs.h
@@ -94,18 +94,6 @@ typedef block_p *block_ptr;
#define IMFS_MEMFILE_MAXIMUM_SIZE \
(LAST_TRIPLY_INDIRECT * IMFS_MEMFILE_BYTES_PER_BLOCK)
-/*
- * What types of IMFS file systems entities there can be.
- */
-typedef enum {
- IMFS_DIRECTORY,
- IMFS_DEVICE,
- IMFS_MEMORY_FILE,
- IMFS_FIFO
-} IMFS_jnode_types_t;
-
-#define IMFS_TYPE_COUNT (IMFS_FIFO + 1)
-
/** @} */
/**
@@ -375,10 +363,23 @@ static inline void IMFS_mtime_ctime_update( IMFS_jnode_t *jnode )
}
typedef struct {
+ const IMFS_mknod_control *directory;
+ const IMFS_mknod_control *device;
+ const IMFS_mknod_control *file;
+ const IMFS_mknod_control *fifo;
+} IMFS_mknod_controls;
+
+typedef struct {
IMFS_directory_t Root_directory;
- const IMFS_mknod_control *mknod_controls[ IMFS_TYPE_COUNT ];
+ const IMFS_mknod_controls *mknod_controls;
} IMFS_fs_info_t;
+typedef struct {
+ IMFS_fs_info_t *fs_info;
+ const rtems_filesystem_operations_table *ops;
+ const IMFS_mknod_controls *mknod_controls;
+} IMFS_mount_data;
+
/*
* Shared Data
*/
@@ -415,14 +416,11 @@ extern int miniIMFS_initialize(
const void *data
);
-/**
- * @brief IMFS initialization support.
- */
extern int IMFS_initialize_support(
rtems_filesystem_mount_table_entry_t *mt_entry,
- const rtems_filesystem_operations_table *op_table,
- const IMFS_mknod_control *const mknod_controls[ IMFS_TYPE_COUNT ]
+ const void *data
);
+
/**
* @brief Unmount this instance of IMFS.
*/
diff --git a/cpukit/libfs/src/imfs/imfs_init.c b/cpukit/libfs/src/imfs/imfs_init.c
index 854363c..e82490f 100644
--- a/cpukit/libfs/src/imfs/imfs_init.c
+++ b/cpukit/libfs/src/imfs/imfs_init.c
@@ -21,6 +21,10 @@
#include "imfs.h"
+#include <stdlib.h>
+
+#include <rtems/seterr.h>
+
const rtems_filesystem_operations_table IMFS_ops = {
.lock_h = rtems_filesystem_default_lock,
.unlock_h = rtems_filesystem_default_unlock,
@@ -43,12 +47,11 @@ const rtems_filesystem_operations_table IMFS_ops = {
.statvfs_h = rtems_filesystem_default_statvfs
};
-static const IMFS_mknod_control *const
- IMFS_mknod_controls[ IMFS_TYPE_COUNT ] = {
- [IMFS_DIRECTORY] = &IMFS_mknod_control_directory,
- [IMFS_DEVICE] = &IMFS_mknod_control_device,
- [IMFS_MEMORY_FILE] = &IMFS_mknod_control_memfile,
- [IMFS_FIFO] = &IMFS_mknod_control_enosys
+static const IMFS_mknod_controls IMFS_default_mknod_controls = {
+ .directory = &IMFS_mknod_control_directory,
+ .device = &IMFS_mknod_control_device,
+ .file = &IMFS_mknod_control_memfile,
+ .fifo = &IMFS_mknod_control_enosys
};
int IMFS_initialize(
@@ -56,9 +59,16 @@ int IMFS_initialize(
const void *data
)
{
- return IMFS_initialize_support(
- mt_entry,
- &IMFS_ops,
- IMFS_mknod_controls
- );
+ IMFS_fs_info_t *fs_info = calloc( 1, sizeof( *fs_info ) );
+ IMFS_mount_data mount_data = {
+ .fs_info = fs_info,
+ .ops = &IMFS_ops,
+ .mknod_controls = &IMFS_default_mknod_controls
+ };
+
+ if ( fs_info == NULL ) {
+ rtems_set_errno_and_return_minus_one( ENOMEM );
+ }
+
+ return IMFS_initialize_support( mt_entry, &mount_data );
}
diff --git a/cpukit/libfs/src/imfs/imfs_initsupp.c b/cpukit/libfs/src/imfs/imfs_initsupp.c
index fee4990..5f0df25 100644
--- a/cpukit/libfs/src/imfs/imfs_initsupp.c
+++ b/cpukit/libfs/src/imfs/imfs_initsupp.c
@@ -104,51 +104,38 @@ IMFS_jnode_t *IMFS_initialize_node(
int IMFS_initialize_support(
rtems_filesystem_mount_table_entry_t *mt_entry,
- const rtems_filesystem_operations_table *op_table,
- const IMFS_mknod_control *const mknod_controls[ IMFS_TYPE_COUNT ]
+ const void *data
)
{
- int rv = 0;
- IMFS_fs_info_t *fs_info = calloc( 1, sizeof( *fs_info ) );
-
- if ( fs_info != NULL ) {
- IMFS_jnode_t *root_node;
-
- memcpy(
- fs_info->mknod_controls,
- mknod_controls,
- sizeof( fs_info->mknod_controls )
- );
-
- root_node = IMFS_initialize_node(
- &fs_info->Root_directory.Node,
- &fs_info->mknod_controls[ IMFS_DIRECTORY ]->node_control,
- "",
- 0,
- (S_IFDIR | 0755),
- NULL
- );
- 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;
- }
-
- if ( rv == 0 ) {
- IMFS_determine_bytes_per_block(
- &imfs_memfile_bytes_per_block,
- imfs_rq_memfile_bytes_per_block,
- IMFS_MEMFILE_DEFAULT_BYTES_PER_BLOCK
- );
- }
+ const IMFS_mount_data *mount_data = data;
+ IMFS_fs_info_t *fs_info = mount_data->fs_info;
+ IMFS_jnode_t *root_node;
+
+ fs_info->mknod_controls = mount_data->mknod_controls;
+
+ root_node = IMFS_initialize_node(
+ &fs_info->Root_directory.Node,
+ &fs_info->mknod_controls->directory->node_control,
+ "",
+ 0,
+ (S_IFDIR | 0755),
+ NULL
+ );
+ IMFS_assert( root_node != NULL );
+
+ mt_entry->fs_info = fs_info;
+ mt_entry->ops = mount_data->ops;
+ 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 );
+
+ IMFS_determine_bytes_per_block(
+ &imfs_memfile_bytes_per_block,
+ imfs_rq_memfile_bytes_per_block,
+ IMFS_MEMFILE_DEFAULT_BYTES_PER_BLOCK
+ );
- return rv;
+ return 0;
}
int IMFS_node_clone( rtems_filesystem_location_info_t *loc )
diff --git a/cpukit/libfs/src/imfs/imfs_mknod.c b/cpukit/libfs/src/imfs/imfs_mknod.c
index ed67192..1a8438b 100644
--- a/cpukit/libfs/src/imfs/imfs_mknod.c
+++ b/cpukit/libfs/src/imfs/imfs_mknod.c
@@ -23,17 +23,20 @@
#include "imfs.h"
-static IMFS_jnode_types_t get_type( mode_t mode )
+static const IMFS_mknod_control *get_control(
+ const IMFS_mknod_controls *controls,
+ mode_t mode
+)
{
if ( S_ISDIR( mode ) ) {
- return IMFS_DIRECTORY;
+ return controls->directory;
} else if ( S_ISBLK( mode ) || S_ISCHR( mode ) ) {
- return IMFS_DEVICE;
- } else if (S_ISFIFO( mode )) {
- return IMFS_FIFO;
+ return controls->device;
+ } else if ( S_ISFIFO( mode ) ) {
+ return controls->fifo;
} else {
IMFS_assert( S_ISREG( mode ) );
- return IMFS_MEMORY_FILE;
+ return controls->file;
}
}
@@ -48,7 +51,7 @@ int IMFS_mknod(
int rv = 0;
const IMFS_fs_info_t *fs_info = parentloc->mt_entry->fs_info;
const IMFS_mknod_control *mknod_control =
- fs_info->mknod_controls[ get_type( mode ) ];
+ get_control( fs_info->mknod_controls, mode );
IMFS_jnode_t *new_node;
new_node = IMFS_create_node(
diff --git a/cpukit/libfs/src/imfs/miniimfs_init.c b/cpukit/libfs/src/imfs/miniimfs_init.c
index 87879fc..7451c5e 100644
--- a/cpukit/libfs/src/imfs/miniimfs_init.c
+++ b/cpukit/libfs/src/imfs/miniimfs_init.c
@@ -21,6 +21,10 @@
#include "imfs.h"
+#include <stdlib.h>
+
+#include <rtems/seterr.h>
+
const rtems_filesystem_operations_table miniIMFS_ops = {
.lock_h = rtems_filesystem_default_lock,
.unlock_h = rtems_filesystem_default_unlock,
@@ -43,12 +47,11 @@ const rtems_filesystem_operations_table miniIMFS_ops = {
.statvfs_h = rtems_filesystem_default_statvfs
};
-static const IMFS_mknod_control *const
- IMFS_mini_mknod_controls[ IMFS_TYPE_COUNT ] = {
- [IMFS_DIRECTORY] = &IMFS_mknod_control_directory,
- [IMFS_DEVICE] = &IMFS_mknod_control_device,
- [IMFS_MEMORY_FILE] = &IMFS_mknod_control_memfile,
- [IMFS_FIFO] = &IMFS_mknod_control_enosys
+static const IMFS_mknod_controls IMFS_mini_mknod_controls = {
+ .directory = &IMFS_mknod_control_directory,
+ .device = &IMFS_mknod_control_device,
+ .file = &IMFS_mknod_control_memfile,
+ .fifo = &IMFS_mknod_control_enosys
};
int miniIMFS_initialize(
@@ -56,9 +59,16 @@ int miniIMFS_initialize(
const void *data
)
{
- return IMFS_initialize_support(
- mt_entry,
- &miniIMFS_ops,
- IMFS_mini_mknod_controls
- );
+ IMFS_fs_info_t *fs_info = calloc( 1, sizeof( *fs_info ) );
+ IMFS_mount_data mount_data = {
+ .fs_info = fs_info,
+ .ops = &miniIMFS_ops,
+ .mknod_controls = &IMFS_mini_mknod_controls
+ };
+
+ if ( fs_info == NULL ) {
+ rtems_set_errno_and_return_minus_one( ENOMEM );
+ }
+
+ return IMFS_initialize_support( mt_entry, &mount_data );
}
More information about the vc
mailing list