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: i32Device 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: u64Total size of the block device in bytes.
Must be a multiple of 8 bytes and not exceed i64::MAX.
seed: u64Seed for the pseudo-random number generator.
Using the same seed with the same configuration will produce identical data patterns, enabling reproducible tests.
fill_percent: u32Percentage of the device to fill with zeros (0-100).
Fill segments are useful for testing compression.
duplicate_percent: u32Percentage of the device to fill with duplicate patterns (0-100).
Duplicate segments contain repeating 512-byte blocks, useful for testing deduplication.
random_percent: u32Percentage of the device to fill with pseudo-random data (0-100).
Random segments simulate encrypted or already-compressed data.
segments: usizeNumber 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: boolWhether 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
impl TestBlockDeviceConfig
Sourcepub fn generate_segments(&self) -> Vec<SegmentInfo>
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);Sourcepub fn validate(&self) -> Result<(), String>
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 validErr(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
impl Clone for TestBlockDeviceConfig
Source§fn clone(&self) -> TestBlockDeviceConfig
fn clone(&self) -> TestBlockDeviceConfig
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more