summaryrefslogtreecommitdiffstats
path: root/cpukit/libblock/src/diskdevs.c
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2012-03-26 14:58:35 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2012-04-12 10:42:43 +0200
commitb467782b5354c5d524f46bac84c5b70a8b4fa1f6 (patch)
tree82e37f50cb88569fad625d5c0f30ae9786fd31c5 /cpukit/libblock/src/diskdevs.c
parentlibblock: Change error status to fatal error (diff)
downloadrtems-b467782b5354c5d524f46bac84c5b70a8b4fa1f6.tar.bz2
libblock: Add rtems_bdbuf_set_block_size()
The new function rtems_bdbuf_set_block_size() must be used to set the block size of a disk device. It will check if the block size is valid and set the new fields block_to_media_block_shift and bds_per_group of the rtems_disk_device structure. This helps to avoid complex arithmetic operations in the block device buffer get and read path.
Diffstat (limited to 'cpukit/libblock/src/diskdevs.c')
-rw-r--r--cpukit/libblock/src/diskdevs.c29
1 files changed, 23 insertions, 6 deletions
diff --git a/cpukit/libblock/src/diskdevs.c b/cpukit/libblock/src/diskdevs.c
index 08a6a9bf8c..500569fb4d 100644
--- a/cpukit/libblock/src/diskdevs.c
+++ b/cpukit/libblock/src/diskdevs.c
@@ -220,6 +220,15 @@ create_disk(dev_t dev, const char *name, rtems_disk_device **dd_ptr)
return RTEMS_SUCCESSFUL;
}
+static int null_handler(
+ rtems_disk_device *dd,
+ uint32_t req,
+ void *argp
+)
+{
+ return -1;
+}
+
rtems_status_code rtems_disk_create_phys(
dev_t dev,
uint32_t block_size,
@@ -236,10 +245,6 @@ rtems_status_code rtems_disk_create_phys(
return RTEMS_INVALID_ADDRESS;
}
- if (block_size == 0) {
- return RTEMS_INVALID_NUMBER;
- }
-
sc = disk_lock();
if (sc != RTEMS_SUCCESSFUL) {
return sc;
@@ -255,7 +260,7 @@ rtems_status_code rtems_disk_create_phys(
dd->phys_dev = dd;
dd->start = 0;
dd->size = block_count;
- dd->block_size = dd->media_block_size = block_size;
+ dd->media_block_size = block_size;
dd->ioctl = handler;
dd->driver_data = driver_data;
@@ -263,6 +268,15 @@ rtems_status_code rtems_disk_create_phys(
dd->capabilities = 0;
}
+ sc = rtems_bdbuf_set_block_size(dd, block_size);
+ if (sc != RTEMS_SUCCESSFUL) {
+ dd->ioctl = null_handler;
+ rtems_disk_delete(dev);
+ disk_unlock();
+
+ return sc;
+ }
+
disk_unlock();
return RTEMS_SUCCESSFUL;
@@ -319,7 +333,10 @@ rtems_status_code rtems_disk_create_log(
dd->phys_dev = physical_disk;
dd->start = begin_block;
dd->size = block_count;
- dd->block_size = dd->media_block_size = physical_disk->block_size;
+ dd->block_size = physical_disk->block_size;
+ dd->media_block_size = physical_disk->media_block_size;
+ dd->block_to_media_block_shift = physical_disk->block_to_media_block_shift;
+ dd->bds_per_group = physical_disk->bds_per_group;
dd->ioctl = physical_disk->ioctl;
dd->driver_data = physical_disk->driver_data;