[PATCH 01/21] ramdisk: Use rtems_blkdev_create()
Sebastian Huber
sebastian.huber at embedded-brains.de
Mon Aug 6 07:14:33 UTC 2018
Update #3358.
---
cpukit/include/rtems/ramdisk.h | 9 +--
cpukit/libblock/src/ramdisk-config.c | 11 +---
cpukit/libblock/src/ramdisk-register.c | 30 ++--------
testsuites/fstests/fsdosfsname01/init.c | 35 +----------
testsuites/fstests/mdosfs_support/fs_support.c | 1 -
testsuites/fstests/mrfs_support/fs_support.c | 1 -
testsuites/fstests/support/ramdisk_support.c | 27 ++-------
testsuites/libtests/block01/init.c | 12 ++--
testsuites/libtests/block02/init.c | 57 +++++++++++-------
testsuites/libtests/block03/init.c | 49 ++++++++++-----
testsuites/libtests/block04/init.c | 49 ++++++++++-----
testsuites/libtests/block07/init.c | 53 +++++++++-------
testsuites/samples/fileio/init.c | 83 ++++++++------------------
13 files changed, 181 insertions(+), 236 deletions(-)
diff --git a/cpukit/include/rtems/ramdisk.h b/cpukit/include/rtems/ramdisk.h
index 727efddbe8..dcc60483dd 100644
--- a/cpukit/include/rtems/ramdisk.h
+++ b/cpukit/include/rtems/ramdisk.h
@@ -84,8 +84,8 @@ rtems_device_driver ramdisk_initialize(
*/
#define RAMDISK_DRIVER_TABLE_ENTRY \
{ \
- .initialization_entry = ramdisk_initialize, \
- RTEMS_GENERIC_BLOCK_DEVICE_DRIVER_ENTRIES \
+ ramdisk_initialize, \
+ NULL, NULL, NULL, NULL, NULL \
}
#define RAMDISK_DEVICE_BASE_NAME "/dev/rd"
@@ -137,8 +137,6 @@ typedef struct ramdisk {
bool free_at_delete_request;
} ramdisk;
-extern const rtems_driver_address_table ramdisk_ops;
-
int ramdisk_ioctl(rtems_disk_device *dd, uint32_t req, void *argp);
/**
@@ -212,8 +210,7 @@ rtems_status_code ramdisk_register(
uint32_t media_block_size,
rtems_blkdev_bnum media_block_count,
bool trace,
- const char *disk,
- dev_t *dev
+ const char *disk
);
/** @} */
diff --git a/cpukit/libblock/src/ramdisk-config.c b/cpukit/libblock/src/ramdisk-config.c
index 7bd137a394..8e1b277674 100644
--- a/cpukit/libblock/src/ramdisk-config.c
+++ b/cpukit/libblock/src/ramdisk-config.c
@@ -23,7 +23,7 @@
rtems_device_driver
ramdisk_initialize(
- rtems_device_major_number major,
+ rtems_device_major_number major RTEMS_UNUSED,
rtems_device_minor_number minor RTEMS_UNUSED,
void *arg RTEMS_UNUSED)
{
@@ -32,10 +32,6 @@ ramdisk_initialize(
struct ramdisk *r;
rtems_status_code rc;
- rc = rtems_disk_io_initialize();
- if (rc != RTEMS_SUCCESSFUL)
- return rc;
-
/*
* Coverity Id 27 notes that this calloc() is a resource leak.
*
@@ -48,7 +44,6 @@ ramdisk_initialize(
r->trace = false;
for (i = 0; i < rtems_ramdisk_configuration_size; i++, c++, r++)
{
- dev_t dev = rtems_filesystem_make_dev_t(major, i);
char name [] = RAMDISK_DEVICE_BASE_NAME "a";
name [sizeof(RAMDISK_DEVICE_BASE_NAME) - 1] += i;
r->block_size = c->block_size;
@@ -73,8 +68,8 @@ ramdisk_initialize(
r->initialized = true;
r->area = c->location;
}
- rc = rtems_disk_create_phys(dev, c->block_size, c->block_num,
- ramdisk_ioctl, r, name);
+ rc = rtems_blkdev_create(name, c->block_size, c->block_num,
+ ramdisk_ioctl, r);
if (rc != RTEMS_SUCCESSFUL)
{
if (r->malloced)
diff --git a/cpukit/libblock/src/ramdisk-register.c b/cpukit/libblock/src/ramdisk-register.c
index ec133d0c03..6b2dc2c36d 100644
--- a/cpukit/libblock/src/ramdisk-register.c
+++ b/cpukit/libblock/src/ramdisk-register.c
@@ -24,57 +24,35 @@
#include "config.h"
#endif
-#include <rtems.h>
#include <rtems/ramdisk.h>
-const rtems_driver_address_table ramdisk_ops = {
- .initialization_entry = NULL,
- RTEMS_GENERIC_BLOCK_DEVICE_DRIVER_ENTRIES
-};
-
rtems_status_code ramdisk_register(
uint32_t media_block_size,
rtems_blkdev_bnum media_block_count,
bool trace,
- const char *disk,
- dev_t *dev_ptr
+ const char *disk
)
{
rtems_status_code sc = RTEMS_SUCCESSFUL;
- rtems_device_major_number major = 0;
ramdisk *rd = NULL;
- dev_t dev = 0;
-
- sc = rtems_io_register_driver(0, &ramdisk_ops, &major);
- if (sc != RTEMS_SUCCESSFUL) {
- return RTEMS_UNSATISFIED;
- }
rd = ramdisk_allocate(NULL, media_block_size, media_block_count, trace);
if (rd == NULL) {
- rtems_io_unregister_driver(major);
-
return RTEMS_UNSATISFIED;
}
- dev = rtems_filesystem_make_dev_t(major, 0);
-
- sc = rtems_disk_create_phys(
- dev,
+ sc = rtems_blkdev_create(
+ disk,
media_block_size,
media_block_count,
ramdisk_ioctl,
- rd,
- disk
+ rd
);
if (sc != RTEMS_SUCCESSFUL) {
ramdisk_free(rd);
- rtems_io_unregister_driver(major);
return RTEMS_UNSATISFIED;
}
- *dev_ptr = dev;
-
return RTEMS_SUCCESSFUL;
}
diff --git a/testsuites/fstests/fsdosfsname01/init.c b/testsuites/fstests/fsdosfsname01/init.c
index ce6850cfa7..90db282955 100644
--- a/testsuites/fstests/fsdosfsname01/init.c
+++ b/testsuites/fstests/fsdosfsname01/init.c
@@ -63,18 +63,6 @@ static const char UTF8_BOM[] = {0xEF, 0xBB, 0xBF};
#define BLOCK_SIZE 512
-#define BLOCK_COUNT ( sizeof( image_bin ) / BLOCK_SIZE )
-
-static ramdisk disk_image = {
- .block_size = BLOCK_SIZE,
- .block_num = BLOCK_COUNT,
- .area = &image_bin[0],
- .initialized = true,
- .malloced = false,
- .trace = false,
- .free_at_delete_request = false
-};
-
static rtems_resource_snapshot before_mount;
static const msdos_format_request_param_t rqdata = {
@@ -981,11 +969,8 @@ static void compare_image(
static void test_compatibility( void )
{
int rc;
- rtems_status_code sc;
- dev_t dev;
- char diskpath[] = "/dev/ramdisk1";
+ char diskpath[] = "/dev/rdd";
rtems_dosfs_mount_options mount_opts;
- rtems_device_major_number major;
FILE *fp;
int buffer;
unsigned int index_file = 0;
@@ -1002,20 +987,6 @@ static void test_compatibility( void )
mount_opts.converter = rtems_dosfs_create_utf8_converter( "CP850" );
rtems_test_assert( mount_opts.converter != NULL );
- sc = rtems_io_register_driver( 0, &ramdisk_ops, &major );
- rtems_test_assert( sc == RTEMS_SUCCESSFUL );
-
- dev = rtems_filesystem_make_dev_t( major, 1 );
-
- sc = rtems_disk_create_phys(
- dev,
- BLOCK_SIZE,
- BLOCK_COUNT,
- ramdisk_ioctl,
- &disk_image,
- diskpath );
- rtems_test_assert( sc == RTEMS_SUCCESSFUL );
-
rc = mount_and_make_target_path(
diskpath,
MOUNT_DIR,
@@ -1416,7 +1387,8 @@ static void Init( rtems_task_argument arg )
rtems_ramdisk_config rtems_ramdisk_configuration [] = {
{ .block_size = BLOCK_SIZE, .block_num = BLOCK_NUM },
{ .block_size = BLOCK_SIZE, .block_num = BLOCK_NUM, .location = &IMAGE_BIN_LE_SINGLEBYTE[0] },
- { .block_size = BLOCK_SIZE, .block_num = BLOCK_NUM, .location = &IMAGE_BIN_LE_MULTIBYTE[0] }
+ { .block_size = BLOCK_SIZE, .block_num = BLOCK_NUM, .location = &IMAGE_BIN_LE_MULTIBYTE[0] },
+ { .block_size = BLOCK_SIZE, .block_num = sizeof( image_bin ) / BLOCK_SIZE, .location = image_bin }
};
size_t rtems_ramdisk_configuration_size = RTEMS_ARRAY_SIZE(rtems_ramdisk_configuration);
@@ -1424,7 +1396,6 @@ size_t rtems_ramdisk_configuration_size = RTEMS_ARRAY_SIZE(rtems_ramdisk_configu
#define CONFIGURE_INIT_TASK_STACK_SIZE ( 1024 * 64 )
#define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER
#define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
-#define CONFIGURE_MAXIMUM_DRIVERS 4
#define CONFIGURE_MAXIMUM_SEMAPHORES (2 * RTEMS_DOSFS_SEMAPHORES_PER_INSTANCE)
#define CONFIGURE_APPLICATION_EXTRA_DRIVERS RAMDISK_DRIVER_TABLE_ENTRY
diff --git a/testsuites/fstests/mdosfs_support/fs_support.c b/testsuites/fstests/mdosfs_support/fs_support.c
index 7b73c27b84..4395182e0f 100644
--- a/testsuites/fstests/mdosfs_support/fs_support.c
+++ b/testsuites/fstests/mdosfs_support/fs_support.c
@@ -87,7 +87,6 @@ void test_shutdown_filesystem(void)
#define CONFIGURE_MAXIMUM_SEMAPHORES RTEMS_DOSFS_SEMAPHORES_PER_INSTANCE
#define CONFIGURE_MAXIMUM_TASKS 10
-#define CONFIGURE_MAXIMUM_DRIVERS 10
#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 40
#define CONFIGURE_INIT_TASK_STACK_SIZE (16 * 1024)
#define CONFIGURE_INIT_TASK_ATTRIBUTES RTEMS_FLOATING_POINT
diff --git a/testsuites/fstests/mrfs_support/fs_support.c b/testsuites/fstests/mrfs_support/fs_support.c
index 28b7be9a03..24c82cbea1 100644
--- a/testsuites/fstests/mrfs_support/fs_support.c
+++ b/testsuites/fstests/mrfs_support/fs_support.c
@@ -66,7 +66,6 @@ test_shutdown_filesystem (void)
#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
#define CONFIGURE_MAXIMUM_TASKS 10
-#define CONFIGURE_MAXIMUM_DRIVERS 10
#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 40
#define CONFIGURE_INIT_TASK_STACK_SIZE (32 * 1024)
#define CONFIGURE_INIT_TASK_ATTRIBUTES RTEMS_FLOATING_POINT
diff --git a/testsuites/fstests/support/ramdisk_support.c b/testsuites/fstests/support/ramdisk_support.c
index d7574b2853..0a07495c02 100644
--- a/testsuites/fstests/support/ramdisk_support.c
+++ b/testsuites/fstests/support/ramdisk_support.c
@@ -11,12 +11,9 @@
#include "config.h"
#endif
-#include <sys/stat.h>
-#include <fcntl.h>
+#include <unistd.h>
#include <rtems/ramdisk.h>
-#include <rtems/blkdev.h>
-#include <rtems/libio.h>
#include "ramdisk_support.h"
#include "fstest.h"
@@ -26,17 +23,14 @@
* Ramdisk information
*/
-dev_t dev = 0;
-
void
init_ramdisk (void)
{
int rc = 0;
- rc = rtems_disk_io_initialize ();
- rtems_test_assert (rc == 0);
+
rc = ramdisk_register (RAMDISK_BLOCK_SIZE, RAMDISK_BLOCK_COUNT,
- false, RAMDISK_PATH, &dev);
+ false, RAMDISK_PATH);
rtems_test_assert (rc == 0);
}
@@ -45,20 +39,7 @@ del_ramdisk (void)
{
int rc = 0;
- rtems_device_major_number major = 0;
- rtems_device_minor_number minor = 0;
- rc = rtems_disk_delete (dev);
+ rc = unlink (RAMDISK_PATH);
rtems_test_assert (rc == 0);
-
- rtems_filesystem_split_dev_t (dev, major, minor);
-
- rtems_test_assert (major >= 0);
- rtems_test_assert (minor >= 0);
-
- rc = rtems_io_unregister_driver (major);
- rtems_test_assert (rc == 0);
- rc = rtems_disk_io_done ();
- rtems_test_assert (rc == 0);
-
}
diff --git a/testsuites/libtests/block01/init.c b/testsuites/libtests/block01/init.c
index 92dbfc9aba..04b2ef4986 100644
--- a/testsuites/libtests/block01/init.c
+++ b/testsuites/libtests/block01/init.c
@@ -7,10 +7,10 @@
*/
/*
- * Copyright (c) 2009-2012 embedded brains GmbH. All rights reserved.
+ * Copyright (c) 2009, 2018 embedded brains GmbH. All rights reserved.
*
* embedded brains GmbH
- * Obere Lagerstr. 30
+ * Dornierstr. 4
* 82178 Puchheim
* Germany
* <rtems at embedded-brains.de>
@@ -35,9 +35,6 @@
const char rtems_test_name[] = "BLOCK 1";
-/* forward declarations to avoid warnings */
-static rtems_task Init(rtems_task_argument argument);
-
#define ASSERT_SC(sc) rtems_test_assert((sc) == RTEMS_SUCCESSFUL)
#define ASSERT_SC_EQ(sc, sc_expected) rtems_test_assert((sc) == (sc_expected))
@@ -46,6 +43,11 @@ static rtems_task Init(rtems_task_argument argument);
#define BLOCK_COUNT 16U
+static const rtems_driver_address_table ramdisk_ops = {
+ .initialization_entry = NULL,
+ RTEMS_GENERIC_BLOCK_DEVICE_DRIVER_ENTRIES
+};
+
static void test_block_io_control_api(dev_t dev, ramdisk *rd)
{
rtems_status_code sc = RTEMS_SUCCESSFUL;
diff --git a/testsuites/libtests/block02/init.c b/testsuites/libtests/block02/init.c
index c550517e21..983f876bcd 100644
--- a/testsuites/libtests/block02/init.c
+++ b/testsuites/libtests/block02/init.c
@@ -7,10 +7,10 @@
*/
/*
- * Copyright (c) 2009-2012 embedded brains GmbH. All rights reserved.
+ * Copyright (c) 2009, 2018 embedded brains GmbH. All rights reserved.
*
* embedded brains GmbH
- * Obere Lagerstr. 30
+ * Dornierstr. 4
* 82178 Puchheim
* Germany
* <rtems at embedded-brains.de>
@@ -30,12 +30,12 @@
#include <rtems/bspIo.h>
#include <rtems/ramdisk.h>
#include <rtems/bdbuf.h>
-#include <rtems/diskdevs.h>
-const char rtems_test_name[] = "BLOCK 2";
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
-/* forward declarations to avoid warnings */
-static rtems_task Init(rtems_task_argument argument);
+const char rtems_test_name[] = "BLOCK 2";
#define ASSERT_SC(sc) rtems_test_assert((sc) == RTEMS_SUCCESSFUL)
@@ -130,29 +130,39 @@ static void task_high(rtems_task_argument arg)
rtems_task_delete(RTEMS_SELF);
}
-static rtems_task Init(rtems_task_argument argument)
+static void do_ramdisk_register(
+ uint32_t media_block_size,
+ rtems_blkdev_bnum media_block_count,
+ const char *disk,
+ rtems_disk_device **dd
+)
{
- rtems_status_code sc = RTEMS_SUCCESSFUL;
- rtems_bdbuf_buffer *bd = NULL;
- dev_t dev_a = 0;
- dev_t dev_b = 0;
+ rtems_status_code sc;
+ int fd;
+ int rv;
- TEST_BEGIN();
-
- sc = rtems_disk_io_initialize();
+ sc = ramdisk_register(media_block_size, media_block_count, false, disk);
ASSERT_SC(sc);
- sc = ramdisk_register(BLOCK_SIZE_A, BLOCK_COUNT_A, false, "/dev/rda", &dev_a);
- ASSERT_SC(sc);
+ fd = open(disk, O_RDWR);
+ rtems_test_assert(fd >= 0);
- sc = ramdisk_register(BLOCK_SIZE_B, BLOCK_COUNT_B, false, "/dev/rdb", &dev_b);
- ASSERT_SC(sc);
+ rv = rtems_disk_fd_get_disk_device(fd, dd);
+ rtems_test_assert(rv == 0);
- dd_a = rtems_disk_obtain(dev_a);
- rtems_test_assert(dd_a != NULL);
+ rv = close(fd);
+ rtems_test_assert(rv == 0);
+}
- dd_b = rtems_disk_obtain(dev_b);
- rtems_test_assert(dd_b != NULL);
+static rtems_task Init(rtems_task_argument argument)
+{
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+ rtems_bdbuf_buffer *bd = NULL;
+
+ TEST_BEGIN();
+
+ do_ramdisk_register(BLOCK_SIZE_A, BLOCK_COUNT_A, "/dev/rda", &dd_a);
+ do_ramdisk_register(BLOCK_SIZE_B, BLOCK_COUNT_B, "/dev/rdb", &dd_b);
sc = rtems_task_create(
rtems_build_name(' ', 'L', 'O', 'W'),
@@ -200,8 +210,9 @@ static rtems_task Init(rtems_task_argument argument)
#define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
#define CONFIGURE_APPLICATION_NEEDS_LIBBLOCK
+#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 4
+
#define CONFIGURE_MAXIMUM_TASKS 3
-#define CONFIGURE_MAXIMUM_DRIVERS 3
#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
diff --git a/testsuites/libtests/block03/init.c b/testsuites/libtests/block03/init.c
index c66a52049f..2bab878134 100644
--- a/testsuites/libtests/block03/init.c
+++ b/testsuites/libtests/block03/init.c
@@ -7,10 +7,10 @@
*/
/*
- * Copyright (c) 2009-2012 embedded brains GmbH. All rights reserved.
+ * Copyright (c) 2009, 2018 embedded brains GmbH. All rights reserved.
*
* embedded brains GmbH
- * Obere Lagerstr. 30
+ * Dornierstr. 4
* 82178 Puchheim
* Germany
* <rtems at embedded-brains.de>
@@ -30,12 +30,12 @@
#include <rtems/bspIo.h>
#include <rtems/ramdisk.h>
#include <rtems/bdbuf.h>
-#include <rtems/diskdevs.h>
-const char rtems_test_name[] = "BLOCK 3";
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
-/* forward declarations to avoid warnings */
-static rtems_task Init(rtems_task_argument argument);
+const char rtems_test_name[] = "BLOCK 3";
#define ASSERT_SC(sc) rtems_test_assert((sc) == RTEMS_SUCCESSFUL)
@@ -124,22 +124,38 @@ static void task_high(rtems_task_argument arg)
rtems_task_delete(RTEMS_SELF);
}
+static void do_ramdisk_register(
+ uint32_t media_block_size,
+ rtems_blkdev_bnum media_block_count,
+ const char *disk,
+ rtems_disk_device **dd
+)
+{
+ rtems_status_code sc;
+ int fd;
+ int rv;
+
+ sc = ramdisk_register(media_block_size, media_block_count, false, disk);
+ ASSERT_SC(sc);
+
+ fd = open(disk, O_RDWR);
+ rtems_test_assert(fd >= 0);
+
+ rv = rtems_disk_fd_get_disk_device(fd, dd);
+ rtems_test_assert(rv == 0);
+
+ rv = close(fd);
+ rtems_test_assert(rv == 0);
+}
+
static rtems_task Init(rtems_task_argument argument)
{
rtems_status_code sc = RTEMS_SUCCESSFUL;
rtems_bdbuf_buffer *bd = NULL;
- dev_t dev = 0;
TEST_BEGIN();
- sc = rtems_disk_io_initialize();
- ASSERT_SC(sc);
-
- sc = ramdisk_register(BLOCK_SIZE, BLOCK_COUNT, false, "/dev/rda", &dev);
- ASSERT_SC(sc);
-
- dd = rtems_disk_obtain(dev);
- rtems_test_assert(dd != NULL);
+ do_ramdisk_register(BLOCK_SIZE, BLOCK_COUNT, "/dev/rda", &dd);
sc = rtems_task_create(
rtems_build_name(' ', 'L', 'O', 'W'),
@@ -187,8 +203,9 @@ static rtems_task Init(rtems_task_argument argument)
#define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
#define CONFIGURE_APPLICATION_NEEDS_LIBBLOCK
+#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 4
+
#define CONFIGURE_MAXIMUM_TASKS 3
-#define CONFIGURE_MAXIMUM_DRIVERS 2
#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
diff --git a/testsuites/libtests/block04/init.c b/testsuites/libtests/block04/init.c
index 1b5d114029..891552d461 100644
--- a/testsuites/libtests/block04/init.c
+++ b/testsuites/libtests/block04/init.c
@@ -7,10 +7,10 @@
*/
/*
- * Copyright (c) 2009-2012 embedded brains GmbH. All rights reserved.
+ * Copyright (c) 2009, 2018 embedded brains GmbH. All rights reserved.
*
* embedded brains GmbH
- * Obere Lagerstr. 30
+ * Dornierstr. 4
* 82178 Puchheim
* Germany
* <rtems at embedded-brains.de>
@@ -30,12 +30,12 @@
#include <rtems/bspIo.h>
#include <rtems/ramdisk.h>
#include <rtems/bdbuf.h>
-#include <rtems/diskdevs.h>
-const char rtems_test_name[] = "BLOCK 4";
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
-/* forward declarations to avoid warnings */
-static rtems_task Init(rtems_task_argument argument);
+const char rtems_test_name[] = "BLOCK 4";
#define ASSERT_SC(sc) rtems_test_assert((sc) == RTEMS_SUCCESSFUL)
@@ -107,21 +107,37 @@ static void task_high(rtems_task_argument arg)
exit(0);
}
+static void do_ramdisk_register(
+ uint32_t media_block_size,
+ rtems_blkdev_bnum media_block_count,
+ const char *disk,
+ rtems_disk_device **dd
+)
+{
+ rtems_status_code sc;
+ int fd;
+ int rv;
+
+ sc = ramdisk_register(media_block_size, media_block_count, false, disk);
+ ASSERT_SC(sc);
+
+ fd = open(disk, O_RDWR);
+ rtems_test_assert(fd >= 0);
+
+ rv = rtems_disk_fd_get_disk_device(fd, dd);
+ rtems_test_assert(rv == 0);
+
+ rv = close(fd);
+ rtems_test_assert(rv == 0);
+}
+
static rtems_task Init(rtems_task_argument argument)
{
rtems_status_code sc = RTEMS_SUCCESSFUL;
- dev_t dev = 0;
TEST_BEGIN();
- sc = rtems_disk_io_initialize();
- ASSERT_SC(sc);
-
- sc = ramdisk_register(BLOCK_SIZE, BLOCK_COUNT, false, "/dev/rda", &dev);
- ASSERT_SC(sc);
-
- dd = rtems_disk_obtain(dev);
- rtems_test_assert(dd != NULL);
+ do_ramdisk_register(BLOCK_SIZE, BLOCK_COUNT, "/dev/rda", &dd);
sc = rtems_task_create(
rtems_build_name(' ', 'L', 'O', 'W'),
@@ -159,8 +175,9 @@ static rtems_task Init(rtems_task_argument argument)
#define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
#define CONFIGURE_APPLICATION_NEEDS_LIBBLOCK
+#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 4
+
#define CONFIGURE_MAXIMUM_TASKS 3
-#define CONFIGURE_MAXIMUM_DRIVERS 2
#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
diff --git a/testsuites/libtests/block07/init.c b/testsuites/libtests/block07/init.c
index 914dd35a90..e0f7ecc031 100644
--- a/testsuites/libtests/block07/init.c
+++ b/testsuites/libtests/block07/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, 2018 embedded brains GmbH. All rights reserved.
+ *
+ * embedded brains GmbH
+ * Dornierstr. 4
+ * 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
@@ -27,19 +28,16 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
+#include <unistd.h>
#include "tmacros.h"
#include <rtems.h>
#include <rtems/ramdisk.h>
#include <rtems/bdbuf.h>
-#include <rtems/diskdevs.h>
const char rtems_test_name[] = "BLOCK 7";
-/* forward declarations to avoid warnings */
-static rtems_task Init(rtems_task_argument argument);
-
#define ASSERT_SC(sc) rtems_test_assert((sc) == RTEMS_SUCCESSFUL)
#define PRIORITY_INIT 1
@@ -158,23 +156,39 @@ static void task_high(rtems_task_argument arg)
rtems_task_delete(RTEMS_SELF);
}
+static void do_ramdisk_register(
+ uint32_t media_block_size,
+ rtems_blkdev_bnum media_block_count,
+ const char *disk,
+ rtems_disk_device **dd
+)
+{
+ rtems_status_code sc;
+ int fd;
+ int rv;
+
+ sc = ramdisk_register(media_block_size, media_block_count, false, disk);
+ ASSERT_SC(sc);
+
+ fd = open(disk, O_RDWR);
+ rtems_test_assert(fd >= 0);
+
+ rv = rtems_disk_fd_get_disk_device(fd, dd);
+ rtems_test_assert(rv == 0);
+
+ rv = close(fd);
+ rtems_test_assert(rv == 0);
+}
+
static rtems_task Init(rtems_task_argument argument)
{
rtems_status_code sc = RTEMS_SUCCESSFUL;
rtems_task_priority cur_prio = 0;
rtems_bdbuf_buffer *bd = NULL;
- dev_t dev = 0;
TEST_BEGIN();
- sc = rtems_disk_io_initialize();
- ASSERT_SC(sc);
-
- sc = ramdisk_register(BLOCK_SIZE_A, BLOCK_COUNT, false, "/dev/rda", &dev);
- ASSERT_SC(sc);
-
- dd = rtems_disk_obtain(dev);
- rtems_test_assert(dd != NULL);
+ do_ramdisk_register(BLOCK_SIZE_A, BLOCK_COUNT, "/dev/rda", &dd);
sc = rtems_task_create(
rtems_build_name(' ', 'L', 'O', 'W'),
@@ -265,7 +279,6 @@ static rtems_task Init(rtems_task_argument argument)
#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 4
#define CONFIGURE_MAXIMUM_TASKS 4
-#define CONFIGURE_MAXIMUM_DRIVERS 2
#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
diff --git a/testsuites/samples/fileio/init.c b/testsuites/samples/fileio/init.c
index 433266a99f..974535b83c 100644
--- a/testsuites/samples/fileio/init.c
+++ b/testsuites/samples/fileio/init.c
@@ -43,38 +43,6 @@ const char rtems_test_name[] = "FILE I/O";
*/
#define RTEMS_DRIVER_AUTO_MAJOR (0)
-/*
- * RAM disk driver so you can create a RAM disk from the shell prompt.
- */
-/**
- * The RAM Disk configuration.
- */
-rtems_ramdisk_config rtems_ramdisk_configuration[] =
-{
- {
- block_size: 512,
- block_num: 1024,
- location: NULL
- }
-};
-
-/**
- * The number of RAM Disk configurations.
- */
-size_t rtems_ramdisk_configuration_size = 1;
-
-/**
- * Create the RAM Disk Driver entry.
- */
-rtems_driver_address_table rtems_ramdisk_io_ops = {
- initialization_entry: ramdisk_initialize,
- open_entry: rtems_blkdev_generic_open,
- close_entry: rtems_blkdev_generic_close,
- read_entry: rtems_blkdev_generic_read,
- write_entry: rtems_blkdev_generic_write,
- control_entry: rtems_blkdev_generic_ioctl
-};
-
/**
* The NV Device descriptor. For this test it is just DRAM.
*/
@@ -404,17 +372,20 @@ disk_test_block_sizes (int argc, char *argv[])
return disk_test_write_blocks (st.st_rdev, start, count, size);
}
-static size_t
+static uint32_t
parse_size_arg (const char* arg)
{
- size_t size;
- size_t scalar = 1;
-
+ uint32_t size;
+ uint32_t scalar = 1;
+
size = strtoul (arg, 0, 0);
switch (arg[strlen (arg) - 1])
{
+ case 'b':
+ scalar = 1;
+ break;
case 'M':
- scalar = (size_t) 1000 * 1024;
+ scalar = 1024000;
break;
case 'm':
scalar = 1000000;
@@ -426,26 +397,26 @@ parse_size_arg (const char* arg)
scalar = 1000;
break;
default:
- printf ("error: invalid scalar (M/m/K/k): %c\n", arg[strlen (arg) - 1]);
+ printf ("error: invalid scalar (b,M/m/K/k): %c\n", arg[strlen (arg) - 1]);
return 0;
}
return size * scalar;
- }
+}
static int
create_ramdisk (int argc, char *argv[])
{
- rtems_device_major_number major;
rtems_status_code sc;
int arg;
- size_t size = 0;
- size_t block_size = 0;
+ uint32_t size = 524288;
+ uint32_t block_size = 512;
+ uint32_t block_count;
for (arg = 0; arg < argc; ++arg)
{
if (argv[arg][0] == '-')
{
- switch (argv[arg][0])
+ switch (argv[arg][1])
{
case 's':
++arg;
@@ -476,30 +447,24 @@ create_ramdisk (int argc, char *argv[])
}
}
- if (block_size)
- rtems_ramdisk_configuration[0].block_size = block_size;
- if (size)
- rtems_ramdisk_configuration[0].block_num =
- size / rtems_ramdisk_configuration[0].block_size;
-
+ block_count = size / block_size;
+
/*
* Register the RAM Disk driver.
*/
printf ("Register RAM Disk Driver [blocks=%" PRIu32 \
- " block-size=%" PRIu32"]:",
- rtems_ramdisk_configuration[0].block_num,
- rtems_ramdisk_configuration[0].block_size);
-
- sc = rtems_io_register_driver (RTEMS_DRIVER_AUTO_MAJOR,
- &rtems_ramdisk_io_ops,
- &major);
+ " block-size=%" PRIu32 "]:",
+ block_count,
+ block_size);
+
+ sc = ramdisk_register(block_size, block_count, false, "/dev/rda");
if (sc != RTEMS_SUCCESSFUL)
{
printf ("error: ramdisk driver not initialised: %s\n",
rtems_status_text (sc));
return 1;
}
-
+
printf ("successful\n");
return 0;
@@ -511,9 +476,9 @@ create_nvdisk (int argc, char *argv[])
rtems_device_major_number major;
rtems_status_code sc;
int arg;
- size_t size = 0;
+ uint32_t size = 0;
#if ADD_WHEN_NVDISK_HAS_CHANGED
- size_t block_size = 0;
+ uint32_t block_size = 0;
#endif
for (arg = 0; arg < argc; ++arg)
--
2.13.7
More information about the devel
mailing list