diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2012-05-14 15:19:20 +0200 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2012-05-15 10:01:42 +0200 |
commit | fed66f991014f40430b256d44231a7828bb8a413 (patch) | |
tree | 776084d409f4c21ed84c1c2da4d65993f10ef588 /cpukit/libcsupport | |
parent | Filesystem: Use ioctl_command_t (diff) | |
download | rtems-fed66f991014f40430b256d44231a7828bb8a413.tar.bz2 |
Filesystem: Add shared device IO support
The device IO file system support in IMFS, devFS, and RFS uses now a
shared implementation.
Diffstat (limited to 'cpukit/libcsupport')
-rw-r--r-- | cpukit/libcsupport/Makefile.am | 3 | ||||
-rw-r--r-- | cpukit/libcsupport/include/rtems/deviceio.h | 56 | ||||
-rw-r--r-- | cpukit/libcsupport/preinstall.am | 4 | ||||
-rw-r--r-- | cpukit/libcsupport/src/sup_fs_deviceerrno.c | 70 | ||||
-rw-r--r-- | cpukit/libcsupport/src/sup_fs_deviceio.c | 128 |
5 files changed, 261 insertions, 0 deletions
diff --git a/cpukit/libcsupport/Makefile.am b/cpukit/libcsupport/Makefile.am index 1d6fa3b50c..46805e9080 100644 --- a/cpukit/libcsupport/Makefile.am +++ b/cpukit/libcsupport/Makefile.am @@ -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) \ diff --git a/cpukit/libcsupport/include/rtems/deviceio.h b/cpukit/libcsupport/include/rtems/deviceio.h new file mode 100644 index 0000000000..6ce5d105b4 --- /dev/null +++ b/cpukit/libcsupport/include/rtems/deviceio.h @@ -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 */ diff --git a/cpukit/libcsupport/preinstall.am b/cpukit/libcsupport/preinstall.am index f71362fe31..eb68f50fa4 100644 --- a/cpukit/libcsupport/preinstall.am +++ b/cpukit/libcsupport/preinstall.am @@ -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 diff --git a/cpukit/libcsupport/src/sup_fs_deviceerrno.c b/cpukit/libcsupport/src/sup_fs_deviceerrno.c new file mode 100644 index 0000000000..4316496561 --- /dev/null +++ b/cpukit/libcsupport/src/sup_fs_deviceerrno.c @@ -0,0 +1,70 @@ +/* + * IMFS Device Node Handlers + * + * 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. + * 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> + +#include <errno.h> + +static const int status_code_to_errno [RTEMS_STATUS_CODES_LAST + 1] = { + [RTEMS_SUCCESSFUL] = 0, + [RTEMS_TASK_EXITTED] = EIO, + [RTEMS_MP_NOT_CONFIGURED] = EIO, + [RTEMS_INVALID_NAME] = EINVAL, + [RTEMS_INVALID_ID] = EIO, + [RTEMS_TOO_MANY] = EIO, + [RTEMS_TIMEOUT] = ETIMEDOUT, + [RTEMS_OBJECT_WAS_DELETED] = EIO, + [RTEMS_INVALID_SIZE] = EIO, + [RTEMS_INVALID_ADDRESS] = EIO, + [RTEMS_INVALID_NUMBER] = EBADF, + [RTEMS_NOT_DEFINED] = EIO, + [RTEMS_RESOURCE_IN_USE] = EBUSY, + [RTEMS_UNSATISFIED] = ENODEV, + [RTEMS_INCORRECT_STATE] = EIO, + [RTEMS_ALREADY_SUSPENDED] = EIO, + [RTEMS_ILLEGAL_ON_SELF] = EIO, + [RTEMS_ILLEGAL_ON_REMOTE_OBJECT] = EIO, + [RTEMS_CALLED_FROM_ISR] = EIO, + [RTEMS_INVALID_PRIORITY] = EIO, + [RTEMS_INVALID_CLOCK] = EINVAL, + [RTEMS_INVALID_NODE] = EINVAL, + [RTEMS_NOT_CONFIGURED] = ENOSYS, + [RTEMS_NOT_OWNER_OF_RESOURCE] = EPERM, + [RTEMS_NOT_IMPLEMENTED] = ENOSYS, + [RTEMS_INTERNAL_ERROR] = EIO, + [RTEMS_NO_MEMORY] = ENOMEM, + [RTEMS_IO_ERROR] = EIO, + [RTEMS_PROXY_BLOCKING] = EIO +}; + +int rtems_deviceio_errno(rtems_status_code sc) +{ + if (sc == RTEMS_SUCCESSFUL) { + return 0; + } else { + int eno = EINVAL; + + if ((unsigned) sc <= RTEMS_STATUS_CODES_LAST) { + eno = status_code_to_errno [sc]; + } + + errno = eno; + + return -1; + } +} diff --git a/cpukit/libcsupport/src/sup_fs_deviceio.c b/cpukit/libcsupport/src/sup_fs_deviceio.c new file mode 100644 index 0000000000..aeff60ea83 --- /dev/null +++ b/cpukit/libcsupport/src/sup_fs_deviceio.c @@ -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); + } +} |