libblock: New block IO control support functions

This commit is contained in:
Sebastian Huber
2012-02-28 13:28:42 +01:00
parent 4f3cbd9240
commit c649976859
3 changed files with 114 additions and 7 deletions

View File

@@ -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. * Only consecutive multi-sector buffer requests are supported.
* *

View File

@@ -58,7 +58,7 @@ static int rtems_shell_main_blksync(
return 1; 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)); fprintf( stderr, "%s: driver sync failed: %s\n", argv[0], strerror (errno));
return 1; return 1;
} }

View File

@@ -7,12 +7,13 @@
*/ */
/* /*
* Copyright (c) 2009 * Copyright (c) 2009-2012 embedded brains GmbH. All rights reserved.
* embedded brains GmbH *
* Obere Lagerstr. 30 * embedded brains GmbH
* D-82178 Puchheim * Obere Lagerstr. 30
* Germany * 82178 Puchheim
* <rtems@embedded-brains.de> * Germany
* <rtems@embedded-brains.de>
* *
* The license and distribution terms for this file may be * The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at * found in the file LICENSE in this distribution or at
@@ -25,7 +26,9 @@
#include "config.h" #include "config.h"
#endif #endif
#include <sys/stat.h>
#include <stdio.h> #include <stdio.h>
#include <fcntl.h>
#include "tmacros.h" #include "tmacros.h"
#include <rtems.h> #include <rtems.h>
@@ -40,6 +43,66 @@
#define BLOCK_COUNT 16U #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) static void test_diskdevs(void)
{ {
rtems_status_code sc = RTEMS_SUCCESSFUL; rtems_status_code sc = RTEMS_SUCCESSFUL;
@@ -154,6 +217,10 @@ static void test_diskdevs(void)
sc = rtems_disk_release(logical_dd); sc = rtems_disk_release(logical_dd);
ASSERT_SC(sc); ASSERT_SC(sc);
/* Test block IO control API */
test_block_io_control_api(physical_dev, rd);
/* Cleanup */ /* Cleanup */
sc = rtems_io_unregister_driver(major); 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_APPLICATION_NEEDS_LIBBLOCK
#define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM #define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM
#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 4
#define CONFIGURE_MAXIMUM_TASKS 2 #define CONFIGURE_MAXIMUM_TASKS 2
#define CONFIGURE_MAXIMUM_DRIVERS 2 #define CONFIGURE_MAXIMUM_DRIVERS 2