TestBlockDeviceConfig

Struct TestBlockDeviceConfig 

Source
pub struct TestBlockDeviceConfig {
    pub dev_id: i32,
    pub size: u64,
    pub seed: u64,
    pub fill_percent: u32,
    pub duplicate_percent: u32,
    pub random_percent: u32,
    pub segments: usize,
    pub unprivileged: bool,
}
Expand description

Configuration for creating a test block device.

This struct contains all the parameters needed to create a procedurally generated test block device with specific characteristics for testing storage systems, compression, deduplication, and other block-level operations.

§Examples

use test_bd::TestBlockDeviceConfig;

let config = TestBlockDeviceConfig {
    dev_id: -1,  // Auto-assign device ID
    size: 1024 * 1024 * 1024,  // 1 GiB
    seed: 42,
    fill_percent: 40,
    duplicate_percent: 30,
    random_percent: 30,
    segments: 100,
    unprivileged: false,
};

// Validate the configuration
config.validate().expect("Invalid configuration");

Fields§

§dev_id: i32

Device ID for the block device.

Use -1 to automatically assign the next available device ID, or specify a non-negative value to request a specific device ID.

§size: u64

Total size of the block device in bytes.

Must be a multiple of 8 bytes and not exceed i64::MAX.

§seed: u64

Seed for the pseudo-random number generator.

Using the same seed with the same configuration will produce identical data patterns, enabling reproducible tests.

§fill_percent: u32

Percentage of the device to fill with zeros (0-100).

Fill segments are useful for testing compression.

§duplicate_percent: u32

Percentage of the device to fill with duplicate patterns (0-100).

Duplicate segments contain repeating 512-byte blocks, useful for testing deduplication.

§random_percent: u32

Percentage of the device to fill with pseudo-random data (0-100).

Random segments simulate encrypted or already-compressed data.

§segments: usize

Number of segments to divide the device into.

Must be less than size / 512. More segments create more varied data distributions but may impact performance.

§unprivileged: bool

Whether to create an unprivileged device (non-root access).

When true, the device can be accessed by non-root users (requires kernel support).

Implementations§

Source§

impl TestBlockDeviceConfig

Source

pub fn generate_segments(&self) -> Vec<SegmentInfo>

Generates the segment layout for this configuration without creating a device.

This is useful for inspecting what the device layout would be before actually creating the device, or for verification purposes.

§Examples
use test_bd::TestBlockDeviceConfig;

let config = TestBlockDeviceConfig {
    dev_id: -1,
    size: 10240,
    seed: 42,
    fill_percent: 50,
    duplicate_percent: 25,
    random_percent: 25,
    segments: 10,
    unprivileged: false,
};

let segments = config.generate_segments();
assert_eq!(segments.len(), 10);
Source

pub fn validate(&self) -> Result<(), String>

Validates the configuration parameters.

Ensures that:

  • Percentages sum to exactly 100
  • Size doesn’t exceed i64::MAX
  • Number of segments is reasonable for the device size
§Returns
  • Ok(()) if the configuration is valid
  • Err(String) with a descriptive error message if validation fails
§Examples
use test_bd::TestBlockDeviceConfig;

let config = TestBlockDeviceConfig {
    dev_id: -1,
    size: 10240,
    seed: 42,
    fill_percent: 50,
    duplicate_percent: 30,
    random_percent: 20,
    segments: 10,
    unprivileged: false,
};

assert!(config.validate().is_ok());

Trait Implementations§

Source§

impl Clone for TestBlockDeviceConfig

Source§

fn clone(&self) -> TestBlockDeviceConfig

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TestBlockDeviceConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V