pub struct DiskWriterState {
state: WriterState,
config: DiskWriterConfig,
current_sector: u64,
next_request_id: u32,
pending: [PendingWrite; 16],
pending_count: usize,
progress: DiskWriterProgress,
error: Option<DiskWriterError>,
}Expand description
ISO streaming disk writer state machine.
Manages non-blocking writes of ISO data to disk.
§Usage
let mut writer = DiskWriterState::new(config);
writer.start(&mut block_driver)?;
// Write chunks as they arrive from HTTP
while let Some(chunk) = http_download.next_chunk() {
match writer.write_chunk(&mut block_driver, chunk_phys, chunk.len()) {
Ok(()) => {},
Err(DiskWriterError::QueueFull) => {
// Backpressure: wait for completions
}
Err(e) => return Err(e),
}
}
// Flush and wait for all completions
writer.finish();
while writer.step(&mut block_driver).is_pending() {
// Poll completions
}Fields§
§state: WriterStateCurrent state.
config: DiskWriterConfigConfiguration.
current_sector: u64Current sector for next write.
next_request_id: u32Next request ID.
pending: [PendingWrite; 16]Pending writes.
pending_count: usizeNumber of active pending writes.
progress: DiskWriterProgressProgress tracking.
error: Option<DiskWriterError>Error (if any).
Implementations§
Source§impl DiskWriterState
impl DiskWriterState
Sourcepub fn new(config: DiskWriterConfig) -> Self
pub fn new(config: DiskWriterConfig) -> Self
Create new disk writer with configuration.
Sourcepub fn state(&self) -> WriterState
pub fn state(&self) -> WriterState
Get current state.
Sourcepub fn progress(&self) -> DiskWriterProgress
pub fn progress(&self) -> DiskWriterProgress
Get write progress.
Sourcepub fn error(&self) -> Option<DiskWriterError>
pub fn error(&self) -> Option<DiskWriterError>
Get error (if in Failed state).
Sourcepub fn can_write(&self) -> bool
pub fn can_write(&self) -> bool
Check if writer can accept more writes.
Returns false if:
- Write queue is full (backpressure)
- Writer is not in Ready/Writing state
Sourcepub fn is_complete(&self) -> bool
pub fn is_complete(&self) -> bool
Check if all writes are complete.
Sourcepub fn has_pending(&self) -> bool
pub fn has_pending(&self) -> bool
Check if writer has pending writes.
Sourcepub fn start<D: BlockDriver>(
&mut self,
driver: &D,
) -> Result<(), DiskWriterError>
pub fn start<D: BlockDriver>( &mut self, driver: &D, ) -> Result<(), DiskWriterError>
Start the writer.
Validates that disk has sufficient space.
Sourcepub fn write_chunk<D: BlockDriver>(
&mut self,
driver: &mut D,
buffer_phys: u64,
len: usize,
) -> Result<(), DiskWriterError>
pub fn write_chunk<D: BlockDriver>( &mut self, driver: &mut D, buffer_phys: u64, len: usize, ) -> Result<(), DiskWriterError>
Write a chunk of data to disk.
§Arguments
driver: Block driver to usebuffer_phys: Physical address of data bufferlen: Length of data in bytes
§Returns
Ok(()): Write submittedErr(QueueFull): Backpressure, try again after polling completionsErr(...): Write failed
§Contract
lenshould be multiple of sector_size for best performance- Buffer must remain valid until completion
Sourcepub fn finish(&mut self)
pub fn finish(&mut self)
Mark writing as finished (no more data coming).
Transitions to Flushing state to wait for pending completions.
Sourcepub fn step<D: BlockDriver>(&mut self, driver: &mut D) -> StepResult
pub fn step<D: BlockDriver>(&mut self, driver: &mut D) -> StepResult
Step the state machine (poll completions).
Should be called regularly to process write completions.
§Returns
Pending: More completions expectedDone: All writes completedFailed: A write failed
Sourcefn handle_completion(&mut self, completion: BlockCompletion)
fn handle_completion(&mut self, completion: BlockCompletion)
Process a write completion.
Sourcefn find_free_slot(&self) -> Option<usize>
fn find_free_slot(&self) -> Option<usize>
Find a free pending slot.
Sourcepub fn next_sector(&self) -> u64
pub fn next_sector(&self) -> u64
Get the next sector to write to.
Sourcepub fn remaining_bytes(&self) -> Option<u64>
pub fn remaining_bytes(&self) -> Option<u64>
Get remaining bytes to write (if total known).
Sourcepub fn set_total_bytes(&mut self, total: u64)
pub fn set_total_bytes(&mut self, total: u64)
Update total bytes (e.g., after HTTP Content-Length received).