pub struct DiskImage { /* private fields */ }Expand description
A DiskImage represents the structure of a floppy disk. It contains a pool of track data
structures, which are indexed by a head vector which contains cylinder vectors.
A DiskImage can be created from a specified disk format using an ImageBuilder.
A DiskImage may be of two DiskDataResolution levels: ByteStream or BitStream. ByteStream images
are sourced from sector-based disk image formats, while BitStream images are sourced from
bitstream-based disk image formats.
Implementations§
Source§impl DiskImage
impl DiskImage
pub fn detect_format<RS: ReadSeek>( image: &mut RS, ) -> Result<DiskImageContainer, DiskImageError>
Sourcepub fn create(disk_format: StandardFormat) -> Self
pub fn create(disk_format: StandardFormat) -> Self
pub fn track_iter(&self) -> impl Iterator<Item = &Box<dyn Track + Send + Sync>>
pub fn track_idx_iter(&self) -> impl Iterator<Item = usize> + '_
pub fn track_ch_iter(&self) -> impl Iterator<Item = DiskCh> + '_
pub fn track(&self, ch: DiskCh) -> Option<&Box<dyn Track + Send + Sync>>
pub fn track_mut( &mut self, ch: DiskCh, ) -> Option<&mut Box<dyn Track + Send + Sync>>
pub fn track_by_idx( &self, track_idx: usize, ) -> Option<&Box<dyn Track + Send + Sync>>
pub fn track_by_idx_mut( &mut self, track_idx: usize, ) -> Option<&mut Box<dyn Track + Send + Sync>>
pub fn set_resolution(&mut self, resolution: DiskDataResolution)
pub fn set_flag(&mut self, flag: DiskImageFlags)
pub fn clear_flag(&mut self, flag: DiskImageFlags)
pub fn has_flag(&self, flag: DiskImageFlags) -> bool
pub fn required_caps(&self) -> FormatCaps
pub fn load_from_file( file_path: PathBuf, disk_selection: Option<DiskSelection>, callback: Option<Box<dyn Fn(LoadingStatus) + Send + 'static>>, ) -> Result<Self, DiskImageError>
pub fn load<RS: ReadSeek>( image_io: &mut RS, image_path: Option<PathBuf>, disk_selection: Option<DiskSelection>, callback: Option<Box<dyn Fn(LoadingStatus) + Send + 'static>>, ) -> Result<Self, DiskImageError>
pub fn set_volume_name(&mut self, name: String)
pub fn volume_name(&self) -> Option<&str>
pub fn get_comment(&self) -> Option<&str>
pub fn set_comment(&mut self, comment: String)
pub fn set_data_rate(&mut self, rate: DiskDataRate)
pub fn data_rate(&self) -> DiskDataRate
pub fn set_data_encoding(&mut self, encoding: DiskDataEncoding)
pub fn data_encoding(&self) -> DiskDataEncoding
pub fn set_image_format(&mut self, format: DiskDescriptor)
pub fn image_format(&self) -> DiskDescriptor
pub fn geometry(&self) -> DiskCh
pub fn heads(&self) -> u8
pub fn tracks(&self, head: u8) -> u16
pub fn write_ct(&self) -> u64
pub fn source_format(&self) -> Option<DiskImageFileFormat>
pub fn set_source_format(&mut self, format: DiskImageFileFormat)
Sourcepub fn resolution(&self) -> DiskDataResolution
pub fn resolution(&self) -> DiskDataResolution
Return the resolution of the disk image, either ByteStream or BitStream.
Sourcepub fn add_track_fluxstream(
&mut self,
ch: DiskCh,
track: FluxStreamTrack,
clock_hint: Option<f64>,
rpm_hint: Option<DiskRpm>,
) -> Result<&Box<dyn Track + Send + Sync>, DiskImageError>
pub fn add_track_fluxstream( &mut self, ch: DiskCh, track: FluxStreamTrack, clock_hint: Option<f64>, rpm_hint: Option<DiskRpm>, ) -> Result<&Box<dyn Track + Send + Sync>, DiskImageError>
Adds a new track to the disk image, of FluxStream resolution. Data of this resolution is sourced from FluxStream images such as Kryoflux, SCP or MFI.
This function locks the disk image to FluxStream resolution and adds a new track with the specified
data encoding, data rate, geometry, and data clock.
§Parameters
track: AFluxStreamTrackthe track to add. Unlike adding a bitstream or metasector track, we must construct a FluxStreamTrack first before adding it.
§Returns
Ok(())if the track was successfully added.Err(DiskImageError::SeekError)if the head value inchis greater than or equal to 2.Err(DiskImageError::ParameterError)if the length ofdataandweakdo not match.Err(DiskImageError::IncompatibleImage)if the disk image is not compatible withBitStreamresolution.
Sourcepub fn add_track_bitstream(
&mut self,
params: BitStreamTrackParams<'_>,
) -> Result<(), DiskImageError>
pub fn add_track_bitstream( &mut self, params: BitStreamTrackParams<'_>, ) -> Result<(), DiskImageError>
Adds a new track to the disk image, of BitStream resolution. Data of this resolution is sourced from BitStream images such as MFM, HFE or 86F.
This function locks the disk image to BitStream resolution and adds a new track with the specified
data encoding, data rate, geometry, and data clock.
§Parameters
params: ABitstreamTrackParamsstruct describing the track to be added.
§Returns
Ok(())if the track was successfully added.Err(DiskImageError::SeekError)if the head value inchis greater than or equal to 2.Err(DiskImageError::ParameterError)if the length ofdataandweakdo not match.Err(DiskImageError::IncompatibleImage)if the disk image is not compatible withBitStreamresolution.
Sourcepub fn add_track_metasector(
&mut self,
encoding: DiskDataEncoding,
data_rate: DiskDataRate,
ch: DiskCh,
) -> Result<&mut Box<dyn Track + Send + Sync>, DiskImageError>
pub fn add_track_metasector( &mut self, encoding: DiskDataEncoding, data_rate: DiskDataRate, ch: DiskCh, ) -> Result<&mut Box<dyn Track + Send + Sync>, DiskImageError>
Adds a new track to the disk image, of ByteStream resolution. Data of this resolution is typically sourced from sector-based image formats.
This function locks the disk image to ByteStream resolution and adds a new track with the
specified data encoding, data rate, and geometry.
§Parameters
data_encoding: The encoding used for the track data.data_rate: The data rate of the track.ch: The geometry of the track (cylinder and head).
§Returns
Ok(())if the track was successfully added.Err(DiskImageError::SeekError)if the head value inchis greater than or equal to 2.Err(DiskImageError::IncompatibleImage)if the disk image is not compatible withByteStreamresolution.
pub fn next_sector_on_track(&self, chs: DiskChs) -> Option<DiskChs>
Sourcepub fn read_sector(
&mut self,
phys_ch: DiskCh,
id_chs: DiskChs,
n: Option<u8>,
scope: RwSectorScope,
debug: bool,
) -> Result<ReadSectorResult, DiskImageError>
pub fn read_sector( &mut self, phys_ch: DiskCh, id_chs: DiskChs, n: Option<u8>, scope: RwSectorScope, debug: bool, ) -> Result<ReadSectorResult, DiskImageError>
Read the sector data from the sector at the physical location ‘phys_ch’ with the sector ID values specified by ‘id_chs’. The data is returned within a ReadSectorResult struct which also sets some convenience metadata flags which are needed when handling ByteStream images. When reading a BitStream image, the sector data includes the address mark and crc. Offsets are provided within ReadSectorResult so these can be skipped when processing the read operation.
pub fn write_sector( &mut self, phys_ch: DiskCh, id_chs: DiskChs, n: Option<u8>, data: &[u8], scope: RwSectorScope, deleted: bool, debug: bool, ) -> Result<WriteSectorResult, DiskImageError>
Sourcepub fn read_all_sectors(
&mut self,
phys_ch: DiskCh,
id_ch: DiskCh,
n: u8,
eot: u8,
) -> Result<ReadTrackResult, DiskImageError>
pub fn read_all_sectors( &mut self, phys_ch: DiskCh, id_ch: DiskCh, n: u8, eot: u8, ) -> Result<ReadTrackResult, DiskImageError>
Read all sectors from the track identified by ‘ch’. The data is returned within a ReadSectorResult struct which also sets some convenience metadata flags which are needed when handling ByteStream images. Unlike read_sector(), the data returned is only the actual sector data. The address marks and CRCs are not included in the data. This function is intended for use in implementing the Read Track FDC command.
Sourcepub fn read_track(
&mut self,
ch: DiskCh,
overdump: Option<usize>,
) -> Result<ReadTrackResult, DiskImageError>
pub fn read_track( &mut self, ch: DiskCh, overdump: Option<usize>, ) -> Result<ReadTrackResult, DiskImageError>
Read the track specified by ch, decoding data. The data is returned within a
ReadTrackResult struct, which crucially contains the exact length of the track data in bits.
§Parameters
ch: The cylinder and head of the track to read.overdump: An optional parameter to specify the number of bytes to read past the end of the track. This is useful for examining track wrapping behavior.
Sourcepub fn read_track_raw(
&mut self,
ch: DiskCh,
overdump: Option<usize>,
) -> Result<ReadTrackResult, DiskImageError>
pub fn read_track_raw( &mut self, ch: DiskCh, overdump: Option<usize>, ) -> Result<ReadTrackResult, DiskImageError>
Read the track specified by ch, without decoding. The data is returned within a
ReadTrackResult struct, which crucially contains the exact length of the track data in bits.
§Parameters
ch: The cylinder and head of the track to read.overdump: An optional parameter to specify the number of bytes to read past the end of the track. This is useful for examining track wrapping behavior.
pub fn add_empty_track( &mut self, ch: DiskCh, encoding: DiskDataEncoding, data_rate: DiskDataRate, bitcells: usize, ) -> Result<usize, DiskImageError>
pub fn format_track( &mut self, ch: DiskCh, format_buffer: Vec<DiskChsn>, fill_pattern: &[u8], sector_gap: usize, ) -> Result<(), DiskImageError>
Sourcepub fn reset_image(&mut self)
pub fn reset_image(&mut self)
Reset an image to an empty state.
pub fn format( &mut self, format: StandardFormat, boot_sector: Option<&[u8]>, creator: Option<&[u8; 8]>, ) -> Result<(), DiskImageError>
pub fn get_next_id(&self, chs: DiskChs) -> Option<DiskChsn>
pub fn update_standard_boot_sector( &mut self, format: StandardFormat, ) -> Result<(), DiskImageError>
Sourcepub fn boot_sector(&self) -> Option<&BootSector>
pub fn boot_sector(&self) -> Option<&BootSector>
Retrieve the DOS boot sector of the disk image, if present.
pub fn get_track_ct(&self, head: usize) -> usize
Sourcepub fn remove_empty_tracks(&mut self)
pub fn remove_empty_tracks(&mut self)
Remove tracks with no sectors from the image. This should be called with caution as sometimes disk images contain empty tracks between valid tracks.
pub fn dump_info<W: Write>(&mut self, out: W) -> Result<(), Error>
pub fn dump_consistency<W: Write>(&mut self, out: W) -> Result<(), Error>
pub fn get_sector_map(&self) -> Vec<Vec<Vec<SectorMapEntry>>>
pub fn find_duplication_mark(&self) -> Option<(DiskCh, DiskChsn)>
pub fn dump_sector_map<W: Write>(&self, out: W) -> Result<(), Error>
pub fn dump_sector_hex<W: Write>( &mut self, phys_ch: DiskCh, id_chs: DiskChs, n: Option<u8>, scope: RwSectorScope, bytes_per_row: usize, out: W, ) -> Result<(), DiskImageError>
pub fn dump_sector_string( &mut self, phys_ch: DiskCh, id_chs: DiskChs, n: Option<u8>, ) -> Result<String, DiskImageError>
pub fn has_weak_bits(&self) -> bool
Sourcepub fn compatible_formats(
&self,
writable: bool,
) -> Vec<(DiskImageFileFormat, Vec<String>)>
pub fn compatible_formats( &self, writable: bool, ) -> Vec<(DiskImageFileFormat, Vec<String>)>
Return a list of tuples representing the disk image formats that are compatible with the current image. This does not mean that fluxfox supports writing to these formats, only that the image is compatible with them.
The tuple contains the DiskImageFormat and a list of strings representing the format’s typical file extensions.
Arguments:
writable: If true, only return formats that are writable.