imfs: Add IMFS_make_linfile()

Update #3818.
This commit is contained in:
Sebastian Huber
2019-11-18 06:55:43 +01:00
parent 38207a31e4
commit f377998568
7 changed files with 164 additions and 49 deletions

View File

@@ -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
};

View File

@@ -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
);
IMFS_linearfile_context linctx = {
.data = &tar_image[offset],
.size = file_size
};
if ( linfile != NULL ) {
linfile->File.size = file_size;
linfile->direct = &tar_image[offset];
}
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;

View File

@@ -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,

View File

@@ -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
);
}