[rtems commit] libblock: New block IO control support functions
Joel Sherrill
joel at rtems.org
Thu Mar 29 14:14:30 UTC 2012
Module: rtems
Branch: master
Commit: 585988738fc2f8a0f57c372486bde49024a919e8
Changeset: http://git.rtems.org/rtems/commit/?id=585988738fc2f8a0f57c372486bde49024a919e8
Author: Sebastian Huber <sebastian.huber at embedded-brains.de>
Date: Tue Feb 28 13:28:42 2012 +0100
libblock: New block IO control support functions
---
cpukit/libblock/include/rtems/blkdev.h | 39 +++++++++++++++
cpukit/libmisc/shell/main_blksync.c | 2 +-
testsuites/libtests/block01/init.c | 80 +++++++++++++++++++++++++++++--
3 files changed, 114 insertions(+), 7 deletions(-)
diff --git a/cpukit/libblock/include/rtems/blkdev.h b/cpukit/libblock/include/rtems/blkdev.h
index 978e930..70259d6 100644
--- a/cpukit/libblock/include/rtems/blkdev.h
+++ b/cpukit/libblock/include/rtems/blkdev.h
@@ -165,6 +165,45 @@ typedef struct rtems_blkdev_request {
/** @} */
+static inline int rtems_disk_fd_get_media_block_size(
+ int fd,
+ uint32_t *media_block_size
+)
+{
+ return ioctl(fd, RTEMS_BLKIO_GETMEDIABLKSIZE, media_block_size);
+}
+
+static inline int rtems_disk_fd_get_block_size(int fd, uint32_t *block_size)
+{
+ return ioctl(fd, RTEMS_BLKIO_GETBLKSIZE, block_size);
+}
+
+static inline int rtems_disk_fd_set_block_size(int fd, uint32_t block_size)
+{
+ return ioctl(fd, RTEMS_BLKIO_SETBLKSIZE, &block_size);
+}
+
+static inline int rtems_disk_fd_get_block_count(
+ int fd,
+ rtems_blkdev_bnum *block_count
+)
+{
+ return ioctl(fd, RTEMS_BLKIO_GETSIZE, block_count);
+}
+
+static inline int rtems_disk_fd_get_disk_device(
+ int fd,
+ const rtems_disk_device **dd_ptr
+)
+{
+ return ioctl(fd, RTEMS_BLKIO_GETDISKDEV, dd_ptr);
+}
+
+static inline int rtems_disk_fd_sync(int fd)
+{
+ return ioctl(fd, RTEMS_BLKIO_SYNCDEV);
+}
+
/**
* Only consecutive multi-sector buffer requests are supported.
*
diff --git a/cpukit/libmisc/shell/main_blksync.c b/cpukit/libmisc/shell/main_blksync.c
index c3739c6..c8859b4 100644
--- a/cpukit/libmisc/shell/main_blksync.c
+++ b/cpukit/libmisc/shell/main_blksync.c
@@ -58,7 +58,7 @@ static int rtems_shell_main_blksync(
return 1;
}
- if (ioctl (fd, RTEMS_BLKIO_SYNCDEV) < 0) {
+ if (rtems_disk_fd_sync (fd) < 0) {
fprintf( stderr, "%s: driver sync failed: %s\n", argv[0], strerror (errno));
return 1;
}
diff --git a/testsuites/libtests/block01/init.c b/testsuites/libtests/block01/init.c
index 4b7720b..9e96cee 100644
--- a/testsuites/libtests/block01/init.c
+++ b/testsuites/libtests/block01/init.c
@@ -7,12 +7,13 @@
*/
/*
- * Copyright (c) 2009
- * embedded brains GmbH
- * Obere Lagerstr. 30
- * D-82178 Puchheim
- * Germany
- * <rtems at embedded-brains.de>
+ * Copyright (c) 2009-2012 embedded brains GmbH. All rights reserved.
+ *
+ * embedded brains GmbH
+ * Obere Lagerstr. 30
+ * 82178 Puchheim
+ * Germany
+ * <rtems at embedded-brains.de>
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
@@ -25,7 +26,9 @@
#include "config.h"
#endif
+#include <sys/stat.h>
#include <stdio.h>
+#include <fcntl.h>
#include "tmacros.h"
#include <rtems.h>
@@ -40,6 +43,66 @@
#define BLOCK_COUNT 16U
+static void test_block_io_control_api(dev_t dev, ramdisk *rd)
+{
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+ rtems_disk_device *dd = NULL;
+ const rtems_disk_device *fd_dd = NULL;
+ int fd = -1;
+ int rv = -1;
+ uint32_t value = 0;
+ rtems_blkdev_bnum block_count = 0;
+
+ sc = rtems_disk_create_phys(dev, BLOCK_SIZE, BLOCK_COUNT, ramdisk_ioctl, rd, "/dev/rda");
+ ASSERT_SC(sc);
+
+ dd = rtems_disk_obtain(dev);
+ rtems_test_assert(dd != NULL);
+
+ fd = open("/dev/rda", O_RDWR);
+ rtems_test_assert(fd >= 0);
+
+ value = 0;
+ rv = rtems_disk_fd_get_media_block_size(fd, &value);
+ rtems_test_assert(rv == 0);
+ rtems_test_assert(value == BLOCK_SIZE);
+
+ value = 0;
+ rv = rtems_disk_fd_get_block_size(fd, &value);
+ rtems_test_assert(rv == 0);
+ rtems_test_assert(value == BLOCK_SIZE);
+
+ value = 1024;
+ rv = rtems_disk_fd_set_block_size(fd, value);
+ rtems_test_assert(rv == 0);
+
+ value = 0;
+ rv = rtems_disk_fd_get_block_size(fd, &value);
+ rtems_test_assert(rv == 0);
+ rtems_test_assert(value == 1024);
+
+ block_count = 0;
+ rv = rtems_disk_fd_get_block_count(fd, &block_count);
+ rtems_test_assert(rv == 0);
+ rtems_test_assert(block_count == BLOCK_COUNT);
+
+ rv = rtems_disk_fd_get_disk_device(fd, &fd_dd);
+ rtems_test_assert(rv == 0);
+ rtems_test_assert(fd_dd == dd);
+
+ rv = rtems_disk_fd_sync(fd);
+ rtems_test_assert(rv == 0);
+
+ rv = close(fd);
+ rtems_test_assert(rv == 0);
+
+ sc = rtems_disk_release(dd);
+ ASSERT_SC(sc);
+
+ sc = rtems_disk_delete(dev);
+ ASSERT_SC(sc);
+}
+
static void test_diskdevs(void)
{
rtems_status_code sc = RTEMS_SUCCESSFUL;
@@ -154,6 +217,10 @@ static void test_diskdevs(void)
sc = rtems_disk_release(logical_dd);
ASSERT_SC(sc);
+ /* Test block IO control API */
+
+ test_block_io_control_api(physical_dev, rd);
+
/* Cleanup */
sc = rtems_io_unregister_driver(major);
@@ -183,6 +250,7 @@ static rtems_task Init(rtems_task_argument argument)
#define CONFIGURE_APPLICATION_NEEDS_LIBBLOCK
#define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM
+#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 4
#define CONFIGURE_MAXIMUM_TASKS 2
#define CONFIGURE_MAXIMUM_DRIVERS 2
More information about the vc
mailing list