Skip to content

GenDiskBuilder docs use the wrong block-size limit #1245

Open

Description

@younes-io

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.

Activity

  1. ojeda commented on Jul 16, 2026

    @ojeda
    Member

    Yeah, that seems like an oversight, but pinging the maintainers...

    Cc: @metaspace @fbq

  2. added
    • docsRelated to `Documentation/rust/`, `samples/`, generated docs, doctests, typos...
    on Jul 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    • docsRelated to `Documentation/rust/`, `samples/`, generated docs, doctests, typos...

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions