Filesystem: Add shared device IO support

The device IO file system support in IMFS, devFS, and RFS uses now a
shared implementation.
This commit is contained in:
Sebastian Huber
2012-05-14 15:19:20 +02:00
parent df01da6707
commit fed66f9910
14 changed files with 255 additions and 289 deletions

View File

@@ -24,6 +24,7 @@ include_rtems_motorola_HEADERS += include/motorola/mc68681.h
## rtems
include_rtems_HEADERS += include/rtems/assoc.h
include_rtems_HEADERS += include/rtems/deviceio.h
include_rtems_HEADERS += include/rtems/error.h
include_rtems_HEADERS += include/rtems/libcsupport.h
include_rtems_HEADERS += include/rtems/libio.h
@@ -127,6 +128,8 @@ libcsupport_a_SOURCES = src/gxx_wrappers.c src/getchark.c src/printk.c \
src/sup_fs_exist_in_same_instance.c \
src/sup_fs_mount_iterate.c \
src/sup_fs_node_type.c \
src/sup_fs_deviceio.c \
src/sup_fs_deviceerrno.c \
src/clonenode.c \
src/freenode.c \
$(BSD_LIBC_C_FILES) $(BASE_FS_C_FILES) $(MALLOC_C_FILES) \

View File

@@ -0,0 +1,56 @@
/*
* COPYRIGHT (c) 1989-2012.
* 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.com/license/LICENSE.
*/
#ifndef _RTEMS_DEVICEIO_H
#define _RTEMS_DEVICEIO_H
#include <rtems/libio.h>
int rtems_deviceio_errno( rtems_status_code status );
int rtems_deviceio_open(
rtems_libio_t *iop,
const char *path,
int oflag,
mode_t mode,
rtems_device_major_number major,
rtems_device_minor_number minor
);
int rtems_deviceio_close(
rtems_libio_t *iop,
rtems_device_major_number major,
rtems_device_minor_number minor
);
ssize_t rtems_deviceio_read(
rtems_libio_t *iop,
void *buf,
size_t nbyte,
rtems_device_major_number major,
rtems_device_minor_number minor
);
ssize_t rtems_deviceio_write(
rtems_libio_t *iop,
const void *buf,
size_t nbyte,
rtems_device_major_number major,
rtems_device_minor_number minor
);
int rtems_deviceio_control(
rtems_libio_t *iop,
ioctl_command_t command,
void *buffer,
rtems_device_major_number major,
rtems_device_minor_number minor
);
#endif /* _RTEMS_DEVICEIO_H */

View File

@@ -71,6 +71,10 @@ $(PROJECT_INCLUDE)/rtems/assoc.h: include/rtems/assoc.h $(PROJECT_INCLUDE)/rtems
$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/assoc.h
PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/assoc.h
$(PROJECT_INCLUDE)/rtems/deviceio.h: include/rtems/deviceio.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/deviceio.h
PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/deviceio.h
$(PROJECT_INCLUDE)/rtems/error.h: include/rtems/error.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/error.h
PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/error.h

View File

@@ -13,14 +13,12 @@
*/
#if HAVE_CONFIG_H
#include "config.h"
#include "config.h"
#endif
#include <errno.h>
#include <rtems/deviceio.h>
#include <rtems.h>
#include <rtems/libio.h>
#include <rtems/devfs.h>
#include <errno.h>
static const int status_code_to_errno [RTEMS_STATUS_CODES_LAST + 1] = {
[RTEMS_SUCCESSFUL] = 0,

View File

@@ -0,0 +1,128 @@
/*
* COPYRIGHT (c) 1989-2012.
* 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.com/license/LICENSE.
*/
#if HAVE_CONFIG_H
#include "config.h"
#endif
#include <rtems/deviceio.h>
int rtems_deviceio_open(
rtems_libio_t *iop,
const char *path,
int oflag,
mode_t mode,
rtems_device_major_number major,
rtems_device_minor_number minor
)
{
rtems_status_code status;
rtems_libio_open_close_args_t args;
args.iop = iop;
args.flags = iop->flags;
args.mode = mode;
status = rtems_io_open( major, minor, &args );
return rtems_deviceio_errno( status );
}
int rtems_deviceio_close(
rtems_libio_t *iop,
rtems_device_major_number major,
rtems_device_minor_number minor
)
{
rtems_status_code status;
rtems_libio_open_close_args_t args;
args.iop = iop;
args.flags = 0;
args.mode = 0;
status = rtems_io_close( major, minor, &args );
return rtems_deviceio_errno( status );
}
ssize_t rtems_deviceio_read(
rtems_libio_t *iop,
void *buf,
size_t nbyte,
rtems_device_major_number major,
rtems_device_minor_number minor
)
{
rtems_status_code status;
rtems_libio_rw_args_t args;
args.iop = iop;
args.offset = iop->offset;
args.buffer = buf;
args.count = nbyte;
args.flags = iop->flags;
args.bytes_moved = 0;
status = rtems_io_read( major, minor, &args );
if ( status == RTEMS_SUCCESSFUL ) {
return (ssize_t) args.bytes_moved;
} else {
return rtems_deviceio_errno( status );
}
}
ssize_t rtems_deviceio_write(
rtems_libio_t *iop,
const void *buf,
size_t nbyte,
rtems_device_major_number major,
rtems_device_minor_number minor
)
{
rtems_status_code status;
rtems_libio_rw_args_t args;
args.iop = iop;
args.offset = iop->offset;
args.buffer = buf;
args.count = nbyte;
args.flags = iop->flags;
args.bytes_moved = 0;
status = rtems_io_write( major, minor, &args );
if ( status == RTEMS_SUCCESSFUL ) {
return (ssize_t) args.bytes_moved;
} else {
return rtems_deviceio_errno( status );
}
}
int rtems_deviceio_control(
rtems_libio_t *iop,
ioctl_command_t command,
void *buffer,
rtems_device_major_number major,
rtems_device_minor_number minor
)
{
rtems_status_code status;
rtems_libio_ioctl_args_t args;
args.iop = iop;
args.command = command;
args.buffer = buffer;
status = rtems_io_control( major, minor, &args );
if ( status == RTEMS_SUCCESSFUL ) {
return args.ioctl_return;
} else {
return rtems_deviceio_errno(status);
}
}

View File

@@ -37,7 +37,7 @@ libdefaultfs_a_SOURCES = \
noinst_LIBRARIES += libimfs.a
libimfs_a_SOURCES =
libimfs_a_SOURCES += src/imfs/deviceerrno.c src/imfs/deviceio.c \
libimfs_a_SOURCES += src/imfs/deviceio.c \
src/imfs/fifoimfs_init.c src/imfs/imfs_chown.c src/imfs/imfs_config.c \
src/imfs/imfs_creat.c src/imfs/imfs_debug.c src/imfs/imfs_directory.c \
src/imfs/imfs_eval.c src/imfs/imfs_fchmod.c \

View File

@@ -5,33 +5,18 @@
*/
#if HAVE_CONFIG_H
#include "config.h"
#include "config.h"
#endif
#include <rtems.h>
#include <rtems/io.h>
#include "devfs.h"
#include <rtems/deviceio.h>
int devFS_close(
rtems_libio_t *iop
)
{
rtems_libio_open_close_args_t args;
rtems_status_code status;
const devFS_node *np = iop->pathinfo.node_access;
args.iop = iop;
args.flags = 0;
args.mode = 0;
status = rtems_io_close(
np->major,
np->minor,
(void *) &args
);
return rtems_deviceio_errno(status);
return rtems_deviceio_close( iop, np->major, np->minor );
}

View File

@@ -49,12 +49,6 @@ extern const rtems_filesystem_operations_table devFS_ops;
extern const rtems_filesystem_file_handlers_r devFS_file_handlers;
/**
* This routine associates RTEMS status code with errno
*/
extern int rtems_deviceio_errno(rtems_status_code code);
static inline const devFS_data *devFS_get_data(
const rtems_filesystem_location_info_t *loc
)

View File

@@ -1,41 +1,24 @@
#if HAVE_CONFIG_H
/*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rtems.com/license/LICENSE.
*/
#include "config.h"
#if HAVE_CONFIG_H
#include "config.h"
#endif
#include <rtems.h>
#include <rtems/io.h>
#include "devfs.h"
#include <rtems/deviceio.h>
int devFS_ioctl(
rtems_libio_t *iop,
ioctl_command_t command,
void *buffer
)
{
rtems_libio_ioctl_args_t args;
rtems_status_code status;
const devFS_node *np = iop->pathinfo.node_access;
args.iop = iop;
args.command = command;
args.buffer = buffer;
status = rtems_io_control(
np->major,
np->minor,
(void *) &args
);
if ( status )
return rtems_deviceio_errno(status);
return args.ioctl_return;
return rtems_deviceio_control( iop, command, buffer, np->major, np->minor );
}

View File

@@ -5,14 +5,13 @@
*/
#if HAVE_CONFIG_H
#include "config.h"
#include "config.h"
#endif
#include <rtems.h>
#include <rtems/io.h>
#include "devfs.h"
#include <rtems/deviceio.h>
int devFS_open(
rtems_libio_t *iop,
const char *pathname,
@@ -20,19 +19,14 @@ int devFS_open(
mode_t mode
)
{
rtems_libio_open_close_args_t args;
rtems_status_code status;
const devFS_node *np = iop->pathinfo.node_access;
args.iop = iop;
args.flags = iop->flags;
args.mode = mode;
status = rtems_io_open(
return rtems_deviceio_open(
iop,
pathname,
oflag,
mode,
np->major,
np->minor,
(void *) &args
np->minor
);
return rtems_deviceio_errno(status);
}

View File

@@ -5,40 +5,20 @@
*/
#if HAVE_CONFIG_H
#include "config.h"
#include "config.h"
#endif
#include <rtems.h>
#include <rtems/io.h>
#include "devfs.h"
#include <rtems/deviceio.h>
ssize_t devFS_read(
rtems_libio_t *iop,
void *buffer,
size_t count
)
{
rtems_libio_rw_args_t args;
rtems_status_code status;
const devFS_node *np = iop->pathinfo.node_access;
args.iop = iop;
args.offset = iop->offset;
args.buffer = buffer;
args.count = count;
args.flags = iop->flags;
args.bytes_moved = 0;
status = rtems_io_read(
np->major,
np->minor,
(void *) &args
);
if ( status )
return rtems_deviceio_errno(status);
return (ssize_t) args.bytes_moved;
return rtems_deviceio_read( iop, buffer, count, np->major, np->minor );
}

View File

@@ -5,40 +5,20 @@
*/
#if HAVE_CONFIG_H
#include "config.h"
#include "config.h"
#endif
#include <rtems.h>
#include <rtems/io.h>
#include "devfs.h"
#include <rtems/deviceio.h>
ssize_t devFS_write(
rtems_libio_t *iop,
const void *buffer,
size_t count
)
{
rtems_libio_rw_args_t args;
rtems_status_code status;
const devFS_node *np = iop->pathinfo.node_access;
args.iop = iop;
args.offset = iop->offset;
args.buffer = (void *) buffer;
args.count = count;
args.flags = iop->flags;
args.bytes_moved = 0;
status = rtems_io_write(
np->major,
np->minor,
(void *) &args
);
if ( status )
return rtems_deviceio_errno(status);
return (ssize_t) args.bytes_moved;
return rtems_deviceio_write( iop, buffer, count, np->major, np->minor );
}

View File

@@ -4,7 +4,7 @@
* This file contains the set of handlers used to map operations on
* IMFS device nodes onto calls to the RTEMS Classic API IO Manager.
*
* COPYRIGHT (c) 1989-2008.
* COPYRIGHT (c) 1989-2012.
* On-Line Applications Research Corporation (OAR).
*
* The license and distribution terms for this file may be
@@ -18,13 +18,7 @@
#include "imfs.h"
#include <rtems/devfs.h>
/*
* device_open
*
* This handler maps an open() operation onto rtems_io_open().
*/
#include <rtems/deviceio.h>
int device_open(
rtems_libio_t *iop,
@@ -33,174 +27,92 @@ int device_open(
mode_t mode
)
{
rtems_libio_open_close_args_t args;
rtems_status_code status;
IMFS_jnode_t *the_jnode;
the_jnode = iop->pathinfo.node_access;
args.iop = iop;
args.flags = iop->flags;
args.mode = mode;
status = rtems_io_open(
return rtems_deviceio_open(
iop,
pathname,
oflag,
mode,
the_jnode->info.device.major,
the_jnode->info.device.minor,
(void *) &args
the_jnode->info.device.minor
);
return rtems_deviceio_errno( status );
}
/*
* device_close
*
* This handler maps a close() operation onto rtems_io_close().
*/
int device_close(
rtems_libio_t *iop
)
{
rtems_libio_open_close_args_t args;
rtems_status_code status;
IMFS_jnode_t *the_jnode;
the_jnode = iop->pathinfo.node_access;
args.iop = iop;
args.flags = 0;
args.mode = 0;
status = rtems_io_close(
return rtems_deviceio_close(
iop,
the_jnode->info.device.major,
the_jnode->info.device.minor,
(void *) &args
the_jnode->info.device.minor
);
return rtems_deviceio_errno( status );
}
/*
* device_read
*
* This handler maps a read() operation onto rtems_io_read().
*/
ssize_t device_read(
rtems_libio_t *iop,
void *buffer,
size_t count
)
{
rtems_libio_rw_args_t args;
rtems_status_code status;
IMFS_jnode_t *the_jnode;
the_jnode = iop->pathinfo.node_access;
args.iop = iop;
args.offset = iop->offset;
args.buffer = buffer;
args.count = count;
args.flags = iop->flags;
args.bytes_moved = 0;
status = rtems_io_read(
return rtems_deviceio_read(
iop,
buffer,
count,
the_jnode->info.device.major,
the_jnode->info.device.minor,
(void *) &args
the_jnode->info.device.minor
);
if ( status )
return rtems_deviceio_errno(status);
return (ssize_t) args.bytes_moved;
}
/*
* device_write
*
* This handler maps a write() operation onto rtems_io_write().
*/
ssize_t device_write(
rtems_libio_t *iop,
const void *buffer,
size_t count
)
{
rtems_libio_rw_args_t args;
rtems_status_code status;
IMFS_jnode_t *the_jnode;
the_jnode = iop->pathinfo.node_access;
args.iop = iop;
args.offset = iop->offset;
args.buffer = (void *) buffer;
args.count = count;
args.flags = iop->flags;
args.bytes_moved = 0;
status = rtems_io_write(
return rtems_deviceio_write(
iop,
buffer,
count,
the_jnode->info.device.major,
the_jnode->info.device.minor,
(void *) &args
the_jnode->info.device.minor
);
if ( status )
return rtems_deviceio_errno(status);
return (ssize_t) args.bytes_moved;
}
/*
* device_ioctl
*
* This handler maps an ioctl() operation onto rtems_io_ioctl().
*/
int device_ioctl(
rtems_libio_t *iop,
ioctl_command_t command,
void *buffer
)
{
rtems_libio_ioctl_args_t args;
rtems_status_code status;
IMFS_jnode_t *the_jnode;
args.iop = iop;
args.command = command;
args.buffer = buffer;
the_jnode = iop->pathinfo.node_access;
status = rtems_io_control(
return rtems_deviceio_control(
iop,
command,
buffer,
the_jnode->info.device.major,
the_jnode->info.device.minor,
(void *) &args
the_jnode->info.device.minor
);
if ( status )
return rtems_deviceio_errno(status);
return args.ioctl_return;
}
/*
* device_stat
*
* The IMFS_stat() is used.
*/
/*
* device_rmnod
*
* The IMFS_rmnod() is used.
*/
int device_ftruncate(
rtems_libio_t *iop,
off_t length

View File

@@ -18,12 +18,13 @@
*/
#if HAVE_CONFIG_H
#include "config.h"
#include "config.h"
#endif
#include <rtems/devfs.h>
#include "rtems-rfs-rtems.h"
#include <rtems/deviceio.h>
static void
rtems_rfs_rtems_device_get_major_and_minor ( const rtems_libio_t *iop,
rtems_device_major_number *major,
@@ -48,13 +49,11 @@ rtems_rfs_rtems_device_open ( rtems_libio_t *iop,
int oflag,
mode_t mode)
{
rtems_libio_open_close_args_t args;
rtems_rfs_file_system* fs = rtems_rfs_rtems_pathloc_dev (&iop->pathinfo);
rtems_rfs_ino ino = rtems_rfs_rtems_get_iop_ino (iop);
rtems_rfs_inode_handle inode;
rtems_device_major_number major;
rtems_device_minor_number minor;
rtems_status_code status;
int rc;
rtems_rfs_rtems_lock (fs);
@@ -81,13 +80,7 @@ rtems_rfs_rtems_device_open ( rtems_libio_t *iop,
iop->data0 = major;
iop->data1 = (void *) minor;
args.iop = iop;
args.flags = iop->flags;
args.mode = mode;
status = rtems_io_open (major, minor, (void *) &args);
return rtems_deviceio_errno (status);
return rtems_deviceio_open (iop, pathname, oflag, mode, minor, major);
}
/**
@@ -100,20 +93,12 @@ rtems_rfs_rtems_device_open ( rtems_libio_t *iop,
static int
rtems_rfs_rtems_device_close (rtems_libio_t* iop)
{
rtems_libio_open_close_args_t args;
rtems_status_code status;
rtems_device_major_number major;
rtems_device_minor_number minor;
rtems_rfs_rtems_device_get_major_and_minor (iop, &major, &minor);
args.iop = iop;
args.flags = 0;
args.mode = 0;
status = rtems_io_close (major, minor, (void *) &args);
return rtems_deviceio_errno (status);
return rtems_deviceio_close (iop, major, minor);
}
/**
@@ -128,25 +113,12 @@ rtems_rfs_rtems_device_close (rtems_libio_t* iop)
static ssize_t
rtems_rfs_rtems_device_read (rtems_libio_t* iop, void* buffer, size_t count)
{
rtems_libio_rw_args_t args;
rtems_status_code status;
rtems_device_major_number major;
rtems_device_minor_number minor;
rtems_rfs_rtems_device_get_major_and_minor (iop, &major, &minor);
args.iop = iop;
args.offset = iop->offset;
args.buffer = buffer;
args.count = count;
args.flags = iop->flags;
args.bytes_moved = 0;
status = rtems_io_read (major, minor, (void *) &args);
if (status)
return rtems_deviceio_errno (status);
return (ssize_t) args.bytes_moved;
return rtems_deviceio_read (iop, buffer, count, major, minor);
}
/*
@@ -163,25 +135,12 @@ rtems_rfs_rtems_device_write (rtems_libio_t* iop,
const void* buffer,
size_t count)
{
rtems_libio_rw_args_t args;
rtems_status_code status;
rtems_device_major_number major;
rtems_device_minor_number minor;
rtems_rfs_rtems_device_get_major_and_minor (iop, &major, &minor);
args.iop = iop;
args.offset = iop->offset;
args.buffer = (void *) buffer;
args.count = count;
args.flags = iop->flags;
args.bytes_moved = 0;
status = rtems_io_write (major, minor, (void *) &args);
if (status)
return rtems_deviceio_errno (status);
return (ssize_t) args.bytes_moved;
return rtems_deviceio_write (iop, buffer, count, major, minor);
}
/**
@@ -198,22 +157,12 @@ rtems_rfs_rtems_device_ioctl (rtems_libio_t* iop,
ioctl_command_t command,
void* buffer)
{
rtems_libio_ioctl_args_t args;
rtems_status_code status;
rtems_device_major_number major;
rtems_device_minor_number minor;
rtems_rfs_rtems_device_get_major_and_minor (iop, &major, &minor);
args.iop = iop;
args.command = command;
args.buffer = buffer;
status = rtems_io_control (major, minor, (void *) &args);
if (status)
return rtems_deviceio_errno (status);
return args.ioctl_return;
return rtems_deviceio_control (iop, command, buffer, major, minor);
}
/**