@@ -1104,6 +1104,13 @@ impl<'a, Storage: driver::Storage> Filesystem<'a, Storage> {
11041104 Ok ( fs)
11051105 }
11061106
1107+ fn set_alloc_config ( alloc : & mut Allocation < Storage > , storage : & mut Storage ) {
1108+ alloc. config . context = storage as * mut _ as * mut c_void ;
1109+ alloc. config . read_buffer = alloc. cache . read . get ( ) as * mut c_void ;
1110+ alloc. config . prog_buffer = alloc. cache . write . get ( ) as * mut c_void ;
1111+ alloc. config . lookahead_buffer = alloc. cache . lookahead . get ( ) as * mut c_void ;
1112+ }
1113+
11071114 /// Mount the filesystem or, if that fails, call `f` with the mount error and the storage and then try again.
11081115 pub fn mount_or_else < F > (
11091116 alloc : & ' a mut Allocation < Storage > ,
@@ -1113,9 +1120,11 @@ impl<'a, Storage: driver::Storage> Filesystem<'a, Storage> {
11131120 where
11141121 F : FnOnce ( Error , & mut Storage , & mut Allocation < Storage > ) -> Result < ( ) > ,
11151122 {
1116- let fs = Self :: new ( alloc, storage) ;
1123+ let mut fs = Self :: new ( alloc, storage) ;
11171124 if let Err ( err) = fs. raw_mount ( ) {
1118- f ( err, fs. storage , & mut fs. alloc . borrow_mut ( ) ) ?;
1125+ let alloc = fs. alloc . get_mut ( ) ;
1126+ f ( err, fs. storage , alloc) ?;
1127+ Self :: set_alloc_config ( alloc, fs. storage ) ;
11191128 fs. raw_mount ( ) ?;
11201129 }
11211130 Ok ( fs)
@@ -1130,12 +1139,7 @@ impl<'a, Storage: driver::Storage> Filesystem<'a, Storage> {
11301139
11311140 // Not public, user should use `mount`, possibly after `format`
11321141 fn new ( alloc : & ' a mut Allocation < Storage > , storage : & ' a mut Storage ) -> Self {
1133- alloc. config . context = storage as * mut _ as * mut c_void ;
1134-
1135- alloc. config . read_buffer = alloc. cache . read . get ( ) as * mut c_void ;
1136- alloc. config . prog_buffer = alloc. cache . write . get ( ) as * mut c_void ;
1137- alloc. config . lookahead_buffer = alloc. cache . lookahead . get ( ) as * mut c_void ;
1138-
1142+ Self :: set_alloc_config ( alloc, storage) ;
11391143 Filesystem {
11401144 alloc : RefCell :: new ( alloc) ,
11411145 storage,
0 commit comments