hadris_iso/read/
volume.rs1use super::super::io::{self, IsoCursor, LogicalSector, Read, Seek};
2use super::super::volume::VolumeDescriptor;
3use spin::Mutex;
4
5io_transform! {
6
7pub struct VolumeDescriptorIter<'ctx, DATA: Read + Seek> {
9 pub(crate) data: &'ctx Mutex<IsoCursor<DATA>>,
10 pub(crate) current_sector: LogicalSector,
11 pub(crate) done: bool,
12}
13
14impl<DATA: Read + Seek> VolumeDescriptorIter<'_, DATA> {
15 pub async fn next_descriptor(&mut self) -> io::Result<Option<VolumeDescriptor>> {
17 if self.done {
18 return Ok(None);
19 }
20
21 let mut data = self.data.lock();
22 let _current_offset = data.seek_sector(self.current_sector).await?;
23 self.current_sector += 1;
24
25 #[cfg(feature = "std")]
26 tracing::trace!(
27 "attempting to read volume descriptor at offset: {:#x}",
28 _current_offset
29 );
30
31 let mut buf = [0u8; 2048];
33 data.read_exact(&mut buf).await?;
34
35 let descriptor = VolumeDescriptor::new(buf);
36 if matches!(descriptor, VolumeDescriptor::End(_)) {
37 self.done = true;
38 }
39 Ok(Some(descriptor))
40 }
41}
42
43} sync_only! {
46impl<DATA: Read + Seek> Iterator for VolumeDescriptorIter<'_, DATA> {
47 type Item = io::Result<VolumeDescriptor>;
48
49 fn next(&mut self) -> Option<Self::Item> {
50 self.next_descriptor().transpose()
51 }
52}
53}