imfs: Replace devfs with an IMFS specialization

Add a simplified path evaluation function IMFS_eval_path_devfs() for a
device only IMFS configuration.

The code size can be further reduced by the application if it disables
the support for legacy IO drivers via:

  #define CONFIGURE_IMFS_DISABLE_MKNOD
  #define CONFIGURE_IMFS_DISABLE_MKNOD_DEVICE

Obsolete CONFIGURE_MAXIMUM_DEVICES.  Remove BSP_MAXIMUM_DEVICES.

Update #3894.
Update #3898.
This commit is contained in:
Sebastian Huber
2020-03-03 19:23:53 +01:00
parent 103a371faa
commit 0161b93d50
32 changed files with 245 additions and 1148 deletions

View File

@@ -239,8 +239,6 @@ void i386_stub_glue_init_breakin(void);
int i386_stub_glue_uart(void); int i386_stub_glue_uart(void);
void breakpoint(void); void breakpoint(void);
#define BSP_MAXIMUM_DEVICES 6
/* /*
* Debug helper methods * Debug helper methods
*/ */

View File

@@ -69,9 +69,6 @@ extern "C" {
/* Maximum supported APBUARTs by BSP */ /* Maximum supported APBUARTs by BSP */
#define BSP_NUMBER_OF_TERMIOS_PORTS 8 #define BSP_NUMBER_OF_TERMIOS_PORTS 8
/* Make sure maximum number of consoles fit in filesystem */
#define BSP_MAXIMUM_DEVICES 8
/* GRLIB driver functions */ /* GRLIB driver functions */
extern void BSP_shared_interrupt_mask(int irq); extern void BSP_shared_interrupt_mask(int irq);

View File

@@ -61,9 +61,6 @@ void *bsp_idle_thread( uintptr_t ignored );
/* Maximum supported APBUARTs by BSP */ /* Maximum supported APBUARTs by BSP */
#define BSP_NUMBER_OF_TERMIOS_PORTS 8 #define BSP_NUMBER_OF_TERMIOS_PORTS 8
/* Make sure maximum number of consoles fit in filesystem */
#define BSP_MAXIMUM_DEVICES 8
/* /*
* Network driver configuration * Network driver configuration
*/ */

View File

@@ -380,16 +380,6 @@ librtemscpu_a_SOURCES += libfs/src/defaults/default_unmount.c
librtemscpu_a_SOURCES += libfs/src/defaults/default_utime.c librtemscpu_a_SOURCES += libfs/src/defaults/default_utime.c
librtemscpu_a_SOURCES += libfs/src/defaults/default_write.c librtemscpu_a_SOURCES += libfs/src/defaults/default_write.c
librtemscpu_a_SOURCES += libfs/src/defaults/default_writev.c librtemscpu_a_SOURCES += libfs/src/defaults/default_writev.c
librtemscpu_a_SOURCES += libfs/src/devfs/devclose.c
librtemscpu_a_SOURCES += libfs/src/devfs/devfs_eval.c
librtemscpu_a_SOURCES += libfs/src/devfs/devfs_init.c
librtemscpu_a_SOURCES += libfs/src/devfs/devfs_mknod.c
librtemscpu_a_SOURCES += libfs/src/devfs/devfs_show.c
librtemscpu_a_SOURCES += libfs/src/devfs/devioctl.c
librtemscpu_a_SOURCES += libfs/src/devfs/devopen.c
librtemscpu_a_SOURCES += libfs/src/devfs/devread.c
librtemscpu_a_SOURCES += libfs/src/devfs/devstat.c
librtemscpu_a_SOURCES += libfs/src/devfs/devwrite.c
librtemscpu_a_SOURCES += libfs/src/dosfs/fat.c librtemscpu_a_SOURCES += libfs/src/dosfs/fat.c
librtemscpu_a_SOURCES += libfs/src/dosfs/fat_fat_operations.c librtemscpu_a_SOURCES += libfs/src/dosfs/fat_fat_operations.c
librtemscpu_a_SOURCES += libfs/src/dosfs/fat_file.c librtemscpu_a_SOURCES += libfs/src/dosfs/fat_file.c
@@ -421,6 +411,7 @@ librtemscpu_a_SOURCES += libfs/src/imfs/imfs_dir.c
librtemscpu_a_SOURCES += libfs/src/imfs/imfs_dir_default.c librtemscpu_a_SOURCES += libfs/src/imfs/imfs_dir_default.c
librtemscpu_a_SOURCES += libfs/src/imfs/imfs_dir_minimal.c librtemscpu_a_SOURCES += libfs/src/imfs/imfs_dir_minimal.c
librtemscpu_a_SOURCES += libfs/src/imfs/imfs_eval.c librtemscpu_a_SOURCES += libfs/src/imfs/imfs_eval.c
librtemscpu_a_SOURCES += libfs/src/imfs/imfs_eval_devfs.c
librtemscpu_a_SOURCES += libfs/src/imfs/imfs_fchmod.c librtemscpu_a_SOURCES += libfs/src/imfs/imfs_fchmod.c
librtemscpu_a_SOURCES += libfs/src/imfs/imfs_fifo.c librtemscpu_a_SOURCES += libfs/src/imfs/imfs_fifo.c
librtemscpu_a_SOURCES += libfs/src/imfs/imfs_fsunmount.c librtemscpu_a_SOURCES += libfs/src/imfs/imfs_fsunmount.c

View File

@@ -82,7 +82,6 @@ include_rtems_HEADERS += include/rtems/config.h
include_rtems_HEADERS += include/rtems/console.h include_rtems_HEADERS += include/rtems/console.h
include_rtems_HEADERS += include/rtems/counter.h include_rtems_HEADERS += include/rtems/counter.h
include_rtems_HEADERS += include/rtems/cpuuse.h include_rtems_HEADERS += include/rtems/cpuuse.h
include_rtems_HEADERS += include/rtems/devfs.h
include_rtems_HEADERS += include/rtems/deviceio.h include_rtems_HEADERS += include/rtems/deviceio.h
include_rtems_HEADERS += include/rtems/devnull.h include_rtems_HEADERS += include/rtems/devnull.h
include_rtems_HEADERS += include/rtems/devzero.h include_rtems_HEADERS += include/rtems/devzero.h

View File

@@ -48,7 +48,6 @@
#undef BSP_IDLE_TASK_STACK_SIZE #undef BSP_IDLE_TASK_STACK_SIZE
#undef BSP_INITIAL_EXTENSION #undef BSP_INITIAL_EXTENSION
#undef BSP_INTERRUPT_STACK_SIZE #undef BSP_INTERRUPT_STACK_SIZE
#undef BSP_MAXIMUM_DEVICES
#undef CONFIGURE_BSP_PREREQUISITE_DRIVERS #undef CONFIGURE_BSP_PREREQUISITE_DRIVERS
#undef CONFIGURE_MALLOC_BSP_SUPPORTS_SBRK #undef CONFIGURE_MALLOC_BSP_SUPPORTS_SBRK
#else #else

View File

@@ -47,7 +47,6 @@
#include <rtems/sysinit.h> #include <rtems/sysinit.h>
#ifdef CONFIGURE_FILESYSTEM_ALL #ifdef CONFIGURE_FILESYSTEM_ALL
#define CONFIGURE_FILESYSTEM_DEVFS
#define CONFIGURE_FILESYSTEM_DOSFS #define CONFIGURE_FILESYSTEM_DOSFS
#define CONFIGURE_FILESYSTEM_FTPFS #define CONFIGURE_FILESYSTEM_FTPFS
#define CONFIGURE_FILESYSTEM_IMFS #define CONFIGURE_FILESYSTEM_IMFS
@@ -57,12 +56,6 @@
#define CONFIGURE_FILESYSTEM_TFTPFS #define CONFIGURE_FILESYSTEM_TFTPFS
#endif #endif
#ifdef CONFIGURE_USE_DEVFS_AS_BASE_FILESYSTEM
#define CONFIGURE_FILESYSTEM_DEVFS
#elif !defined(CONFIGURE_APPLICATION_DISABLE_FILESYSTEM)
#define _CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM
#endif
#ifdef CONFIGURE_USE_MINIIMFS_AS_BASE_FILESYSTEM #ifdef CONFIGURE_USE_MINIIMFS_AS_BASE_FILESYSTEM
#ifdef CONFIGURE_USE_DEVFS_AS_BASE_FILESYSTEM #ifdef CONFIGURE_USE_DEVFS_AS_BASE_FILESYSTEM
#error "CONFIGURE_USE_MINIIMFS_AS_BASE_FILESYSTEM cannot be used together with CONFIGURE_USE_DEVFS_AS_BASE_FILESYSTEM" #error "CONFIGURE_USE_MINIIMFS_AS_BASE_FILESYSTEM cannot be used together with CONFIGURE_USE_DEVFS_AS_BASE_FILESYSTEM"
@@ -78,6 +71,21 @@
#define CONFIGURE_IMFS_DISABLE_UTIME #define CONFIGURE_IMFS_DISABLE_UTIME
#endif #endif
#ifdef CONFIGURE_USE_DEVFS_AS_BASE_FILESYSTEM
#define CONFIGURE_IMFS_DISABLE_CHMOD
#define CONFIGURE_IMFS_DISABLE_CHOWN
#define CONFIGURE_IMFS_DISABLE_LINK
#define CONFIGURE_IMFS_DISABLE_MKNOD_FILE
#define CONFIGURE_IMFS_DISABLE_MOUNT
#define CONFIGURE_IMFS_DISABLE_READDIR
#define CONFIGURE_IMFS_DISABLE_READLINK
#define CONFIGURE_IMFS_DISABLE_RENAME
#define CONFIGURE_IMFS_DISABLE_RMNOD
#define CONFIGURE_IMFS_DISABLE_SYMLINK
#define CONFIGURE_IMFS_DISABLE_UNMOUNT
#define CONFIGURE_IMFS_DISABLE_UTIME
#endif
#ifdef CONFIGURE_APPLICATION_DISABLE_FILESYSTEM #ifdef CONFIGURE_APPLICATION_DISABLE_FILESYSTEM
#ifdef CONFIGURE_USE_DEVFS_AS_BASE_FILESYSTEM #ifdef CONFIGURE_USE_DEVFS_AS_BASE_FILESYSTEM
#error "CONFIGURE_APPLICATION_DISABLE_FILESYSTEM cannot be used together with CONFIGURE_USE_DEVFS_AS_BASE_FILESYSTEM" #error "CONFIGURE_APPLICATION_DISABLE_FILESYSTEM cannot be used together with CONFIGURE_USE_DEVFS_AS_BASE_FILESYSTEM"
@@ -87,10 +95,6 @@
#error "CONFIGURE_APPLICATION_DISABLE_FILESYSTEM cannot be used together with CONFIGURE_USE_MINIIMFS_AS_BASE_FILESYSTEM" #error "CONFIGURE_APPLICATION_DISABLE_FILESYSTEM cannot be used together with CONFIGURE_USE_MINIIMFS_AS_BASE_FILESYSTEM"
#endif #endif
#ifdef CONFIGURE_FILESYSTEM_DEVFS
#error "CONFIGURE_APPLICATION_DISABLE_FILESYSTEM cannot be used together with CONFIGURE_FILESYSTEM_DEVFS"
#endif
#ifdef CONFIGURE_FILESYSTEM_DOSFS #ifdef CONFIGURE_FILESYSTEM_DOSFS
#error "CONFIGURE_APPLICATION_DISABLE_FILESYSTEM cannot be used together with CONFIGURE_FILESYSTEM_DOSFS" #error "CONFIGURE_APPLICATION_DISABLE_FILESYSTEM cannot be used together with CONFIGURE_FILESYSTEM_DOSFS"
#endif #endif
@@ -118,13 +122,9 @@
#ifdef CONFIGURE_FILESYSTEM_TFTPFS #ifdef CONFIGURE_FILESYSTEM_TFTPFS
#error "CONFIGURE_APPLICATION_DISABLE_FILESYSTEM cannot be used together with CONFIGURE_FILESYSTEM_TFTPFS" #error "CONFIGURE_APPLICATION_DISABLE_FILESYSTEM cannot be used together with CONFIGURE_FILESYSTEM_TFTPFS"
#endif #endif
#else
#define _CONFIGURE_FILESYSTEM_INITIALIZE
#endif #endif
#ifdef CONFIGURE_FILESYSTEM_DEVFS #include <rtems/imfs.h>
#include <rtems/devfs.h>
#endif
#ifdef CONFIGURE_FILESYSTEM_DOSFS #ifdef CONFIGURE_FILESYSTEM_DOSFS
#include <rtems/dosfs.h> #include <rtems/dosfs.h>
@@ -134,11 +134,6 @@
#include <rtems/ftpfs.h> #include <rtems/ftpfs.h>
#endif #endif
#if defined(CONFIGURE_FILESYSTEM_IMFS) \
|| defined(_CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM)
#include <rtems/imfs.h>
#endif
#ifdef CONFIGURE_FILESYSTEM_JFFS2 #ifdef CONFIGURE_FILESYSTEM_JFFS2
#include <rtems/jffs2.h> #include <rtems/jffs2.h>
#endif #endif
@@ -159,28 +154,7 @@
extern "C" { extern "C" {
#endif #endif
#ifdef CONFIGURE_USE_DEVFS_AS_BASE_FILESYSTEM #ifndef CONFIGURE_APPLICATION_DISABLE_FILESYSTEM
#ifndef CONFIGURE_MAXIMUM_DEVICES
#ifdef BSP_MAXIMUM_DEVICES
#define CONFIGURE_MAXIMUM_DEVICES BSP_MAXIMUM_DEVICES
#else
#define CONFIGURE_MAXIMUM_DEVICES 4
#endif
#endif
static devFS_node devFS_root_filesystem_nodes[ CONFIGURE_MAXIMUM_DEVICES ];
static const devFS_data _Filesystem_Root_data = {
devFS_root_filesystem_nodes,
CONFIGURE_MAXIMUM_DEVICES
};
#define _CONFIGURE_FILESYSTEM_ROOT_TYPE RTEMS_FILESYSTEM_TYPE_DEVFS
#endif /* CONFIGURE_USE_DEVFS_AS_BASE_FILESYSTEM */
#ifdef _CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM
#ifndef CONFIGURE_IMFS_MEMFILE_BYTES_PER_BLOCK #ifndef CONFIGURE_IMFS_MEMFILE_BYTES_PER_BLOCK
#define CONFIGURE_IMFS_MEMFILE_BYTES_PER_BLOCK \ #define CONFIGURE_IMFS_MEMFILE_BYTES_PER_BLOCK \
@@ -198,12 +172,16 @@ static const devFS_data _Filesystem_Root_data = {
const int imfs_memfile_bytes_per_block = CONFIGURE_IMFS_MEMFILE_BYTES_PER_BLOCK; const int imfs_memfile_bytes_per_block = CONFIGURE_IMFS_MEMFILE_BYTES_PER_BLOCK;
static IMFS_fs_info_t _IMFS_fs_info; static IMFS_fs_info_t IMFS_root_fs_info;
static const rtems_filesystem_operations_table _IMFS_ops = { static const rtems_filesystem_operations_table IMFS_root_ops = {
rtems_filesystem_default_lock, rtems_filesystem_default_lock,
rtems_filesystem_default_unlock, rtems_filesystem_default_unlock,
#ifdef CONFIGURE_USE_DEVFS_AS_BASE_FILESYSTEM
IMFS_eval_path_devfs,
#else
IMFS_eval_path, IMFS_eval_path,
#endif
#ifdef CONFIGURE_IMFS_DISABLE_LINK #ifdef CONFIGURE_IMFS_DISABLE_LINK
rtems_filesystem_default_link, rtems_filesystem_default_link,
#else #else
@@ -266,13 +244,17 @@ static const rtems_filesystem_operations_table _IMFS_ops = {
rtems_filesystem_default_statvfs rtems_filesystem_default_statvfs
}; };
static const IMFS_mknod_controls _IMFS_mknod_controls = { static const IMFS_mknod_controls IMFS_root_mknod_controls = {
#ifdef CONFIGURE_IMFS_DISABLE_READDIR #ifdef CONFIGURE_IMFS_DISABLE_READDIR
&IMFS_mknod_control_dir_minimal, &IMFS_mknod_control_dir_minimal,
#else #else
&IMFS_mknod_control_dir_default, &IMFS_mknod_control_dir_default,
#endif #endif
#ifdef CONFIGURE_IMFS_DISABLE_MKNOD_DEVICE
&IMFS_mknod_control_enosys,
#else
&IMFS_mknod_control_device, &IMFS_mknod_control_device,
#endif
#ifdef CONFIGURE_IMFS_DISABLE_MKNOD_FILE #ifdef CONFIGURE_IMFS_DISABLE_MKNOD_FILE
&IMFS_mknod_control_enosys, &IMFS_mknod_control_enosys,
#else #else
@@ -285,18 +267,12 @@ static const IMFS_mknod_controls _IMFS_mknod_controls = {
#endif #endif
}; };
static const IMFS_mount_data _Filesystem_Root_data = { static const IMFS_mount_data IMFS_root_mount_data = {
&_IMFS_fs_info, &IMFS_root_fs_info,
&_IMFS_ops, &IMFS_root_ops,
&_IMFS_mknod_controls &IMFS_root_mknod_controls
}; };
#define _CONFIGURE_FILESYSTEM_ROOT_TYPE "/"
#endif /* _CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM */
#ifdef _CONFIGURE_FILESYSTEM_INITIALIZE
#if defined(CONFIGURE_FILESYSTEM_DEVFS) \ #if defined(CONFIGURE_FILESYSTEM_DEVFS) \
&& !defined(CONFIGURE_FILESYSTEM_ENTRY_DEVFS) && !defined(CONFIGURE_FILESYSTEM_ENTRY_DEVFS)
#define CONFIGURE_FILESYSTEM_ENTRY_DEVFS \ #define CONFIGURE_FILESYSTEM_ENTRY_DEVFS \
@@ -346,9 +322,7 @@ static const IMFS_mount_data _Filesystem_Root_data = {
#endif #endif
const rtems_filesystem_table_t rtems_filesystem_table[] = { const rtems_filesystem_table_t rtems_filesystem_table[] = {
#ifdef _CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM
{ "/", IMFS_initialize_support }, { "/", IMFS_initialize_support },
#endif
#ifdef CONFIGURE_FILESYSTEM_ENTRY_DEVFS #ifdef CONFIGURE_FILESYSTEM_ENTRY_DEVFS
CONFIGURE_FILESYSTEM_ENTRY_DEVFS, CONFIGURE_FILESYSTEM_ENTRY_DEVFS,
#endif #endif
@@ -380,9 +354,9 @@ const rtems_filesystem_mount_configuration
rtems_filesystem_root_configuration = { rtems_filesystem_root_configuration = {
NULL, NULL,
NULL, NULL,
_CONFIGURE_FILESYSTEM_ROOT_TYPE, "/",
RTEMS_FILESYSTEM_READ_WRITE, RTEMS_FILESYSTEM_READ_WRITE,
&_Filesystem_Root_data &IMFS_root_mount_data
}; };
RTEMS_SYSINIT_ITEM( RTEMS_SYSINIT_ITEM(
@@ -391,7 +365,7 @@ RTEMS_SYSINIT_ITEM(
RTEMS_SYSINIT_ORDER_MIDDLE RTEMS_SYSINIT_ORDER_MIDDLE
); );
#endif /* _CONFIGURE_FILESYSTEM_INITIALIZE */ #endif /* !CONFIGURE_APPLICATION_DISABLE_FILESYSTEM */
#ifndef CONFIGURE_MAXIMUM_FILE_DESCRIPTORS #ifndef CONFIGURE_MAXIMUM_FILE_DESCRIPTORS
#define CONFIGURE_MAXIMUM_FILE_DESCRIPTORS 3 #define CONFIGURE_MAXIMUM_FILE_DESCRIPTORS 3

View File

@@ -65,6 +65,10 @@
#error "The CONFIGURE_BDBUF_BUFFER_COUNT configuration option is obsolete since RTEMS 4.10.0" #error "The CONFIGURE_BDBUF_BUFFER_COUNT configuration option is obsolete since RTEMS 4.10.0"
#endif #endif
#ifdef CONFIGURE_MAXIMUM_DEVICES
#warning "The CONFIGURE_MAXIMUM_DEVICES configuration option is obsolete since RTEMS 5.1"
#endif
#ifdef CONFIGURE_ENABLE_GO #ifdef CONFIGURE_ENABLE_GO
#warning "The CONFIGURE_ENABLE_GO configuration option is obsolete since RTEMS 5.1" #warning "The CONFIGURE_ENABLE_GO configuration option is obsolete since RTEMS 5.1"
#endif #endif

View File

@@ -1,255 +0,0 @@
/**
* @file
*
* @brief Device Only File System
*
* This include file contains all constants and structures associated
* with the 'device-only' filesystem.
*/
#ifndef _RTEMS_DEVFS_H
#define _RTEMS_DEVFS_H
#include <rtems/libio_.h>
/**
* @defgroup DevFsDeviceTable Device Only File System
*
* @ingroup FileSystemTypesAndMount
*
* @brief This structure defines the type of device table
*/
/**@{*/
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Per Device Node Control Structure
*
* This structure is instanced per device node and contains all information
* used by this file system implementation to manage that device node.
*/
typedef struct {
/** This member points to device name which is not a null-terminated string */
const char *name;
/** This member is the name length of a device */
size_t namelen;
/** major number of a device */
rtems_device_major_number major;
/** minor number of a device */
rtems_device_minor_number minor;
/** device creation mode, only device file can be created */
mode_t mode;
} devFS_node;
typedef struct {
devFS_node *nodes;
size_t count;
} devFS_data;
/**
* The following defines the device-only filesystem operating
* operations.
*/
extern const rtems_filesystem_operations_table devFS_ops;
/**
* The following defines the device-only filesystem operating
* handlers.
*/
extern const rtems_filesystem_file_handlers_r devFS_file_handlers;
/**
* @brief Obtain Immutable Pointer to Immutable File System Data
*
* This methods returns the immutable file system specific information
* associated with this file.
*/
static inline const devFS_data *devFS_get_data(
const rtems_filesystem_location_info_t *loc
)
{
return (const devFS_data *) loc->mt_entry->immutable_fs_info;
}
/**
* @brief Evaluate Path
*/
extern void devFS_eval_path(
rtems_filesystem_eval_path_context_t *ctx
);
/**
* @brief Maps Open Operation to rtems_io_open
*
* This handler maps open operation to rtems_io_open.
*
* @param iop This is the RTEMS's internal representation of file.
* @param pathname a null-terminated string that starts with /dev.
* @param oflag access flags
* @param mode access mode
*
* @retval the same as open
*/
extern int devFS_open(
rtems_libio_t *iop,
const char *pathname,
int oflag,
mode_t mode
);
/**
* @brief Maps Close Operation to rtems_io_close
*
* This handler maps close operation to rtems_io_close.
*
* @param iop This is the RTEMS's internal representation of file
*
* @retval the same as close
*/
extern int devFS_close(
rtems_libio_t *iop
);
/**
* @brief Maps Read Operation to rtems_io_read
*
* This handler maps read operation to rtems_io_read.
*
* @param iop This is the RTEMS's internal representation of file
* @param buffer memory location to store read data
* @param count how many bytes to read
*
* @retval On successful, this routine returns total bytes read. On error
* it returns -1 and errno is set to proper value.
*/
extern ssize_t devFS_read(
rtems_libio_t *iop,
void *buffer,
size_t count
);
/**
* @brief Writes Operation to rtems_io_write
*
* This handler maps write operation to rtems_io_write.
*
* @param iop This is the RTEMS's internal representation of file
* @param buffer data to be written
* @param count how many bytes to write
*
* @retval On successful, this routine returns total bytes written. On error
* it returns -1 and errno is set to proper value.
*/
extern ssize_t devFS_write(
rtems_libio_t *iop,
const void *buffer,
size_t count
);
/**
* @brief Maps ioctl Operation to rtems_io_ioctl
*
* This handler maps ioctl operation to rtems_io_ioctl.
*
* @param iop This is the RTEMS's internal representation of file
* @param command io control command
* @param buffer io control parameters
*
* @retval On successful, this routine returns total bytes written. On error
* it returns -1 and errno is set to proper value.
*/
extern int devFS_ioctl(
rtems_libio_t *iop,
ioctl_command_t command,
void *buffer
);
/**
* @brief Gets the Device File Information
*
* This handler gets the device file information. This routine only
* set the following member of struct stat:
*
* - st_dev: device number
* - st_mode: device file creation mode, only two mode are accepted:
* + S_IFCHR: character device file
* + S_IFBLK: block device file
*
* @param loc contains filesystem access information
* @param buf buffer to hold the device file's information
*
* @retval On successful, this routine returns 0. On error
* it returns -1 and errno is set to proper value.
*/
extern int devFS_stat(
const rtems_filesystem_location_info_t *loc,
struct stat *buf
);
/**
* @brief Creates an item in the main device table.
*
* This routine is invoked upon registration of a new device
* file. It is responsible for creating a item in the main
* device table. This routine searches the device table in
* sequential order, when found a empty slot, it fills the slot
* with proper values.
*
* @see rtems_filesystem_mknod_t.
*/
extern int devFS_mknod(
const rtems_filesystem_location_info_t *parentloc,
const char *name,
size_t namelen,
mode_t mode,
dev_t dev
);
/**
* @brief Creates the Main Device Table
*
* This routine is invoked upon rtems filesystem initialization.
* It is responsible for creating the main device table,
* initializing it to a known state, and set device file operation
* handlers. After this, the device-only filesytem is ready for use
*
* @param mt_entry The filesystem mount table entry.
* @param data Filesystem specific data.
*
* @retval upon success, this routine returns 0; otherwise it returns
* -1 and errno is set to proper value. The only error is when malloc
* failed, and errno is set to NOMEM.
*/
extern int devFS_initialize(
rtems_filesystem_mount_table_entry_t *mt_entry,
const void *data
);
/**
* @brief Retrieves and Prints all the Device Registered in System
*
* This routine retrieves all the device registered in system, and
* prints out their detail information. For example, on one system,
* devFS_show will print out following message:
*
* @code
* /dev/console 0 0
* /dev/clock 1 0
* /dev/tty0 0 0
* /flash 2 0
* @endcode
*
* This routine is intended for debugging, and can be used by shell
* program to provide user with the system information.
*/
extern void devFS_Show(void);
#ifdef __cplusplus
}
#endif
/**@}*/
#endif

View File

@@ -536,6 +536,13 @@ extern void IMFS_eval_path(
rtems_filesystem_eval_path_context_t *ctx rtems_filesystem_eval_path_context_t *ctx
); );
/**
* @brief IMFS device filesystem evaluation node support.
*/
extern void IMFS_eval_path_devfs(
rtems_filesystem_eval_path_context_t *ctx
);
/** /**
* @brief Create a new IMFS link node. * @brief Create a new IMFS link node.
* *

View File

@@ -1,29 +0,0 @@
/**
* @file
*
* @brief Maps Close Operation to rtems_io_close
* @ingroup DevFsDeviceTable Define Device Table Type
*/
/*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rtems.org/license/LICENSE.
*/
#if HAVE_CONFIG_H
#include "config.h"
#endif
#include <rtems/devfs.h>
#include <rtems/deviceio.h>
int devFS_close(
rtems_libio_t *iop
)
{
const devFS_node *np = iop->pathinfo.node_access;
return rtems_deviceio_close( iop, np->major, np->minor );
}

View File

@@ -1,95 +0,0 @@
/**
* @file
*
* @brief Evaluate Patch
* @ingroup DevFsDeviceTable Define Device Table Type
*/
/*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rtems.org/license/LICENSE.
*/
#if HAVE_CONFIG_H
#include "config.h"
#endif
#include <string.h>
#include <rtems/devfs.h>
static devFS_node *devFS_search_node(
const devFS_data *data,
const char *path,
size_t pathlen,
devFS_node **free_node_ptr
)
{
size_t i = 0;
size_t n = data->count;
devFS_node *nodes = data->nodes;
devFS_node *node = NULL;
devFS_node *free_node = NULL;
for (i = 0; (free_node == NULL || node == NULL) && i < n; ++i) {
devFS_node *current = nodes + i;
if (current->name != NULL) {
if (
current->namelen == pathlen
&& memcmp(current->name, path, pathlen) == 0
) {
node = current;
}
} else {
free_node = current;
}
}
*free_node_ptr = free_node;
return node;
}
void devFS_eval_path(
rtems_filesystem_eval_path_context_t *ctx
)
{
rtems_filesystem_location_info_t *currentloc =
rtems_filesystem_eval_path_get_currentloc(ctx);
devFS_node *free_node;
devFS_node *node = devFS_search_node(
devFS_get_data(currentloc),
rtems_filesystem_eval_path_get_path(ctx),
rtems_filesystem_eval_path_get_pathlen(ctx),
&free_node
);
int eval_flags = rtems_filesystem_eval_path_get_flags(ctx);
if (node != NULL) {
if ((eval_flags & RTEMS_FS_EXCLUSIVE) == 0) {
currentloc->node_access = node;
rtems_filesystem_eval_path_clear_path(ctx);
} else {
rtems_filesystem_eval_path_error(ctx, EEXIST);
}
} else {
if ((eval_flags & RTEMS_FS_MAKE) != 0) {
if (free_node != NULL) {
free_node->mode = S_IRWXU | S_IRWXG | S_IRWXO;
currentloc->node_access = free_node;
rtems_filesystem_eval_path_set_token(
ctx,
rtems_filesystem_eval_path_get_path(ctx),
rtems_filesystem_eval_path_get_pathlen(ctx)
);
rtems_filesystem_eval_path_clear_path(ctx);
} else {
rtems_filesystem_eval_path_error(ctx, ENOSPC);
}
} else {
rtems_filesystem_eval_path_error(ctx, ENOENT);
}
}
}

View File

@@ -1,79 +0,0 @@
/**
* @file
*
* @brief Creates the Main Device Table
* @ingroup DevFsDeviceTable Define Device Table Type
*/
/*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rtems.org/license/LICENSE.
*/
#if HAVE_CONFIG_H
#include "config.h"
#endif
#include <rtems/devfs.h>
const rtems_filesystem_operations_table devFS_ops = {
.lock_h = rtems_filesystem_default_lock,
.unlock_h = rtems_filesystem_default_unlock,
.eval_path_h = devFS_eval_path,
.link_h = rtems_filesystem_default_link,
.are_nodes_equal_h = rtems_filesystem_default_are_nodes_equal,
.mknod_h = devFS_mknod,
.rmnod_h = rtems_filesystem_default_rmnod,
.fchmod_h = rtems_filesystem_default_fchmod,
.chown_h = rtems_filesystem_default_chown,
.clonenod_h = rtems_filesystem_default_clonenode,
.freenod_h = rtems_filesystem_default_freenode,
.mount_h = rtems_filesystem_default_mount,
.unmount_h = rtems_filesystem_default_unmount,
.fsunmount_me_h = rtems_filesystem_default_fsunmount,
.utime_h = rtems_filesystem_default_utime,
.symlink_h = rtems_filesystem_default_symlink,
.readlink_h = rtems_filesystem_default_readlink,
.rename_h = rtems_filesystem_default_rename,
.statvfs_h = rtems_filesystem_default_statvfs
};
const rtems_filesystem_file_handlers_r devFS_file_handlers = {
.open_h = devFS_open,
.close_h = devFS_close,
.read_h = devFS_read,
.write_h = devFS_write,
.ioctl_h = devFS_ioctl,
.lseek_h = rtems_filesystem_default_lseek_file,
.fstat_h = devFS_stat,
.ftruncate_h = rtems_filesystem_default_ftruncate,
.fsync_h = rtems_filesystem_default_fsync_or_fdatasync,
.fdatasync_h = rtems_filesystem_default_fsync_or_fdatasync,
.fcntl_h = rtems_filesystem_default_fcntl,
.kqfilter_h = rtems_filesystem_default_kqfilter,
.mmap_h = rtems_filesystem_default_mmap,
.poll_h = rtems_filesystem_default_poll,
.readv_h = rtems_filesystem_default_readv,
.writev_h = rtems_filesystem_default_writev
};
int devFS_initialize(
rtems_filesystem_mount_table_entry_t *mt_entry,
const void *data
)
{
int rv = 0;
if (data != NULL) {
mt_entry->ops = &devFS_ops;
mt_entry->immutable_fs_info = data;
mt_entry->mt_fs_root->location.handlers = &devFS_file_handlers;
} else {
errno = EINVAL;
rv = -1;
}
return rv;
}

View File

@@ -1,63 +0,0 @@
/**
* @file
*
* @brief Creates an item in the main device table.
* @ingroup DevFsDeviceTable Define Device Table Type
*/
/*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rtems.org/license/LICENSE.
*/
#if HAVE_CONFIG_H
#include "config.h"
#endif
#include <sys/stat.h>
#include <stdlib.h>
#include <string.h>
#include <rtems/devfs.h>
int devFS_mknod(
const rtems_filesystem_location_info_t *parentloc,
const char *name,
size_t namelen,
mode_t mode,
dev_t dev
)
{
int rv = 0;
if (namelen != 3 || name [0] != 'd' || name [1] != 'e' || name [2] != 'v') {
if (S_ISBLK(mode) || S_ISCHR(mode)) {
char *dupname = malloc(namelen);
if (dupname != NULL) {
devFS_node *node = parentloc->node_access;
node->name = dupname;
node->namelen = namelen;
node->major = rtems_filesystem_dev_major_t(dev);
node->minor = rtems_filesystem_dev_minor_t(dev);
node->mode = mode;
memcpy(dupname, name, namelen);
} else {
errno = ENOMEM;
rv = -1;
}
} else {
errno = ENOTSUP;
rv = -1;
}
} else {
if (!S_ISDIR(mode)) {
errno = ENOTSUP;
rv = -1;
}
}
return rv;
}

View File

@@ -1,51 +0,0 @@
/**
* @file
*
* @brief Retrieves and Prints all the Device Registered in System
* @ingroup DevFsDeviceTable Define Device Table Type
*/
/*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rtems.org/license/LICENSE.
*/
#if HAVE_CONFIG_H
#include "config.h"
#endif
#include <rtems/devfs.h>
#include <rtems/bspIo.h>
void devFS_Show(void)
{
rtems_filesystem_location_info_t *rootloc = &rtems_filesystem_root->location;
if (rootloc->mt_entry->ops == &devFS_ops) {
const devFS_data *data = devFS_get_data(rootloc);
size_t i = 0;
size_t n = data->count;
devFS_node *nodes = data->nodes;
for (i = 0; i < n; ++i) {
devFS_node *current = nodes + i;
if (current->name != NULL) {
size_t j = 0;
size_t m = current->namelen;
printk("/");
for (j = 0; j < m; ++j) {
printk("%c", current->name [j]);
}
printk(
" %lu %lu\n",
(unsigned long) current->major,
(unsigned long) current->minor
);
}
}
}
}

View File

@@ -1,31 +0,0 @@
/**
* @file
*
* @brief Maps ioctl Operation to rtems_io_ioctl
* @ingroup DevFsDeviceTable Define Device Table Type
*/
/*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rtems.org/license/LICENSE.
*/
#if HAVE_CONFIG_H
#include "config.h"
#endif
#include <rtems/devfs.h>
#include <rtems/deviceio.h>
int devFS_ioctl(
rtems_libio_t *iop,
ioctl_command_t command,
void *buffer
)
{
const devFS_node *np = iop->pathinfo.node_access;
return rtems_deviceio_control( iop, command, buffer, np->major, np->minor );
}

View File

@@ -1,39 +0,0 @@
/**
* @file
*
* @brief Maps Open Operation to rtems_io_open
* @ingroup DevFsDeviceTable Define Device Table Type
*/
/*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rtems.org/license/LICENSE.
*/
#if HAVE_CONFIG_H
#include "config.h"
#endif
#include <rtems/devfs.h>
#include <rtems/deviceio.h>
int devFS_open(
rtems_libio_t *iop,
const char *pathname,
int oflag,
mode_t mode
)
{
const devFS_node *np = iop->pathinfo.node_access;
return rtems_deviceio_open(
iop,
pathname,
oflag,
mode,
np->major,
np->minor
);
}

View File

@@ -1,31 +0,0 @@
/**
* @file
*
* @brief DevFS Read
* @ingroup Read Operation to rtems_io_read
*/
/*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rtems.org/license/LICENSE.
*/
#if HAVE_CONFIG_H
#include "config.h"
#endif
#include <rtems/devfs.h>
#include <rtems/deviceio.h>
ssize_t devFS_read(
rtems_libio_t *iop,
void *buffer,
size_t count
)
{
const devFS_node *np = iop->pathinfo.node_access;
return rtems_deviceio_read( iop, buffer, count, np->major, np->minor );
}

View File

@@ -1,36 +0,0 @@
/**
* @file
*
* @brief Gets the Device File Information
* @ingroup DevFsDeviceTable Define Device Table Type
*/
/*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rtems.org/license/LICENSE.
*/
#if HAVE_CONFIG_H
#include "config.h"
#endif
#include <rtems/devfs.h>
int devFS_stat(
const rtems_filesystem_location_info_t *loc,
struct stat *buf
)
{
int rv = 0;
const devFS_node *the_dev = loc->node_access;
if (the_dev != NULL) {
buf->st_rdev = rtems_filesystem_make_dev_t( the_dev->major, the_dev->minor );
buf->st_mode = the_dev->mode;
} else {
rv = rtems_filesystem_default_fstat(loc, buf);
}
return rv;
}

View File

@@ -1,31 +0,0 @@
/**
* @file
*
* @brief Writes Operation to rtems_io_write
* @ingroup DevFsDeviceTable Define Device Table Type
*/
/*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rtems.org/license/LICENSE.
*/
#if HAVE_CONFIG_H
#include "config.h"
#endif
#include <rtems/devfs.h>
#include <rtems/deviceio.h>
ssize_t devFS_write(
rtems_libio_t *iop,
const void *buffer,
size_t count
)
{
const devFS_node *np = iop->pathinfo.node_access;
return rtems_deviceio_write( iop, buffer, count, np->major, np->minor );
}

View File

@@ -0,0 +1,163 @@
/* SPDX-License-Identifier: BSD-2-Clause */
/**
* @file
*
* @ingroup ClassicIO
*
* @brief Implementation of IMFS_eval_path_devfs().
*/
/*
* Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de)
*
* 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>
#include <string.h>
typedef struct {
uint8_t len;
char name[3];
} IMFS_devfs_dir;
static const IMFS_devfs_dir IMFS_devfs_dirs[] = {
{ .len = 1, .name = { '/' } },
{ .len = 1, .name = { '.' } },
{ .len = 2, .name = { '.', '.' } },
{ .len = 3, .name = { 'd', 'e', 'v' } }
};
static IMFS_jnode_t *IMFS_devfs_is_dir(
rtems_filesystem_eval_path_context_t *ctx,
IMFS_directory_t *dir
)
{
const char *path;
size_t pathlen;
size_t i;
path = rtems_filesystem_eval_path_get_path( ctx );
pathlen = rtems_filesystem_eval_path_get_pathlen( ctx );
for ( i = 0; i < RTEMS_ARRAY_SIZE( IMFS_devfs_dirs ); ++i ) {
bool match;
match = IMFS_devfs_dirs[ i ].len == pathlen
&& memcmp( IMFS_devfs_dirs[ i ].name, path, pathlen ) == 0;
if ( match ) {
int eval_flags;
eval_flags = rtems_filesystem_eval_path_get_flags( ctx );
eval_flags &= ~RTEMS_FS_EXCLUSIVE;
rtems_filesystem_eval_path_set_flags( ctx, eval_flags );
rtems_filesystem_eval_path_clear_path( ctx );
return &dir->Node;
}
}
return NULL;
}
static IMFS_jnode_t *IMFS_devfs_search(
rtems_filesystem_eval_path_context_t *ctx,
IMFS_directory_t *dir
)
{
const char *path;
size_t pathlen;
rtems_chain_control *entries;
rtems_chain_node *current;
rtems_chain_node *tail;
path = rtems_filesystem_eval_path_get_path( ctx );
pathlen = rtems_filesystem_eval_path_get_pathlen( ctx );
entries = &dir->Entries;
current = rtems_chain_first( entries );
tail = rtems_chain_tail( entries );
while ( current != tail ) {
IMFS_jnode_t *entry;
bool match;
entry = (IMFS_jnode_t *) current;
match = entry->namelen == pathlen
&& memcmp( entry->name, path, pathlen ) == 0;
if ( match ) {
return entry;
}
current = rtems_chain_next( current );
}
return NULL;
}
void IMFS_eval_path_devfs( rtems_filesystem_eval_path_context_t *ctx )
{
rtems_filesystem_location_info_t *currentloc;
IMFS_directory_t *dir;
IMFS_jnode_t *entry;
currentloc = rtems_filesystem_eval_path_get_currentloc( ctx );
dir = currentloc->node_access;
entry = IMFS_devfs_is_dir( ctx, dir );
if ( entry != NULL ) {
return;
}
entry = IMFS_devfs_search( ctx, dir );
if ( entry != NULL ) {
int eval_flags;
eval_flags = rtems_filesystem_eval_path_get_flags( ctx );
if ( ( eval_flags & RTEMS_FS_EXCLUSIVE ) == 0 ) {
--dir->Node.reference_count;
++entry->reference_count;
currentloc->node_access = entry;
currentloc->node_access_2 = IMFS_generic_get_context_by_node( entry );
IMFS_Set_handlers( currentloc );
rtems_filesystem_eval_path_clear_path( ctx );
} else {
rtems_filesystem_eval_path_error( ctx, EEXIST );
}
} else {
rtems_filesystem_eval_path_set_token(
ctx,
rtems_filesystem_eval_path_get_path( ctx ),
rtems_filesystem_eval_path_get_pathlen( ctx )
);
rtems_filesystem_eval_path_clear_path( ctx );
}
}

View File

@@ -271,24 +271,6 @@ devfs01_CPPFLAGS = $(AM_CPPFLAGS) $(TEST_FLAGS_devfs01) \
$(support_includes) $(support_includes)
endif endif
if TEST_devfs02
lib_tests += devfs02
lib_screens += devfs02/devfs02.scn
lib_docs += devfs02/devfs02.doc
devfs02_SOURCES = devfs02/init.c
devfs02_CPPFLAGS = $(AM_CPPFLAGS) $(TEST_FLAGS_devfs02) \
$(support_includes)
endif
if TEST_devfs03
lib_tests += devfs03
lib_screens += devfs03/devfs03.scn
lib_docs += devfs03/devfs03.doc
devfs03_SOURCES = devfs03/init.c
devfs03_CPPFLAGS = $(AM_CPPFLAGS) $(TEST_FLAGS_devfs03) \
$(support_includes)
endif
if TEST_devfs04 if TEST_devfs04
lib_tests += devfs04 lib_tests += devfs04
lib_screens += devfs04/devfs04.scn lib_screens += devfs04/devfs04.scn

View File

@@ -119,8 +119,6 @@ RTEMS_TEST_CHECK([crypt01])
RTEMS_TEST_CHECK([debugger01]) RTEMS_TEST_CHECK([debugger01])
RTEMS_TEST_CHECK([defaultconfig01]) RTEMS_TEST_CHECK([defaultconfig01])
RTEMS_TEST_CHECK([devfs01]) RTEMS_TEST_CHECK([devfs01])
RTEMS_TEST_CHECK([devfs02])
RTEMS_TEST_CHECK([devfs03])
RTEMS_TEST_CHECK([devfs04]) RTEMS_TEST_CHECK([devfs04])
RTEMS_TEST_CHECK([deviceio01]) RTEMS_TEST_CHECK([deviceio01])
RTEMS_TEST_CHECK([devnullfatal01]) RTEMS_TEST_CHECK([devnullfatal01])

View File

@@ -1,10 +1,28 @@
/* SPDX-License-Identifier: BSD-2-Clause */
/* /*
* COPYRIGHT (c) 1989-2012. * Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de)
* On-Line Applications Research Corporation (OAR).
* *
* The license and distribution terms for this file may be * Redistribution and use in source and binary forms, with or without
* found in the file LICENSE in this distribution or at * modification, are permitted provided that the following conditions
* http://www.rtems.org/license/LICENSE. * 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.
*/ */
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
@@ -12,34 +30,24 @@
#endif #endif
#include <tmacros.h> #include <tmacros.h>
#include "test_support.h"
#include <rtems/devfs.h>
#include <errno.h> #include <errno.h>
const char rtems_test_name[] = "DEVFS 1"; const char rtems_test_name[] = "DEVFS 1";
/* forward declarations to avoid warnings */ static void Init(rtems_task_argument argument)
rtems_task Init(rtems_task_argument argument);
rtems_task Init(
rtems_task_argument argument
)
{ {
TEST_BEGIN(); TEST_BEGIN();
puts( "devFS_Show" );
devFS_Show();
TEST_END(); TEST_END();
rtems_test_exit(0); rtems_test_exit(0);
} }
/* configuration information */ #define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER
#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
#define CONFIGURE_MAXIMUM_TASKS 1 #define CONFIGURE_MAXIMUM_TASKS 1
#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
#define CONFIGURE_RTEMS_INIT_TASKS_TABLE #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
@@ -49,4 +57,3 @@ rtems_task Init(
#define CONFIGURE_INIT #define CONFIGURE_INIT
#include <rtems/confdefs.h> #include <rtems/confdefs.h>
/* end of file */

View File

@@ -1,22 +0,0 @@
# COPYRIGHT (c) 1989-2010.
# On-Line Applications Research Corporation (OAR).
#
# The license and distribution terms for this file may be
# found in the file LICENSE in this distribution or at
# http://www.rtems.org/license/LICENSE.
#
This file describes the directives and concepts tested by this test set.
test set name: devfs02
directives:
+ devFS_mknod
+ devFS_evaluate_path
concepts:
+ System calls open, mknod, mkfifo are used to exercise the above
mentioned routines. This test exercise mostly the error paths.

View File

@@ -1,13 +0,0 @@
*** TEST DEVFS02 ***
Init - attempt to create a fifo - expect EINVAL
Init - set the device name table to NULL
Init - attempt to create a node - expect EFAULT
Init - attempt to stat a node - expect EFAULT
Init - attempt to open a node
Init - restore the device name table
Init - set device table size to zero
Init - attempt to create a node - expect ENOMEM
Init - restore device table size
Init - attempt to create /node -- OK
Init - attempt to create /node - expect EEXIST
*** END OF TEST DEVFS02 ***

View File

@@ -1,108 +0,0 @@
/*
* COPYRIGHT (c) 1989-2012.
* On-Line Applications Research Corporation (OAR).
*
* Modifications to support reference counting in the file system are
* Copyright (c) 2012 embedded brains GmbH.
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rtems.org/license/LICENSE.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "test_support.h"
#include <tmacros.h>
#include <errno.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <rtems/devfs.h>
#include <rtems/malloc.h>
const char rtems_test_name[] = "DEVFS 2";
/* forward declarations to avoid warnings */
rtems_task Init(rtems_task_argument argument);
rtems_task Init(
rtems_task_argument argument
)
{
int status;
rtems_filesystem_location_info_t *rootloc = &rtems_filesystem_root->location;
const devFS_data *data = rootloc->mt_entry->immutable_fs_info;
devFS_data zero_count_data = {
.nodes = data->nodes,
.count = 0
};
void *opaque;
TEST_BEGIN();
puts( "Init - attempt to create a fifo - expect ENOTSUP" );
status = mkfifo( "/fifo01", 0 );
rtems_test_assert( status == -1 );
rtems_test_assert( errno == ENOTSUP );
/* Manipulate the device table size */
puts( "Init - set device table size to zero" );
rootloc->mt_entry->immutable_fs_info = &zero_count_data;
puts( "Init - attempt to create a node - expect ENOSPC" );
status = mknod( "/node", S_IFBLK, 0LL );
rtems_test_assert( status == -1 );
rtems_test_assert( errno == ENOSPC );
/* Now restore */
puts( "Init - restore device table size" );
rootloc->mt_entry->immutable_fs_info = data;
opaque = rtems_heap_greedy_allocate( NULL, 0 );
puts( "Init - attempt to create a node - expect ENOMEM" );
status = mknod( "/node", S_IFBLK, 0LL );
rtems_test_assert( status == -1 );
rtems_test_assert( errno == ENOMEM );
rtems_heap_greedy_free( opaque );
puts( "Init - attempt to create /node -- OK" );
status = mknod( "/node", S_IFBLK, 0LL );
rtems_test_assert( status == 0 );
puts( "Init - attempt to create /node - expect EEXIST" );
status = mknod( "/node", S_IFBLK, 0LL );
rtems_test_assert( status == -1 );
rtems_test_assert( errno == EEXIST );
TEST_END();
rtems_test_exit(0);
}
/* configuration information */
#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
#define CONFIGURE_MAXIMUM_TASKS 1
#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
#define CONFIGURE_MAXIMUM_FILE_DESCRIPTORS 2
/* Make sure that we have enough devices for all BSPs */
#define CONFIGURE_MAXIMUM_DEVICES 64
#define CONFIGURE_USE_DEVFS_AS_BASE_FILESYSTEM
#define CONFIGURE_INIT
#include <rtems/confdefs.h>
/* end of file */

View File

@@ -1,21 +0,0 @@
# COPYRIGHT (c) 1989-2010.
# On-Line Applications Research Corporation (OAR).
#
# The license and distribution terms for this file may be
# found in the file LICENSE in this distribution or at
# http://www.rtems.org/license/LICENSE.
#
This file describes the directives and concepts tested by this test set.
test set name: devfs03
directives:
+ devFS_initialize
concepts:
+ A call to mount, after consuming much of the workspace memory leads
to an ENOMEM which initializing the filesystem.

View File

@@ -1,6 +0,0 @@
*** TEST DEVFS03 ***
Init - attempt to create /dir01 -- OK
Init - allocating most of workspace memory
Init - mount a new fs at /dir01 - expect ENOMEM
Init - freeing the workspace memory
*** END OF TEST DEVFS03 ***

View File

@@ -1,99 +0,0 @@
/*
* COPYRIGHT (c) 1989-2012.
* On-Line Applications Research Corporation (OAR).
*
* Modifications to support reference counting in the file system are
* Copyright (c) 2012 embedded brains GmbH.
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rtems.org/license/LICENSE.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <tmacros.h>
#include "test_support.h"
#include <rtems/devfs.h>
#include <errno.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
const char rtems_test_name[] = "DEVFS 3";
/* forward declarations to avoid warnings */
rtems_task Init(rtems_task_argument argument);
rtems_task Init(
rtems_task_argument argument
)
{
int status;
devFS_node nodes [1];
devFS_data data = {
.nodes = nodes,
.count = 1
};
TEST_BEGIN();
memset(nodes, 0, sizeof(nodes));
puts( "Init - attempt to create /dir01 -- OK" );
status = mkdir( "/dir01", S_IRWXU );
rtems_test_assert( status == 0 );
puts( "Init - mount a new fs at /dir01 - expect EINVAL" );
status = mount( NULL,
"/dir01",
"devfs",
RTEMS_FILESYSTEM_READ_WRITE,
NULL );
rtems_test_assert( status == -1 );
rtems_test_assert( errno == EINVAL );
puts( "Init - mount a new fs at /dir01 - OK" );
status = mount( NULL,
"/dir01",
"devfs",
RTEMS_FILESYSTEM_READ_WRITE,
&data );
rtems_test_assert( status == 0 );
puts( "Init - make file /dir01/dev -- expect ENOTSUP" );
status = creat( "/dir01/dev", S_IRWXU );
rtems_test_assert( status == -1 );
rtems_test_assert( errno == ENOTSUP );
puts( "Init - unmount fs at /dir01 - OK" );
status = unmount( "/dir01" );
rtems_test_assert( status == 0 );
status = rmdir( "/dir01" );
rtems_test_assert( status == 0 );
TEST_END();
rtems_test_exit(0);
}
/* configuration information */
#define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
#define CONFIGURE_MAXIMUM_FILE_DESCRIPTORS 4
#define CONFIGURE_MAXIMUM_TASKS 1
#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
#define CONFIGURE_FILESYSTEM_DEVFS
#define CONFIGURE_INIT
#include <rtems/confdefs.h>
/* end of file */

View File

@@ -13,21 +13,17 @@
#include <tmacros.h> #include <tmacros.h>
#include "test_support.h" #include "test_support.h"
#include <rtems/devfs.h>
#include <errno.h> #include <errno.h>
#include <unistd.h> #include <unistd.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/ioctl.h>
#include <fcntl.h> #include <fcntl.h>
#include "test_driver.h" #include "test_driver.h"
#include <rtems/devnull.h>
const char rtems_test_name[] = "DEVFS 4"; const char rtems_test_name[] = "DEVFS 4";
/* forward declarations to avoid warnings */ static rtems_task Init(
rtems_task Init(rtems_task_argument argument);
rtems_task Init(
rtems_task_argument argument rtems_task_argument argument
) )
{ {
@@ -88,9 +84,6 @@ rtems_task Init(
#define CONFIGURE_RTEMS_INIT_TASKS_TABLE #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
/* Make sure that we have enough devices for all BSPs */
#define CONFIGURE_MAXIMUM_DEVICES 64
#define CONFIGURE_USE_DEVFS_AS_BASE_FILESYSTEM #define CONFIGURE_USE_DEVFS_AS_BASE_FILESYSTEM
#define CONFIGURE_INIT #define CONFIGURE_INIT

View File

@@ -13,21 +13,18 @@
#include <tmacros.h> #include <tmacros.h>
#include "test_support.h" #include "test_support.h"
#include <rtems/devfs.h>
#include <errno.h> #include <errno.h>
#include <unistd.h> #include <unistd.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/ioctl.h>
#include <fcntl.h> #include <fcntl.h>
#include "test_driver.h" #include "test_driver.h"
#include <rtems/devnull.h> #include <rtems/devnull.h>
const char rtems_test_name[] = "DEVICEIO 1"; const char rtems_test_name[] = "DEVICEIO 1";
/* forward declarations to avoid warnings */ static rtems_task Init(
rtems_task Init(rtems_task_argument argument);
rtems_task Init(
rtems_task_argument argument rtems_task_argument argument
) )
{ {