[PATCH 1/3] Filesystem: Add shared device IO support

sebastian.huber at embedded-brains.de sebastian.huber at embedded-brains.de
Mon May 14 15:13:36 UTC 2012


From: Sebastian Huber <sebastian.huber at embedded-brains.de>

The device IO file system support in IMFS, devFS, and RFS uses now a
shared implementation.
---
 cpukit/libcsupport/Makefile.am              |    3 +
 cpukit/libcsupport/include/rtems/deviceio.h |   56 +++++++++++
 cpukit/libcsupport/preinstall.am            |    4 +
 cpukit/libcsupport/src/sup_fs_deviceerrno.c |   70 +++++++++++++
 cpukit/libcsupport/src/sup_fs_deviceio.c    |  128 ++++++++++++++++++++++++
 cpukit/libfs/Makefile.am                    |    2 +-
 cpukit/libfs/src/devfs/devclose.c           |   23 +----
 cpukit/libfs/src/devfs/devfs.h              |    6 -
 cpukit/libfs/src/devfs/devioctl.c           |   27 +----
 cpukit/libfs/src/devfs/devopen.c            |   24 ++---
 cpukit/libfs/src/devfs/devread.c            |   28 +-----
 cpukit/libfs/src/devfs/devwrite.c           |   28 +-----
 cpukit/libfs/src/imfs/deviceerrno.c         |   72 --------------
 cpukit/libfs/src/imfs/deviceio.c            |  140 +++++----------------------
 cpukit/libfs/src/rfs/rtems-rfs-rtems-dev.c  |   67 ++-----------
 15 files changed, 322 insertions(+), 356 deletions(-)
 create mode 100644 cpukit/libcsupport/include/rtems/deviceio.h
 create mode 100644 cpukit/libcsupport/src/sup_fs_deviceerrno.c
 create mode 100644 cpukit/libcsupport/src/sup_fs_deviceio.c
 delete mode 100644 cpukit/libfs/src/imfs/deviceerrno.c

diff --git a/cpukit/libcsupport/Makefile.am b/cpukit/libcsupport/Makefile.am
index 1d6fa3b..46805e9 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 0000000..6ce5d10
--- /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 f71362f..eb68f50 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 0000000..4316496
--- /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 0000000..aeff60e
--- /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);
+  }
+}
diff --git a/cpukit/libfs/Makefile.am b/cpukit/libfs/Makefile.am
index 9a792d1..c5e483e 100644
--- a/cpukit/libfs/Makefile.am
+++ b/cpukit/libfs/Makefile.am
@@ -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 \
diff --git a/cpukit/libfs/src/devfs/devclose.c b/cpukit/libfs/src/devfs/devclose.c
index c83fab9..83646c7 100644
--- a/cpukit/libfs/src/devfs/devclose.c
+++ b/cpukit/libfs/src/devfs/devclose.c
@@ -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 );
 }
-
-
diff --git a/cpukit/libfs/src/devfs/devfs.h b/cpukit/libfs/src/devfs/devfs.h
index 60ee7ab..4155dd6 100644
--- a/cpukit/libfs/src/devfs/devfs.h
+++ b/cpukit/libfs/src/devfs/devfs.h
@@ -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
 )
diff --git a/cpukit/libfs/src/devfs/devioctl.c b/cpukit/libfs/src/devfs/devioctl.c
index bca8250..e1d62c4 100644
--- a/cpukit/libfs/src/devfs/devioctl.c
+++ b/cpukit/libfs/src/devfs/devioctl.c
@@ -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 );
 }
-
diff --git a/cpukit/libfs/src/devfs/devopen.c b/cpukit/libfs/src/devfs/devopen.c
index adb8fe4..26450ab 100644
--- a/cpukit/libfs/src/devfs/devopen.c
+++ b/cpukit/libfs/src/devfs/devopen.c
@@ -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);
 }
diff --git a/cpukit/libfs/src/devfs/devread.c b/cpukit/libfs/src/devfs/devread.c
index 6868a9e..25d69b0 100644
--- a/cpukit/libfs/src/devfs/devread.c
+++ b/cpukit/libfs/src/devfs/devread.c
@@ -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 );
 }
-
diff --git a/cpukit/libfs/src/devfs/devwrite.c b/cpukit/libfs/src/devfs/devwrite.c
index fe48745..57e7fdb 100644
--- a/cpukit/libfs/src/devfs/devwrite.c
+++ b/cpukit/libfs/src/devfs/devwrite.c
@@ -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 );
 }
-
diff --git a/cpukit/libfs/src/imfs/deviceerrno.c b/cpukit/libfs/src/imfs/deviceerrno.c
deleted file mode 100644
index eb5e03d..0000000
--- a/cpukit/libfs/src/imfs/deviceerrno.c
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- *  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 <errno.h>
-
-#include <rtems.h>
-#include <rtems/libio.h>
-#include <rtems/devfs.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/libfs/src/imfs/deviceio.c b/cpukit/libfs/src/imfs/deviceio.c
index 60a66f3..679f945 100644
--- a/cpukit/libfs/src/imfs/deviceio.c
+++ b/cpukit/libfs/src/imfs/deviceio.c
@@ -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
diff --git a/cpukit/libfs/src/rfs/rtems-rfs-rtems-dev.c b/cpukit/libfs/src/rfs/rtems-rfs-rtems-dev.c
index 729d420..ced234a 100644
--- a/cpukit/libfs/src/rfs/rtems-rfs-rtems-dev.c
+++ b/cpukit/libfs/src/rfs/rtems-rfs-rtems-dev.c
@@ -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);
 }
 
 /**
-- 
1.6.4.2




More information about the devel mailing list