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.
This commit is contained in:
Sebastian Huber
2012-04-12 10:42:43 +02:00
parent 3d60c1b22a
commit b467782b53
6 changed files with 170 additions and 90 deletions
+21 -2
View File
@@ -479,7 +479,7 @@ rtems_bdbuf_init (void);
* @param bd [out] Reference to the buffer descriptor pointer.
*
* @retval RTEMS_SUCCESSFUL Successful operation.
* @retval RTEMS_INVALID_NUMBER Invalid block size.
* @retval RTEMS_INVALID_ID Invalid block number.
*/
rtems_status_code
rtems_bdbuf_get (
@@ -512,7 +512,7 @@ rtems_bdbuf_get (
* @param bd [out] Reference to the buffer descriptor pointer.
*
* @retval RTEMS_SUCCESSFUL Successful operation.
* @retval RTEMS_INVALID_NUMBER Invalid block size.
* @retval RTEMS_INVALID_ID Invalid block number.
* @retval RTEMS_IO_ERROR IO error.
*/
rtems_status_code
@@ -625,6 +625,25 @@ rtems_bdbuf_syncdev (const rtems_disk_device *dd);
void
rtems_bdbuf_purge_dev (const rtems_disk_device *dd);
/**
* @brief Sets the block size of a disk device.
*
* This will also change the block_to_media_block_shift and bds_per_group
* fields of the disk device.
*
* Before you can use this function, the rtems_bdbuf_init() routine must be
* called at least once to initialize the cache, otherwise a fatal error will
* occur.
*
* @param dd [in, out] The disk device.
* @param dd [in] The new block size.
*
* @retval RTEMS_SUCCESSFUL Successful operation.
* @retval RTEMS_INVALID_NUMBER Invalid block size.
*/
rtems_status_code
rtems_bdbuf_set_block_size (rtems_disk_device *dd, uint32_t block_size);
/** @} */
#ifdef __cplusplus
+22 -2
View File
@@ -109,7 +109,9 @@ struct rtems_disk_device {
/**
* @brief Device block size in bytes.
*
* This is the minimum transfer unit. It can be any size.
* This is the minimum transfer unit. It must be positive.
*
* @see rtems_bdbuf_set_block_size().
*/
uint32_t block_size;
@@ -120,6 +122,24 @@ struct rtems_disk_device {
*/
uint32_t media_block_size;
/**
* @brief Block to media block shift.
*
* In case this value is non-negative the media block of a block can be
* calculated as media block = block << block_to_media_block_shift, otherwise
* a 64-bit operation will be used.
*
* @see rtems_bdbuf_set_block_size().
*/
int block_to_media_block_shift;
/**
* @brief Buffer descriptors per group count.
*
* @see rtems_bdbuf_set_block_size().
*/
size_t bds_per_group;
/**
* @brief IO control handler for this disk.
*/
@@ -222,7 +242,7 @@ static inline rtems_blkdev_bnum rtems_disk_get_block_count(
* @retval RTEMS_SUCCESSFUL Successful operation.
* @retval RTEMS_NOT_CONFIGURED Cannot lock disk device operation mutex.
* @retval RTEMS_INVALID_ADDRESS IO control handler is @c NULL.
* @retval RTEMS_INVALID_NUMBER Block size is zero.
* @retval RTEMS_INVALID_NUMBER Block size is invalid.
* @retval RTEMS_NO_MEMORY Not enough memory.
* @retval RTEMS_RESOURCE_IN_USE Disk device descriptor is already in use.
* @retval RTEMS_UNSATISFIED Cannot create device node.