11use crate :: { dap, screen, second_stage_end} ;
22use core:: { fmt:: Write as _, slice} ;
33
4+ #[ derive( Clone ) ]
45pub struct DiskAccess {
56 pub disk_number : u16 ,
67 pub base_offset : u64 ,
78 pub current_offset : u64 ,
89}
910
10- impl fatfs:: IoBase for DiskAccess {
11- type Error = ( ) ;
12- }
13-
14- impl fatfs:: Read for DiskAccess {
15- fn read ( & mut self , buf : & mut [ u8 ] ) -> Result < usize , Self :: Error > {
11+ impl Read for DiskAccess {
12+ fn read_exact ( & mut self , buf : & mut [ u8 ] ) {
1613 writeln ! ( screen:: Writer , "read {} bytes" , buf. len( ) ) . unwrap ( ) ;
1714
1815 let end_addr = self . base_offset + self . current_offset + u64:: try_from ( buf. len ( ) ) . unwrap ( ) ;
@@ -34,35 +31,37 @@ impl fatfs::Read for DiskAccess {
3431 buf. copy_from_slice ( data) ;
3532
3633 self . current_offset = end_addr;
37- Ok ( buf. len ( ) )
3834 }
3935}
4036
41- impl fatfs :: Seek for DiskAccess {
42- fn seek ( & mut self , pos : fatfs :: SeekFrom ) -> Result < u64 , Self :: Error > {
37+ impl Seek for DiskAccess {
38+ fn seek ( & mut self , pos : SeekFrom ) -> u64 {
4339 writeln ! ( screen:: Writer , "seek to {pos:?}" ) . unwrap ( ) ;
4440 match pos {
45- fatfs :: SeekFrom :: Start ( offset) => {
41+ SeekFrom :: Start ( offset) => {
4642 self . current_offset = offset;
47- Ok ( self . current_offset )
43+ self . current_offset
4844 }
49- fatfs :: SeekFrom :: Current ( offset) => {
45+ SeekFrom :: Current ( offset) => {
5046 self . current_offset = ( i64:: try_from ( self . current_offset ) . unwrap ( ) + offset)
5147 . try_into ( )
5248 . unwrap ( ) ;
53- Ok ( self . current_offset )
49+ self . current_offset
5450 }
55- fatfs:: SeekFrom :: End ( _) => Err ( ( ) ) ,
5651 }
5752 }
5853}
5954
60- impl fatfs:: Write for DiskAccess {
61- fn write ( & mut self , buf : & [ u8 ] ) -> Result < usize , Self :: Error > {
62- unimplemented ! ( )
63- }
55+ pub trait Read {
56+ fn read_exact ( & mut self , buf : & mut [ u8 ] ) ;
57+ }
6458
65- fn flush ( & mut self ) -> Result < ( ) , Self :: Error > {
66- unimplemented ! ( )
67- }
59+ #[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
60+ pub enum SeekFrom {
61+ Start ( u64 ) ,
62+ Current ( i64 ) ,
63+ }
64+
65+ pub trait Seek {
66+ fn seek ( & mut self , pos : SeekFrom ) -> u64 ;
6867}
0 commit comments