[PATCH 1/7] IMFS: Introduce IMFS_mknod_control
Sebastian Huber
sebastian.huber at embedded-brains.de
Mon Feb 9 20:35:51 UTC 2015
Drop IMFS_node_control::node_size field and add node_size parameter to
IMFS_allocate_node() and IMFS_create_node(). This reduces the size of
generic nodes.
---
cpukit/libfs/src/imfs/fifoimfs_init.c | 14 ++++++-------
cpukit/libfs/src/imfs/imfs.h | 24 +++++++++++++----------
cpukit/libfs/src/imfs/imfs_creat.c | 8 ++++----
cpukit/libfs/src/imfs/imfs_fifo.c | 14 +++++++------
cpukit/libfs/src/imfs/imfs_handlers_device.c | 14 +++++++------
cpukit/libfs/src/imfs/imfs_handlers_directory.c | 14 +++++++------
cpukit/libfs/src/imfs/imfs_handlers_memfile.c | 15 +++++++-------
cpukit/libfs/src/imfs/imfs_init.c | 14 ++++++-------
cpukit/libfs/src/imfs/imfs_initsupp.c | 26 +++++++++++++------------
cpukit/libfs/src/imfs/imfs_link.c | 2 +-
cpukit/libfs/src/imfs/imfs_load_tar.c | 1 +
cpukit/libfs/src/imfs/imfs_make_generic_node.c | 1 +
cpukit/libfs/src/imfs/imfs_mknod.c | 5 ++++-
cpukit/libfs/src/imfs/imfs_symlink.c | 2 +-
cpukit/libfs/src/imfs/memfile.c | 2 +-
cpukit/libfs/src/imfs/miniimfs_init.c | 14 ++++++-------
testsuites/fstests/fsimfsgeneric01/init.c | 2 --
17 files changed, 94 insertions(+), 78 deletions(-)
diff --git a/cpukit/libfs/src/imfs/fifoimfs_init.c b/cpukit/libfs/src/imfs/fifoimfs_init.c
index 17f4917..3b87f19 100644
--- a/cpukit/libfs/src/imfs/fifoimfs_init.c
+++ b/cpukit/libfs/src/imfs/fifoimfs_init.c
@@ -47,12 +47,12 @@ const rtems_filesystem_operations_table fifoIMFS_ops = {
.statvfs_h = rtems_filesystem_default_statvfs
};
-static const IMFS_node_control *const
- IMFS_fifo_node_controls [IMFS_TYPE_COUNT] = {
- [IMFS_DIRECTORY] = &IMFS_node_control_directory,
- [IMFS_DEVICE] = &IMFS_node_control_device,
- [IMFS_MEMORY_FILE] = &IMFS_node_control_memfile,
- [IMFS_FIFO] = &IMFS_node_control_fifo
+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
};
int fifoIMFS_initialize(
@@ -63,6 +63,6 @@ int fifoIMFS_initialize(
return IMFS_initialize_support(
mt_entry,
&fifoIMFS_ops,
- IMFS_fifo_node_controls
+ IMFS_fifo_mknod_controls
);
}
diff --git a/cpukit/libfs/src/imfs/imfs.h b/cpukit/libfs/src/imfs/imfs.h
index f258ae0..f69408a 100644
--- a/cpukit/libfs/src/imfs/imfs.h
+++ b/cpukit/libfs/src/imfs/imfs.h
@@ -214,12 +214,16 @@ void IMFS_node_destroy_default( IMFS_jnode_t *node );
*/
typedef struct {
const rtems_filesystem_file_handlers_r *handlers;
- size_t node_size;
IMFS_node_control_initialize node_initialize;
IMFS_node_control_remove node_remove;
IMFS_node_control_destroy node_destroy;
} IMFS_node_control;
+typedef struct {
+ IMFS_node_control node_control;
+ size_t node_size;
+} IMFS_mknod_control;
+
/** @} */
/**
@@ -371,19 +375,19 @@ static inline void IMFS_mtime_ctime_update( IMFS_jnode_t *jnode )
}
typedef struct {
- const IMFS_node_control *node_controls [IMFS_TYPE_COUNT];
+ const IMFS_mknod_control *mknod_controls[ IMFS_TYPE_COUNT ];
} IMFS_fs_info_t;
/*
* Shared Data
*/
-extern const IMFS_node_control IMFS_node_control_directory;
-extern const IMFS_node_control IMFS_node_control_device;
-extern const IMFS_node_control IMFS_node_control_memfile;
+extern const IMFS_mknod_control IMFS_mknod_control_directory;
+extern const IMFS_mknod_control IMFS_mknod_control_device;
+extern const IMFS_mknod_control IMFS_mknod_control_memfile;
extern const IMFS_node_control IMFS_node_control_linfile;
-extern const IMFS_node_control IMFS_node_control_fifo;
-extern const IMFS_node_control IMFS_node_control_enosys;
+extern const IMFS_mknod_control IMFS_mknod_control_fifo;
+extern const IMFS_mknod_control IMFS_mknod_control_enosys;
extern const rtems_filesystem_operations_table miniIMFS_ops;
extern const rtems_filesystem_operations_table IMFS_ops;
@@ -416,7 +420,7 @@ extern int miniIMFS_initialize(
extern int IMFS_initialize_support(
rtems_filesystem_mount_table_entry_t *mt_entry,
const rtems_filesystem_operations_table *op_table,
- const IMFS_node_control *const node_controls [IMFS_TYPE_COUNT]
+ const IMFS_mknod_control *const mknod_controls[ IMFS_TYPE_COUNT ]
);
/**
* @brief Unmount this instance of IMFS.
@@ -559,8 +563,8 @@ extern int IMFS_mknod(
* Routine to create a new in memory file system node.
*/
extern IMFS_jnode_t *IMFS_allocate_node(
- IMFS_fs_info_t *fs_info,
const IMFS_node_control *node_control,
+ size_t node_size,
const char *name,
size_t namelen,
mode_t mode,
@@ -576,6 +580,7 @@ extern IMFS_jnode_t *IMFS_allocate_node(
extern IMFS_jnode_t *IMFS_create_node(
const rtems_filesystem_location_info_t *parentloc,
const IMFS_node_control *node_control,
+ size_t node_size,
const char *name,
size_t namelen,
mode_t mode,
@@ -614,7 +619,6 @@ extern bool IMFS_is_imfs_instance(
#define IMFS_GENERIC_INITIALIZER( handlers, init, destroy ) \
{ \
( handlers ), \
- sizeof( IMFS_generic_t ), \
( init ), \
IMFS_node_remove_default, \
( destroy ) \
diff --git a/cpukit/libfs/src/imfs/imfs_creat.c b/cpukit/libfs/src/imfs/imfs_creat.c
index 7d60e66..c0fc2e1 100644
--- a/cpukit/libfs/src/imfs/imfs_creat.c
+++ b/cpukit/libfs/src/imfs/imfs_creat.c
@@ -23,8 +23,8 @@
#include <string.h>
IMFS_jnode_t *IMFS_allocate_node(
- IMFS_fs_info_t *fs_info,
const IMFS_node_control *node_control,
+ size_t node_size,
const char *name,
size_t namelen,
mode_t mode,
@@ -46,7 +46,7 @@ IMFS_jnode_t *IMFS_allocate_node(
/*
* Allocate an IMFS jnode
*/
- node = calloc( 1, node_control->node_size );
+ node = calloc( 1, node_size );
if ( !node ) {
errno = ENOMEM;
@@ -88,16 +88,16 @@ IMFS_jnode_t *IMFS_allocate_node(
IMFS_jnode_t *IMFS_create_node(
const rtems_filesystem_location_info_t *parentloc,
const IMFS_node_control *node_control,
+ size_t node_size,
const char *name,
size_t namelen,
mode_t mode,
void *arg
)
{
- IMFS_fs_info_t *fs_info = parentloc->mt_entry->fs_info;
IMFS_jnode_t *node = IMFS_allocate_node(
- fs_info,
node_control,
+ node_size,
name,
namelen,
mode,
diff --git a/cpukit/libfs/src/imfs/imfs_fifo.c b/cpukit/libfs/src/imfs/imfs_fifo.c
index 36eab85..d84429d 100644
--- a/cpukit/libfs/src/imfs/imfs_fifo.c
+++ b/cpukit/libfs/src/imfs/imfs_fifo.c
@@ -130,10 +130,12 @@ static const rtems_filesystem_file_handlers_r IMFS_fifo_handlers = {
.writev_h = rtems_filesystem_default_writev
};
-const IMFS_node_control IMFS_node_control_fifo = {
- .handlers = &IMFS_fifo_handlers,
- .node_size = sizeof(IMFS_fifo_t),
- .node_initialize = IMFS_node_initialize_default,
- .node_remove = IMFS_node_remove_default,
- .node_destroy = IMFS_node_destroy_default
+const IMFS_mknod_control IMFS_mknod_control_fifo = {
+ {
+ .handlers = &IMFS_fifo_handlers,
+ .node_initialize = IMFS_node_initialize_default,
+ .node_remove = IMFS_node_remove_default,
+ .node_destroy = IMFS_node_destroy_default
+ },
+ .node_size = sizeof( IMFS_fifo_t )
};
diff --git a/cpukit/libfs/src/imfs/imfs_handlers_device.c b/cpukit/libfs/src/imfs/imfs_handlers_device.c
index f27511e..0a7cb5f 100644
--- a/cpukit/libfs/src/imfs/imfs_handlers_device.c
+++ b/cpukit/libfs/src/imfs/imfs_handlers_device.c
@@ -63,10 +63,12 @@ static IMFS_jnode_t *IMFS_node_initialize_device(
return node;
}
-const IMFS_node_control IMFS_node_control_device = {
- .handlers = &IMFS_device_handlers,
- .node_size = sizeof(IMFS_device_t),
- .node_initialize = IMFS_node_initialize_device,
- .node_remove = IMFS_node_remove_default,
- .node_destroy = IMFS_node_destroy_default
+const IMFS_mknod_control IMFS_mknod_control_device = {
+ {
+ .handlers = &IMFS_device_handlers,
+ .node_initialize = IMFS_node_initialize_device,
+ .node_remove = IMFS_node_remove_default,
+ .node_destroy = IMFS_node_destroy_default
+ },
+ .node_size = sizeof( IMFS_device_t )
};
diff --git a/cpukit/libfs/src/imfs/imfs_handlers_directory.c b/cpukit/libfs/src/imfs/imfs_handlers_directory.c
index 1be399b..bcfe3e7 100644
--- a/cpukit/libfs/src/imfs/imfs_handlers_directory.c
+++ b/cpukit/libfs/src/imfs/imfs_handlers_directory.c
@@ -102,10 +102,12 @@ static IMFS_jnode_t *IMFS_node_remove_directory(
return &dir->Node;
}
-const IMFS_node_control IMFS_node_control_directory = {
- .handlers = &IMFS_directory_handlers,
- .node_size = sizeof(IMFS_directory_t),
- .node_initialize = IMFS_node_initialize_directory,
- .node_remove = IMFS_node_remove_directory,
- .node_destroy = IMFS_node_destroy_default
+const IMFS_mknod_control IMFS_mknod_control_directory = {
+ {
+ .handlers = &IMFS_directory_handlers,
+ .node_initialize = IMFS_node_initialize_directory,
+ .node_remove = IMFS_node_remove_directory,
+ .node_destroy = IMFS_node_destroy_default
+ },
+ .node_size = sizeof( IMFS_directory_t )
};
diff --git a/cpukit/libfs/src/imfs/imfs_handlers_memfile.c b/cpukit/libfs/src/imfs/imfs_handlers_memfile.c
index db682bb..1e5dba2 100644
--- a/cpukit/libfs/src/imfs/imfs_handlers_memfile.c
+++ b/cpukit/libfs/src/imfs/imfs_handlers_memfile.c
@@ -69,17 +69,18 @@ static const rtems_filesystem_file_handlers_r IMFS_linfile_handlers = {
.writev_h = rtems_filesystem_default_writev
};
-const IMFS_node_control IMFS_node_control_memfile = {
- .handlers = &IMFS_memfile_handlers,
- .node_size = sizeof(IMFS_file_t),
- .node_initialize = IMFS_node_initialize_default,
- .node_remove = IMFS_node_remove_default,
- .node_destroy = IMFS_memfile_remove
+const IMFS_mknod_control IMFS_mknod_control_memfile = {
+ {
+ .handlers = &IMFS_memfile_handlers,
+ .node_initialize = IMFS_node_initialize_default,
+ .node_remove = IMFS_node_remove_default,
+ .node_destroy = IMFS_memfile_remove
+ },
+ .node_size = sizeof( IMFS_file_t )
};
const IMFS_node_control IMFS_node_control_linfile = {
.handlers = &IMFS_linfile_handlers,
- .node_size = sizeof(IMFS_file_t),
.node_initialize = IMFS_node_initialize_default,
.node_remove = IMFS_node_remove_default,
.node_destroy = IMFS_node_destroy_default
diff --git a/cpukit/libfs/src/imfs/imfs_init.c b/cpukit/libfs/src/imfs/imfs_init.c
index 5e29880..854363c 100644
--- a/cpukit/libfs/src/imfs/imfs_init.c
+++ b/cpukit/libfs/src/imfs/imfs_init.c
@@ -43,12 +43,12 @@ const rtems_filesystem_operations_table IMFS_ops = {
.statvfs_h = rtems_filesystem_default_statvfs
};
-static const IMFS_node_control *const
- IMFS_node_controls [IMFS_TYPE_COUNT] = {
- [IMFS_DIRECTORY] = &IMFS_node_control_directory,
- [IMFS_DEVICE] = &IMFS_node_control_device,
- [IMFS_MEMORY_FILE] = &IMFS_node_control_memfile,
- [IMFS_FIFO] = &IMFS_node_control_enosys
+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
};
int IMFS_initialize(
@@ -59,6 +59,6 @@ int IMFS_initialize(
return IMFS_initialize_support(
mt_entry,
&IMFS_ops,
- IMFS_node_controls
+ IMFS_mknod_controls
);
}
diff --git a/cpukit/libfs/src/imfs/imfs_initsupp.c b/cpukit/libfs/src/imfs/imfs_initsupp.c
index 563d620..9881d84 100644
--- a/cpukit/libfs/src/imfs/imfs_initsupp.c
+++ b/cpukit/libfs/src/imfs/imfs_initsupp.c
@@ -58,7 +58,7 @@ static int IMFS_determine_bytes_per_block(
int IMFS_initialize_support(
rtems_filesystem_mount_table_entry_t *mt_entry,
const rtems_filesystem_operations_table *op_table,
- const IMFS_node_control *const node_controls [IMFS_TYPE_COUNT]
+ const IMFS_mknod_control *const mknod_controls[ IMFS_TYPE_COUNT ]
)
{
int rv = 0;
@@ -68,14 +68,14 @@ int IMFS_initialize_support(
IMFS_jnode_t *root_node;
memcpy(
- fs_info->node_controls,
- node_controls,
- sizeof( fs_info->node_controls )
+ fs_info->mknod_controls,
+ mknod_controls,
+ sizeof( fs_info->mknod_controls )
);
root_node = IMFS_allocate_node(
- fs_info,
- fs_info->node_controls [IMFS_DIRECTORY],
+ &fs_info->mknod_controls[ IMFS_DIRECTORY ]->node_control,
+ fs_info->mknod_controls[ IMFS_DIRECTORY ]->node_size,
"",
0,
(S_IFDIR | 0755),
@@ -165,10 +165,12 @@ void IMFS_node_destroy_default( IMFS_jnode_t *node )
free( node );
}
-const IMFS_node_control IMFS_node_control_enosys = {
- .handlers = &rtems_filesystem_handlers_default,
- .node_size = sizeof(IMFS_jnode_t),
- .node_initialize = IMFS_node_initialize_enosys,
- .node_remove = IMFS_node_remove_default,
- .node_destroy = IMFS_node_destroy_default
+const IMFS_mknod_control IMFS_mknod_control_enosys = {
+ {
+ .handlers = &rtems_filesystem_handlers_default,
+ .node_initialize = IMFS_node_initialize_enosys,
+ .node_remove = IMFS_node_remove_default,
+ .node_destroy = IMFS_node_destroy_default
+ },
+ .node_size = sizeof( IMFS_jnode_t )
};
diff --git a/cpukit/libfs/src/imfs/imfs_link.c b/cpukit/libfs/src/imfs/imfs_link.c
index de4701a..27e04ff 100644
--- a/cpukit/libfs/src/imfs/imfs_link.c
+++ b/cpukit/libfs/src/imfs/imfs_link.c
@@ -46,6 +46,7 @@ int IMFS_link(
new_node = IMFS_create_node(
parentloc,
&IMFS_node_control_hard_link,
+ sizeof( IMFS_link_t ),
name,
namelen,
IMFS_STAT_FMT_HARD_LINK | ( S_IRWXU | S_IRWXG | S_IRWXO ),
@@ -133,7 +134,6 @@ static IMFS_jnode_t *IMFS_node_remove_hard_link(
static const IMFS_node_control IMFS_node_control_hard_link = {
.handlers = &IMFS_link_handlers,
- .node_size = sizeof(IMFS_link_t),
.node_initialize = IMFS_node_initialize_hard_link,
.node_remove = IMFS_node_remove_hard_link,
.node_destroy = IMFS_node_destroy_default
diff --git a/cpukit/libfs/src/imfs/imfs_load_tar.c b/cpukit/libfs/src/imfs/imfs_load_tar.c
index e6dc499..d303cd2 100644
--- a/cpukit/libfs/src/imfs/imfs_load_tar.c
+++ b/cpukit/libfs/src/imfs/imfs_load_tar.c
@@ -126,6 +126,7 @@ int rtems_tarfs_load(
IMFS_create_node(
currentloc,
&IMFS_node_control_linfile,
+ sizeof( IMFS_file_t ),
rtems_filesystem_eval_path_get_token( &ctx ),
rtems_filesystem_eval_path_get_tokenlen( &ctx ),
(file_mode & (S_IRWXU | S_IRWXG | S_IRWXO)) | S_IFREG,
diff --git a/cpukit/libfs/src/imfs/imfs_make_generic_node.c b/cpukit/libfs/src/imfs/imfs_make_generic_node.c
index aeb82b4..f302dda 100644
--- a/cpukit/libfs/src/imfs/imfs_make_generic_node.c
+++ b/cpukit/libfs/src/imfs/imfs_make_generic_node.c
@@ -85,6 +85,7 @@ int IMFS_make_generic_node(
IMFS_jnode_t *new_node = IMFS_create_node(
currentloc,
node_control,
+ sizeof( IMFS_generic_t ),
rtems_filesystem_eval_path_get_token( &ctx ),
rtems_filesystem_eval_path_get_tokenlen( &ctx ),
mode,
diff --git a/cpukit/libfs/src/imfs/imfs_mknod.c b/cpukit/libfs/src/imfs/imfs_mknod.c
index 6ff505c..ed67192 100644
--- a/cpukit/libfs/src/imfs/imfs_mknod.c
+++ b/cpukit/libfs/src/imfs/imfs_mknod.c
@@ -47,11 +47,14 @@ 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 ) ];
IMFS_jnode_t *new_node;
new_node = IMFS_create_node(
parentloc,
- fs_info->node_controls[ get_type( mode ) ],
+ &mknod_control->node_control,
+ mknod_control->node_size,
name,
namelen,
mode,
diff --git a/cpukit/libfs/src/imfs/imfs_symlink.c b/cpukit/libfs/src/imfs/imfs_symlink.c
index 3ecff3b..2ddf99c 100644
--- a/cpukit/libfs/src/imfs/imfs_symlink.c
+++ b/cpukit/libfs/src/imfs/imfs_symlink.c
@@ -49,6 +49,7 @@ int IMFS_symlink(
new_node = IMFS_create_node(
parentloc,
&IMFS_node_control_sym_link,
+ sizeof( IMFS_sym_link_t ),
name,
namelen,
( S_IFLNK | ( S_IRWXU | S_IRWXG | S_IRWXO )),
@@ -133,7 +134,6 @@ static void IMFS_node_destroy_sym_link( IMFS_jnode_t *node )
static const IMFS_node_control IMFS_node_control_sym_link = {
.handlers = &IMFS_link_handlers,
- .node_size = sizeof(IMFS_sym_link_t),
.node_initialize = IMFS_node_initialize_sym_link,
.node_remove = IMFS_node_remove_default,
.node_destroy = IMFS_node_destroy_sym_link
diff --git a/cpukit/libfs/src/imfs/memfile.c b/cpukit/libfs/src/imfs/memfile.c
index 563001a..59da9a6 100644
--- a/cpukit/libfs/src/imfs/memfile.c
+++ b/cpukit/libfs/src/imfs/memfile.c
@@ -88,7 +88,7 @@ int IMFS_linfile_open(
uint32_t count = file->File.size;
const unsigned char *buffer = file->Linearfile.direct;
- file->Node.control = &IMFS_node_control_memfile;
+ file->Node.control = &IMFS_mknod_control_memfile.node_control;
file->File.size = 0;
file->Memfile.indirect = 0;
file->Memfile.doubly_indirect = 0;
diff --git a/cpukit/libfs/src/imfs/miniimfs_init.c b/cpukit/libfs/src/imfs/miniimfs_init.c
index 6097f72..87879fc 100644
--- a/cpukit/libfs/src/imfs/miniimfs_init.c
+++ b/cpukit/libfs/src/imfs/miniimfs_init.c
@@ -43,12 +43,12 @@ const rtems_filesystem_operations_table miniIMFS_ops = {
.statvfs_h = rtems_filesystem_default_statvfs
};
-static const IMFS_node_control *const
- IMFS_mini_node_controls [IMFS_TYPE_COUNT] = {
- [IMFS_DIRECTORY] = &IMFS_node_control_directory,
- [IMFS_DEVICE] = &IMFS_node_control_device,
- [IMFS_MEMORY_FILE] = &IMFS_node_control_memfile,
- [IMFS_FIFO] = &IMFS_node_control_enosys
+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
};
int miniIMFS_initialize(
@@ -59,6 +59,6 @@ int miniIMFS_initialize(
return IMFS_initialize_support(
mt_entry,
&miniIMFS_ops,
- IMFS_mini_node_controls
+ IMFS_mini_mknod_controls
);
}
diff --git a/testsuites/fstests/fsimfsgeneric01/init.c b/testsuites/fstests/fsimfsgeneric01/init.c
index 671ad14..44d75c5 100644
--- a/testsuites/fstests/fsimfsgeneric01/init.c
+++ b/testsuites/fstests/fsimfsgeneric01/init.c
@@ -298,7 +298,6 @@ static void node_destroy(IMFS_jnode_t *node)
static const IMFS_node_control node_control = {
.handlers = &node_handlers,
- .node_size = sizeof(IMFS_generic_t),
.node_initialize = node_initialize,
.node_remove = node_remove,
.node_destroy = node_destroy
@@ -392,7 +391,6 @@ static void node_destroy_inhibited(IMFS_jnode_t *node)
static const IMFS_node_control node_initialization_error_control = {
.handlers = &node_handlers,
- .node_size = sizeof(IMFS_generic_t),
.node_initialize = node_initialize_error,
.node_remove = node_remove_inhibited,
.node_destroy = node_destroy_inhibited
--
2.1.4
More information about the devel
mailing list