[rtems commit] libblock: Split file and simplify

Joel Sherrill joel at rtems.org
Thu Mar 29 14:14:30 UTC 2012


Module:    rtems
Branch:    master
Commit:    dfef6e4478749ad1b50f91069201b1c21766e1b8
Changeset: http://git.rtems.org/rtems/commit/?id=dfef6e4478749ad1b50f91069201b1c21766e1b8

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Mon Mar  5 14:39:53 2012 +0100

libblock: Split file and simplify

---

 cpukit/libblock/Makefile.am        |    1 +
 cpukit/libblock/src/blkdev-ioctl.c |   71 +++++++++++++++++++++++++++++
 cpukit/libblock/src/blkdev.c       |   88 +++++-------------------------------
 3 files changed, 83 insertions(+), 77 deletions(-)

diff --git a/cpukit/libblock/Makefile.am b/cpukit/libblock/Makefile.am
index 04eca6f..0311319 100644
--- a/cpukit/libblock/Makefile.am
+++ b/cpukit/libblock/Makefile.am
@@ -8,6 +8,7 @@ include $(top_srcdir)/automake/compile.am
 noinst_LIBRARIES = libblock.a
 libblock_a_SOURCES = src/bdbuf.c \
     src/blkdev.c \
+    src/blkdev-ioctl.c \
     src/blkdev-ops.c \
     src/diskdevs.c \
     src/flashdisk.c \
diff --git a/cpukit/libblock/src/blkdev-ioctl.c b/cpukit/libblock/src/blkdev-ioctl.c
new file mode 100644
index 0000000..296f379
--- /dev/null
+++ b/cpukit/libblock/src/blkdev-ioctl.c
@@ -0,0 +1,71 @@
+/**
+ * @file
+ *
+ * @ingroup rtems_blkdev
+ *
+ * Block device management.
+ */
+
+/*
+ * Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia
+ * Author: Victor V. Vengerov <vvv at oktet.ru>
+ */
+
+#if HAVE_CONFIG_H
+  #include "config.h"
+#endif
+
+#include <errno.h>
+
+#include <rtems/blkdev.h>
+#include <rtems/bdbuf.h>
+
+int
+rtems_blkdev_ioctl(rtems_disk_device *dd, uint32_t req, void *argp)
+{
+    size_t            *arg_size = argp;
+    int                rc = 0;
+
+    switch (req)
+    {
+        case RTEMS_BLKIO_GETMEDIABLKSIZE:
+            *arg_size = dd->media_block_size;
+            break;
+
+        case RTEMS_BLKIO_GETBLKSIZE:
+            *arg_size = dd->block_size;
+            break;
+
+        case RTEMS_BLKIO_SETBLKSIZE:
+            dd->block_size = *arg_size;
+            break;
+
+        case RTEMS_BLKIO_GETSIZE:
+            *arg_size = dd->size;
+            break;
+
+        case RTEMS_BLKIO_SYNCDEV:
+        {
+            rtems_status_code sc = rtems_bdbuf_syncdev(dd);
+            if (sc != RTEMS_SUCCESSFUL) {
+                errno = EIO;
+                rc = -1;
+            }
+            break;
+        }
+
+        case RTEMS_BLKIO_GETDISKDEV:
+        {
+            rtems_disk_device **dd_ptr = argp;
+            *dd_ptr = dd;
+            break;
+        }
+
+        default:
+            errno = EINVAL;
+            rc = -1;
+            break;
+    }
+
+    return rc;
+}
diff --git a/cpukit/libblock/src/blkdev.c b/cpukit/libblock/src/blkdev.c
index 3e950d6..83ea563 100644
--- a/cpukit/libblock/src/blkdev.c
+++ b/cpukit/libblock/src/blkdev.c
@@ -180,87 +180,21 @@ rtems_blkdev_generic_ioctl(
     rtems_libio_ioctl_args_t *args = arg;
     rtems_libio_t *iop = args->iop;
     rtems_disk_device *dd = iop->data1;
-    int rc;
 
-    switch (args->command)
+    if (args->command != RTEMS_BLKIO_REQUEST)
     {
-        case RTEMS_BLKIO_GETMEDIABLKSIZE:
-            *((uint32_t *) args->buffer) = dd->media_block_size;
-            args->ioctl_return = 0;
-            break;
-
-        case RTEMS_BLKIO_GETBLKSIZE:
-            *((uint32_t *) args->buffer) = dd->block_size;
-            args->ioctl_return = 0;
-            break;
-
-        case RTEMS_BLKIO_SETBLKSIZE:
-            dd->block_size = *((uint32_t *) args->buffer);
-            args->ioctl_return = 0;
-            break;
-
-        case RTEMS_BLKIO_GETSIZE:
-            *((rtems_blkdev_bnum *) args->buffer) = dd->size;
-            args->ioctl_return = 0;
-            break;
-
-        case RTEMS_BLKIO_SYNCDEV:
-            rc = rtems_bdbuf_syncdev(dd);
-            args->ioctl_return = (uint32_t) (rc == RTEMS_SUCCESSFUL ? 0 : -1);
-            break;
-
-        case RTEMS_BLKIO_GETDISKDEV:
-            *((rtems_disk_device **) args->buffer) = dd;
-            args->ioctl_return = 0;
-            break;
-
-        case RTEMS_BLKIO_REQUEST:
-            /*
-             * It is not allowed to directly access the driver circumventing
-             * the cache.
-             */
-            args->ioctl_return = (uint32_t) -1;
-            break;
-
-        default:
-            args->ioctl_return = (uint32_t) dd->ioctl(dd->phys_dev,
-                                                      args->command,
-                                                      args->buffer);
-            break;
+        args->ioctl_return = (uint32_t) dd->ioctl(dd,
+                                                  args->command,
+                                                  args->buffer);
     }
-
-    return RTEMS_SUCCESSFUL;
-}
-
-int
-rtems_blkdev_ioctl(rtems_disk_device *dd, uint32_t req, void *argp)
-{
-    size_t            *arg_size = argp;
-    int                rc = 0;
-
-    switch (req)
+    else
     {
-        case RTEMS_BLKIO_GETMEDIABLKSIZE:
-            *arg_size = dd->media_block_size;
-            break;
-
-        case RTEMS_BLKIO_GETBLKSIZE:
-            *arg_size = dd->block_size;
-            break;
-
-        case RTEMS_BLKIO_SETBLKSIZE:
-            dd->block_size = *arg_size;
-            break;
-
-        case RTEMS_BLKIO_GETSIZE:
-            *arg_size = dd->size;
-            break;
-
-        default:
-            errno = EINVAL;
-            rc = -1;
-            break;
+        /*
+         * It is not allowed to directly access the driver circumventing the
+         * cache.
+         */
+        args->ioctl_return = (uint32_t) -1;
     }
 
-    return rc;
+    return RTEMS_SUCCESSFUL;
 }




More information about the vc mailing list