@@ -55,6 +55,9 @@ pub struct FatVolume {
5555 /// The block the FAT starts in. Relative to start of partition (so add
5656 /// `self.lba_offset` before passing to volume manager)
5757 pub ( crate ) fat_start : BlockCount ,
58+ /// The block the second FAT starts in (if present). Relative to start of
59+ /// partition (so add `self.lba_offset` before passing to volume manager)
60+ pub ( crate ) second_fat_start : Option < BlockCount > ,
5861 /// Expected number of free clusters
5962 pub ( crate ) free_clusters_count : Option < u32 > ,
6063 /// Number of the next expected free cluster
@@ -118,10 +121,15 @@ impl FatVolume {
118121 {
119122 let mut blocks = [ Block :: new ( ) ] ;
120123 let this_fat_block_num;
124+ let mut second_fat_block_num = None ;
121125 match & self . fat_specific_info {
122126 FatSpecificInfo :: Fat16 ( _fat16_info) => {
123127 let fat_offset = cluster. 0 * 2 ;
124128 this_fat_block_num = self . lba_start + self . fat_start . offset_bytes ( fat_offset) ;
129+ if let Some ( fat_start) = self . second_fat_start {
130+ second_fat_block_num =
131+ Some ( self . lba_start + fat_start. offset_bytes ( fat_offset) ) ;
132+ }
125133 let this_fat_ent_offset = ( fat_offset % Block :: LEN_U32 ) as usize ;
126134 block_device
127135 . read ( & mut blocks, this_fat_block_num, "read_fat" )
@@ -143,6 +151,10 @@ impl FatVolume {
143151 // FAT32 => 4 bytes per entry
144152 let fat_offset = cluster. 0 * 4 ;
145153 this_fat_block_num = self . lba_start + self . fat_start . offset_bytes ( fat_offset) ;
154+ if let Some ( fat_start) = self . second_fat_start {
155+ second_fat_block_num =
156+ Some ( self . lba_start + fat_start. offset_bytes ( fat_offset) ) ;
157+ }
146158 let this_fat_ent_offset = ( fat_offset % Block :: LEN_U32 ) as usize ;
147159 block_device
148160 . read ( & mut blocks, this_fat_block_num, "read_fat" )
@@ -166,6 +178,11 @@ impl FatVolume {
166178 block_device
167179 . write ( & blocks, this_fat_block_num)
168180 . map_err ( Error :: DeviceError ) ?;
181+ if let Some ( second_fat_block_num) = second_fat_block_num {
182+ block_device
183+ . write ( & blocks, second_fat_block_num)
184+ . map_err ( Error :: DeviceError ) ?;
185+ }
169186 Ok ( ( ) )
170187 }
171188
@@ -1098,6 +1115,13 @@ where
10981115 blocks_per_cluster : bpb. blocks_per_cluster ( ) ,
10991116 first_data_block : ( first_data_block) ,
11001117 fat_start : BlockCount ( u32:: from ( bpb. reserved_block_count ( ) ) ) ,
1118+ second_fat_start : if bpb. num_fats ( ) == 2 {
1119+ Some ( BlockCount (
1120+ u32:: from ( bpb. reserved_block_count ( ) ) + bpb. fat_size ( ) ,
1121+ ) )
1122+ } else {
1123+ None
1124+ } ,
11011125 free_clusters_count : None ,
11021126 next_free_cluster : None ,
11031127 cluster_count : bpb. total_clusters ( ) ,
@@ -1135,6 +1159,13 @@ where
11351159 blocks_per_cluster : bpb. blocks_per_cluster ( ) ,
11361160 first_data_block : BlockCount ( first_data_block) ,
11371161 fat_start : BlockCount ( u32:: from ( bpb. reserved_block_count ( ) ) ) ,
1162+ second_fat_start : if bpb. num_fats ( ) == 2 {
1163+ Some ( BlockCount (
1164+ u32:: from ( bpb. reserved_block_count ( ) ) + bpb. fat_size ( ) ,
1165+ ) )
1166+ } else {
1167+ None
1168+ } ,
11381169 free_clusters_count : info_sector. free_clusters_count ( ) ,
11391170 next_free_cluster : info_sector. next_free_cluster ( ) ,
11401171 cluster_count : bpb. total_clusters ( ) ,
0 commit comments