The docs for GenDiskBuilder::logical_block_size and physical_block_size say the block size must be between 512 and 4096 bytes. The shared validate_block_size helper actually accepts powers of two up to PAGE_SIZE.
|
/// Validate block size by verifying that it is between 512 and `PAGE_SIZE`, |
|
/// and that it is a power of two. |
|
pub fn validate_block_size(size: u32) -> Result { |
|
if !(512..=bindings::PAGE_SIZE as u32).contains(&size) || !size.is_power_of_two() { |
|
Err(error::code::EINVAL) |
|
} else { |
|
Ok(()) |
|
} |
|
} |
|
|
|
/// Set the logical block size of the device to be built. |
|
/// |
|
/// This method will check that block size is a power of two and between 512 |
|
/// and 4096. If not, an error is returned and the block size is not set. |
|
/// |
|
/// This is the smallest unit the storage device can address. It is |
|
/// typically 4096 bytes. |
|
pub fn logical_block_size(mut self, block_size: u32) -> Result<Self> { |
|
Self::validate_block_size(block_size)?; |
|
self.logical_block_size = block_size; |
|
Ok(self) |
|
} |
|
|
|
/// Set the physical block size of the device to be built. |
|
/// |
|
/// This method will check that block size is a power of two and between 512 |
|
/// and 4096. If not, an error is returned and the block size is not set. |
|
/// |
|
/// This is the smallest unit a physical storage device can write |
|
/// atomically. It is usually the same as the logical block size but may be |
|
/// bigger. One example is SATA drives with 4096 byte physical block size |
|
/// that expose a 512 byte logical block size to the operating system. |
|
pub fn physical_block_size(mut self, block_size: u32) -> Result<Self> { |
|
Self::validate_block_size(block_size)?; |
On configurations with a larger page size, the documented limit is therefore too low.
Would a small patch updating both comments to use PAGE_SIZE be welcome? I can prepare it.
The docs for
GenDiskBuilder::logical_block_sizeandphysical_block_sizesay the block size must be between 512 and 4096 bytes. The sharedvalidate_block_sizehelper actually accepts powers of two up toPAGE_SIZE.linux/rust/kernel/block/mq/gen_disk.rs
Lines 53 to 86 in 7059bdf
On configurations with a larger page size, the documented limit is therefore too low.
Would a small patch updating both comments to use
PAGE_SIZEbe welcome? I can prepare it.