forked from Imagelibrary/rtems
libblock: New block IO control support functions
This commit is contained in:
@@ -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.
|
||||
*
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -7,10 +7,11 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009
|
||||
* Copyright (c) 2009-2012 embedded brains GmbH. All rights reserved.
|
||||
*
|
||||
* embedded brains GmbH
|
||||
* Obere Lagerstr. 30
|
||||
* D-82178 Puchheim
|
||||
* 82178 Puchheim
|
||||
* Germany
|
||||
* <rtems@embedded-brains.de>
|
||||
*
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user