forked from Imagelibrary/rtems
@@ -428,6 +428,7 @@ librtemscpu_a_SOURCES += libfs/src/imfs/imfs_linfile.c
|
|||||||
librtemscpu_a_SOURCES += libfs/src/imfs/imfs_link.c
|
librtemscpu_a_SOURCES += libfs/src/imfs/imfs_link.c
|
||||||
librtemscpu_a_SOURCES += libfs/src/imfs/imfs_load_tar.c
|
librtemscpu_a_SOURCES += libfs/src/imfs/imfs_load_tar.c
|
||||||
librtemscpu_a_SOURCES += libfs/src/imfs/imfs_make_generic_node.c
|
librtemscpu_a_SOURCES += libfs/src/imfs/imfs_make_generic_node.c
|
||||||
|
librtemscpu_a_SOURCES += libfs/src/imfs/imfs_make_linfile.c
|
||||||
librtemscpu_a_SOURCES += libfs/src/imfs/imfs_memfile.c
|
librtemscpu_a_SOURCES += libfs/src/imfs/imfs_memfile.c
|
||||||
librtemscpu_a_SOURCES += libfs/src/imfs/imfs_mknod.c
|
librtemscpu_a_SOURCES += libfs/src/imfs/imfs_mknod.c
|
||||||
librtemscpu_a_SOURCES += libfs/src/imfs/imfs_mount.c
|
librtemscpu_a_SOURCES += libfs/src/imfs/imfs_mount.c
|
||||||
|
|||||||
@@ -317,6 +317,11 @@ typedef struct {
|
|||||||
void *context;
|
void *context;
|
||||||
} IMFS_generic_t;
|
} IMFS_generic_t;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
const void *data;
|
||||||
|
size_t size;
|
||||||
|
} IMFS_linearfile_context;
|
||||||
|
|
||||||
static inline IMFS_directory_t *IMFS_iop_to_directory(
|
static inline IMFS_directory_t *IMFS_iop_to_directory(
|
||||||
const rtems_libio_t *iop
|
const rtems_libio_t *iop
|
||||||
)
|
)
|
||||||
@@ -592,6 +597,32 @@ static inline bool IMFS_is_imfs_instance(
|
|||||||
return loc->mt_entry->ops->clonenod_h == IMFS_node_clone;
|
return loc->mt_entry->ops->clonenod_h == IMFS_node_clone;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern int IMFS_make_node(
|
||||||
|
const char *path,
|
||||||
|
mode_t mode,
|
||||||
|
const IMFS_node_control *node_control,
|
||||||
|
size_t node_size,
|
||||||
|
void *context
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Makes a linear IMFS file.
|
||||||
|
*
|
||||||
|
* @param path The path to the new linear IMFS file.
|
||||||
|
* @param mode The file mode permissions. S_IFREG is set by the function.
|
||||||
|
* @param data The begin of linear file data area.
|
||||||
|
* @param size The size of the linear file data area in bytes.
|
||||||
|
*
|
||||||
|
* @retval 0 Successful operation.
|
||||||
|
* @retval -1 An error occurred. The @c errno indicates the error.
|
||||||
|
*/
|
||||||
|
extern int IMFS_make_linearfile(
|
||||||
|
const char *path,
|
||||||
|
mode_t mode,
|
||||||
|
const char *data,
|
||||||
|
size_t size
|
||||||
|
);
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -95,9 +95,25 @@ static const rtems_filesystem_file_handlers_r IMFS_linfile_handlers = {
|
|||||||
.writev_h = rtems_filesystem_default_writev
|
.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 = {
|
const IMFS_node_control IMFS_node_control_linfile = {
|
||||||
.handlers = &IMFS_linfile_handlers,
|
.handlers = &IMFS_linfile_handlers,
|
||||||
.node_initialize = IMFS_node_initialize_default,
|
.node_initialize = IMFS_node_initialize_linfile,
|
||||||
.node_remove = IMFS_node_remove_default,
|
.node_remove = IMFS_node_remove_default,
|
||||||
.node_destroy = IMFS_node_destroy_default
|
.node_destroy = IMFS_node_destroy_default
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -135,21 +135,20 @@ int rtems_tarfs_load(
|
|||||||
rtems_filesystem_eval_path_continue( &ctx );
|
rtems_filesystem_eval_path_continue( &ctx );
|
||||||
|
|
||||||
if ( !rtems_filesystem_location_is_null( currentloc ) ) {
|
if ( !rtems_filesystem_location_is_null( currentloc ) ) {
|
||||||
IMFS_linearfile_t *linfile = (IMFS_linearfile_t *)
|
IMFS_linearfile_context linctx = {
|
||||||
IMFS_create_node(
|
.data = &tar_image[offset],
|
||||||
currentloc,
|
.size = file_size
|
||||||
&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 ) {
|
IMFS_create_node(
|
||||||
linfile->File.size = file_size;
|
currentloc,
|
||||||
linfile->direct = &tar_image[offset];
|
&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;
|
nblocks = (((file_size) + 511) & ~511) / 512;
|
||||||
|
|||||||
@@ -40,10 +40,27 @@ IMFS_jnode_t *IMFS_node_initialize_generic(
|
|||||||
}
|
}
|
||||||
|
|
||||||
int IMFS_make_generic_node(
|
int IMFS_make_generic_node(
|
||||||
const char *path,
|
const char *path,
|
||||||
mode_t mode,
|
mode_t mode,
|
||||||
const IMFS_node_control *node_control,
|
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;
|
int rv = 0;
|
||||||
@@ -75,7 +92,7 @@ int IMFS_make_generic_node(
|
|||||||
IMFS_jnode_t *new_node = IMFS_create_node(
|
IMFS_jnode_t *new_node = IMFS_create_node(
|
||||||
currentloc,
|
currentloc,
|
||||||
node_control,
|
node_control,
|
||||||
sizeof( IMFS_generic_t ),
|
node_size,
|
||||||
rtems_filesystem_eval_path_get_token( &ctx ),
|
rtems_filesystem_eval_path_get_token( &ctx ),
|
||||||
rtems_filesystem_eval_path_get_tokenlen( &ctx ),
|
rtems_filesystem_eval_path_get_tokenlen( &ctx ),
|
||||||
mode,
|
mode,
|
||||||
|
|||||||
53
cpukit/libfs/src/imfs/imfs_make_linfile.c
Normal file
53
cpukit/libfs/src/imfs/imfs_make_linfile.c
Normal 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
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2014 embedded brains GmbH. All rights reserved.
|
* Copyright (c) 2014, 2019 embedded brains GmbH. All rights reserved.
|
||||||
*
|
*
|
||||||
* embedded brains GmbH
|
* embedded brains GmbH
|
||||||
* Dornierstr. 4
|
* Dornierstr. 4
|
||||||
@@ -24,6 +24,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include <rtems/imfs.h>
|
||||||
#include <rtems/shell.h>
|
#include <rtems/shell.h>
|
||||||
#include <rtems/userenv.h>
|
#include <rtems/userenv.h>
|
||||||
|
|
||||||
@@ -31,20 +32,23 @@
|
|||||||
|
|
||||||
const char rtems_test_name[] = "SHELL 1";
|
const char rtems_test_name[] = "SHELL 1";
|
||||||
|
|
||||||
static void create_file(const char *name, const char *content)
|
static const char etc_passwd[] =
|
||||||
{
|
"moop:foo:1:3:blob:a::c\n"
|
||||||
FILE *fp;
|
"no:*:2:4::::\n"
|
||||||
int rv;
|
"zero::3:5::::\n"
|
||||||
|
"shadow:x:4:6::::\n"
|
||||||
|
"invchroot::5:7:::/inv:\n"
|
||||||
|
"chroot::6:8:::/chroot:\n";
|
||||||
|
|
||||||
fp = fopen(name, "wx");
|
static const char etc_group[] =
|
||||||
rtems_test_assert(fp != NULL);
|
"A::1:moop,u,v,w,zero\n"
|
||||||
|
"B::2:moop\n"
|
||||||
rv = fputs(content, fp);
|
"blub:bar:3:moop\n"
|
||||||
rtems_test_assert(rv == 0);
|
"C::4:l,m,n,moop\n"
|
||||||
|
"D::5:moop,moop\n"
|
||||||
rv = fclose(fp);
|
"E::6:x\n"
|
||||||
rtems_test_assert(rv == 0);
|
"E::7:y,z\n"
|
||||||
}
|
"F::8:s,moop,t\n";
|
||||||
|
|
||||||
static void test(void)
|
static void test(void)
|
||||||
{
|
{
|
||||||
@@ -64,27 +68,21 @@ static void test(void)
|
|||||||
rv = lstat("/chroot", &st_chroot);
|
rv = lstat("/chroot", &st_chroot);
|
||||||
rtems_test_assert(rv == 0);
|
rtems_test_assert(rv == 0);
|
||||||
|
|
||||||
create_file(
|
rv = IMFS_make_linearfile(
|
||||||
"/etc/passwd",
|
"/etc/passwd",
|
||||||
"moop:foo:1:3:blob:a::c\n"
|
S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH,
|
||||||
"no:*:2:4::::\n"
|
etc_passwd,
|
||||||
"zero::3:5::::\n"
|
sizeof(etc_passwd)
|
||||||
"shadow:x:4:6::::\n"
|
|
||||||
"invchroot::5:7:::/inv:\n"
|
|
||||||
"chroot::6:8:::/chroot:\n"
|
|
||||||
);
|
);
|
||||||
|
rtems_test_assert(rv == 0);
|
||||||
|
|
||||||
create_file(
|
rv = IMFS_make_linearfile(
|
||||||
"/etc/group",
|
"/etc/group",
|
||||||
"A::1:moop,u,v,w,zero\n"
|
S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH,
|
||||||
"B::2:moop\n"
|
etc_group,
|
||||||
"blub:bar:3:moop\n"
|
sizeof(etc_group)
|
||||||
"C::4:l,m,n,moop\n"
|
|
||||||
"D::5:moop,moop\n"
|
|
||||||
"E::6:x\n"
|
|
||||||
"E::7:y,z\n"
|
|
||||||
"F::8:s,moop,t\n"
|
|
||||||
);
|
);
|
||||||
|
rtems_test_assert(rv == 0);
|
||||||
|
|
||||||
sc = rtems_libio_set_private_env();
|
sc = rtems_libio_set_private_env();
|
||||||
rtems_test_assert(sc == RTEMS_SUCCESSFUL);
|
rtems_test_assert(sc == RTEMS_SUCCESSFUL);
|
||||||
|
|||||||
Reference in New Issue
Block a user