11//! File Systems related commands for Neotron OS
22
3- use crate :: { bios , osprint, osprintln, Ctx } ;
3+ use crate :: { osprint, osprintln, Ctx , FILESYSTEM } ;
44
55pub static DIR_ITEM : menu:: Item < Ctx > = menu:: Item {
66 item_type : menu:: ItemType :: Callback {
@@ -49,17 +49,11 @@ pub static TYPE_ITEM: menu::Item<Ctx> = menu::Item {
4949
5050/// Called when the "dir" command is executed.
5151fn dir ( _menu : & menu:: Menu < Ctx > , _item : & menu:: Item < Ctx > , _args : & [ & str ] , _ctx : & mut Ctx ) {
52- fn work ( ) -> Result < ( ) , embedded_sdmmc :: Error < bios :: Error > > {
52+ fn work ( ) -> Result < ( ) , crate :: fs :: Error > {
5353 osprintln ! ( "Listing files on Block Device 0, /" ) ;
54- let bios_block = crate :: fs:: BiosBlock ( ) ;
55- let time = crate :: fs:: BiosTime ( ) ;
56- let mut mgr = embedded_sdmmc:: VolumeManager :: new ( bios_block, time) ;
57- // Open the first partition
58- let volume = mgr. open_volume ( embedded_sdmmc:: VolumeIdx ( 0 ) ) ?;
59- let root_dir = mgr. open_root_dir ( volume) ?;
60- let mut total_bytes = 0u64 ;
54+ let mut total_bytes = 0 ;
6155 let mut num_files = 0 ;
62- mgr . iterate_dir ( root_dir , |dir_entry| {
56+ FILESYSTEM . iterate_root_dir ( |dir_entry| {
6357 let padding = 8 - dir_entry. name . base_name ( ) . len ( ) ;
6458 for b in dir_entry. name . base_name ( ) {
6559 let ch = * b as char ;
@@ -124,17 +118,11 @@ fn load(_menu: &menu::Menu<Ctx>, _item: &menu::Item<Ctx>, args: &[&str], ctx: &m
124118
125119/// Called when the "exec" command is executed.
126120fn exec ( _menu : & menu:: Menu < Ctx > , _item : & menu:: Item < Ctx > , args : & [ & str ] , ctx : & mut Ctx ) {
127- fn work ( ctx : & mut Ctx , filename : & str ) -> Result < ( ) , embedded_sdmmc:: Error < bios:: Error > > {
128- let bios_block = crate :: fs:: BiosBlock ( ) ;
129- let time = crate :: fs:: BiosTime ( ) ;
130- let mut mgr = embedded_sdmmc:: VolumeManager :: new ( bios_block, time) ;
131- // Open the first partition
132- let volume = mgr. open_volume ( embedded_sdmmc:: VolumeIdx ( 0 ) ) ?;
133- let root_dir = mgr. open_root_dir ( volume) ?;
134- let file = mgr. open_file_in_dir ( root_dir, filename, embedded_sdmmc:: Mode :: ReadOnly ) ?;
121+ fn work ( ctx : & mut Ctx , filename : & str ) -> Result < ( ) , crate :: fs:: Error > {
122+ let file = FILESYSTEM . open_file ( filename, embedded_sdmmc:: Mode :: ReadOnly ) ?;
135123 let buffer = ctx. tpa . as_slice_u8 ( ) ;
136- let count = mgr . read ( file , buffer) ?;
137- if count != mgr . file_length ( file ) ? as usize {
124+ let count = file . read ( buffer) ?;
125+ if count != file . length ( ) as usize {
138126 osprintln ! ( "File too large! Max {} bytes allowed." , buffer. len( ) ) ;
139127 return Ok ( ( ) ) ;
140128 }
@@ -159,17 +147,11 @@ fn exec(_menu: &menu::Menu<Ctx>, _item: &menu::Item<Ctx>, args: &[&str], ctx: &m
159147
160148/// Called when the "type" command is executed.
161149fn typefn ( _menu : & menu:: Menu < Ctx > , _item : & menu:: Item < Ctx > , args : & [ & str ] , ctx : & mut Ctx ) {
162- fn work ( ctx : & mut Ctx , filename : & str ) -> Result < ( ) , embedded_sdmmc:: Error < bios:: Error > > {
163- let bios_block = crate :: fs:: BiosBlock ( ) ;
164- let time = crate :: fs:: BiosTime ( ) ;
165- let mut mgr = embedded_sdmmc:: VolumeManager :: new ( bios_block, time) ;
166- // Open the first partition
167- let volume = mgr. open_volume ( embedded_sdmmc:: VolumeIdx ( 0 ) ) ?;
168- let root_dir = mgr. open_root_dir ( volume) ?;
169- let file = mgr. open_file_in_dir ( root_dir, filename, embedded_sdmmc:: Mode :: ReadOnly ) ?;
150+ fn work ( ctx : & mut Ctx , filename : & str ) -> Result < ( ) , crate :: fs:: Error > {
151+ let file = FILESYSTEM . open_file ( filename, embedded_sdmmc:: Mode :: ReadOnly ) ?;
170152 let buffer = ctx. tpa . as_slice_u8 ( ) ;
171- let count = mgr . read ( file , buffer) ?;
172- if count != mgr . file_length ( file ) ? as usize {
153+ let count = file . read ( buffer) ?;
154+ if count != file . length ( ) as usize {
173155 osprintln ! ( "File too large! Max {} bytes allowed." , buffer. len( ) ) ;
174156 return Ok ( ( ) ) ;
175157 }
0 commit comments