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/src | |
parent | df01da67078b4ed4787680d3987f5b40ac93d080 (diff) |
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/src')
-rw-r--r-- | cpukit/libcsupport/src/sup_fs_deviceerrno.c | 70 | ||||
-rw-r--r-- | cpukit/libcsupport/src/sup_fs_deviceio.c | 128 |
2 files changed, 198 insertions, 0 deletions
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); + } +} |