summaryrefslogtreecommitdiffstats
path: root/cpukit/libfs/src/imfs
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2019-11-18 06:55:43 +0100
committerSebastian Huber <sebastian.huber@embedded-brains.de>2019-11-19 16:22:00 +0100
commitf3779985681baaa4ac4e33dddfabab241008376c (patch)
tree2758bb25741f90b3cd5d9266b0021a40aaf8b659 /cpukit/libfs/src/imfs
parentMove feature macro before "config.h" include (diff)
downloadrtems-f3779985681baaa4ac4e33dddfabab241008376c.tar.bz2
imfs: Add IMFS_make_linfile()
Update #3818.
Diffstat (limited to 'cpukit/libfs/src/imfs')
-rw-r--r--cpukit/libfs/src/imfs/imfs_linfile.c18
-rw-r--r--cpukit/libfs/src/imfs/imfs_load_tar.c29
-rw-r--r--cpukit/libfs/src/imfs/imfs_make_generic_node.c25
-rw-r--r--cpukit/libfs/src/imfs/imfs_make_linfile.c53
4 files changed, 105 insertions, 20 deletions
diff --git a/cpukit/libfs/src/imfs/imfs_linfile.c b/cpukit/libfs/src/imfs/imfs_linfile.c
index f53930d4b0..2044cc66fc 100644
--- a/cpukit/libfs/src/imfs/imfs_linfile.c
+++ b/cpukit/libfs/src/imfs/imfs_linfile.c
@@ -95,9 +95,25 @@ static const rtems_filesystem_file_handlers_r IMFS_linfile_handlers = {
.writev_h = rtems_filesystem_default_writev
};
+static IMFS_jnode_t *IMFS_node_initialize_linfile(
+ IMFS_jnode_t *node,
+ void *arg
+)
+{
+ IMFS_linearfile_t *linfile;
+ IMFS_linearfile_context *ctx;
+
+ linfile = (IMFS_linearfile_t *) node;
+ ctx = arg;
+ linfile->File.size = ctx->size;
+ linfile->direct = RTEMS_DECONST( void *, ctx->data );
+
+ return node;
+}
+
const IMFS_node_control IMFS_node_control_linfile = {
.handlers = &IMFS_linfile_handlers,
- .node_initialize = IMFS_node_initialize_default,
+ .node_initialize = IMFS_node_initialize_linfile,
.node_remove = IMFS_node_remove_default,
.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 e83553866a..6298a3f32d 100644
--- a/cpukit/libfs/src/imfs/imfs_load_tar.c
+++ b/cpukit/libfs/src/imfs/imfs_load_tar.c
@@ -135,21 +135,20 @@ int rtems_tarfs_load(
rtems_filesystem_eval_path_continue( &ctx );
if ( !rtems_filesystem_location_is_null( currentloc ) ) {
- IMFS_linearfile_t *linfile = (IMFS_linearfile_t *)
- 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,
- NULL
- );
-
- if ( linfile != NULL ) {
- linfile->File.size = file_size;
- linfile->direct = &tar_image[offset];
- }
+ IMFS_linearfile_context linctx = {
+ .data = &tar_image[offset],
+ .size = file_size
+ };
+
+ 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,
+ &linctx
+ );
}
nblocks = (((file_size) + 511) & ~511) / 512;
diff --git a/cpukit/libfs/src/imfs/imfs_make_generic_node.c b/cpukit/libfs/src/imfs/imfs_make_generic_node.c
index ce610e5eca..27ef618d0b 100644
--- a/cpukit/libfs/src/imfs/imfs_make_generic_node.c
+++ b/cpukit/libfs/src/imfs/imfs_make_generic_node.c
@@ -40,10 +40,27 @@ IMFS_jnode_t *IMFS_node_initialize_generic(
}
int IMFS_make_generic_node(
- const char *path,
- mode_t mode,
+ const char *path,
+ mode_t mode,
const IMFS_node_control *node_control,
- void *context
+ void *context
+)
+{
+ return IMFS_make_node(
+ path,
+ mode,
+ node_control,
+ sizeof( IMFS_generic_t ),
+ context
+ );
+}
+
+int IMFS_make_node(
+ const char *path,
+ mode_t mode,
+ const IMFS_node_control *node_control,
+ size_t node_size,
+ void *context
)
{
int rv = 0;
@@ -75,7 +92,7 @@ int IMFS_make_generic_node(
IMFS_jnode_t *new_node = IMFS_create_node(
currentloc,
node_control,
- sizeof( IMFS_generic_t ),
+ node_size,
rtems_filesystem_eval_path_get_token( &ctx ),
rtems_filesystem_eval_path_get_tokenlen( &ctx ),
mode,
diff --git a/cpukit/libfs/src/imfs/imfs_make_linfile.c b/cpukit/libfs/src/imfs/imfs_make_linfile.c
new file mode 100644
index 0000000000..d5f1d0e21f
--- /dev/null
+++ b/cpukit/libfs/src/imfs/imfs_make_linfile.c
@@ -0,0 +1,53 @@
+/*
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (C) 2019 embedded brains GmbH
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/imfs.h>
+
+int IMFS_make_linearfile(
+ const char *path,
+ mode_t mode,
+ const char *data,
+ size_t size
+)
+{
+ IMFS_linearfile_context ctx = {
+ .data = data,
+ .size = size
+ };
+
+ return IMFS_make_node(
+ path,
+ ( mode & ~S_IFMT ) | S_IFREG,
+ &IMFS_node_control_linfile,
+ sizeof( IMFS_linearfile_t ),
+ &ctx
+ );
+}