@@ -152,6 +152,12 @@ where
152152 Ok ( new_cluster)
153153}
154154
155+ const FAT16_IO_ERROR_BIT : u32 = 1 << 14 ;
156+ const FAT16_DIRTY_BIT : u32 = 1 << 15 ;
157+
158+ const FAT32_IO_ERROR_BIT : u32 = 1 << 26 ;
159+ const FAT32_DIRTY_BIT : u32 = 1 << 27 ;
160+
155161pub ( crate ) fn read_fat_flags < S , E > ( fat : & mut S , fat_type : FatType ) -> Result < FsStatusFlags , Error < E > >
156162where
157163 S : Read + Seek ,
@@ -166,17 +172,57 @@ where
166172 } ;
167173 let dirty = match fat_type {
168174 FatType :: Fat12 => false ,
169- FatType :: Fat16 => val & ( 1 << 15 ) == 0 ,
170- FatType :: Fat32 => val & ( 1 << 27 ) == 0 ,
175+ FatType :: Fat16 => val & FAT16_DIRTY_BIT == 0 ,
176+ FatType :: Fat32 => val & FAT32_DIRTY_BIT == 0 ,
171177 } ;
172178 let io_error = match fat_type {
173179 FatType :: Fat12 => false ,
174- FatType :: Fat16 => val & ( 1 << 14 ) == 0 ,
175- FatType :: Fat32 => val & ( 1 << 26 ) == 0 ,
180+ FatType :: Fat16 => val & FAT16_IO_ERROR_BIT == 0 ,
181+ FatType :: Fat32 => val & FAT32_IO_ERROR_BIT == 0 ,
176182 } ;
177183 Ok ( FsStatusFlags { dirty, io_error } )
178184}
179185
186+ pub ( crate ) fn write_fat_flags < S , E > ( fat : & mut S , fat_type : FatType , fat_status : FsStatusFlags ) -> Result < ( ) , Error < E > >
187+ where
188+ S : Read + Write + Seek ,
189+ E : IoError ,
190+ Error < E > : From < S :: Error > ,
191+ {
192+ match fat_type {
193+ FatType :: Fat12 => {
194+ Ok ( ( ) )
195+ } ,
196+ FatType :: Fat16 => {
197+ let mut val = 0 ;
198+
199+ if fat_status. dirty {
200+ val |= FAT16_DIRTY_BIT ;
201+ }
202+
203+ if fat_status. io_error {
204+ val |= FAT16_IO_ERROR_BIT ;
205+ }
206+
207+ Fat16 :: set ( fat, 1 , FatValue :: Data ( !val) )
208+ } ,
209+ FatType :: Fat32 => {
210+
211+ let mut val = 0 ;
212+
213+ if fat_status. dirty {
214+ val |= FAT32_DIRTY_BIT ;
215+ }
216+
217+ if fat_status. io_error {
218+ val |= FAT32_IO_ERROR_BIT ;
219+ }
220+
221+ Fat32 :: set ( fat, 1 , FatValue :: Data ( !val) )
222+ } ,
223+ }
224+ }
225+
180226pub ( crate ) fn count_free_clusters < S , E > ( fat : & mut S , fat_type : FatType , total_clusters : u32 ) -> Result < u32 , Error < E > >
181227where
182228 S : Read + Seek ,
0 commit comments