@@ -55,6 +55,9 @@ pub struct FatVolume {
55
55
/// The block the FAT starts in. Relative to start of partition (so add
56
56
/// `self.lba_offset` before passing to volume manager)
57
57
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 > ,
58
61
/// Expected number of free clusters
59
62
pub ( crate ) free_clusters_count : Option < u32 > ,
60
63
/// Number of the next expected free cluster
@@ -118,10 +121,15 @@ impl FatVolume {
118
121
{
119
122
let mut blocks = [ Block :: new ( ) ] ;
120
123
let this_fat_block_num;
124
+ let mut second_fat_block_num = None ;
121
125
match & self . fat_specific_info {
122
126
FatSpecificInfo :: Fat16 ( _fat16_info) => {
123
127
let fat_offset = cluster. 0 * 2 ;
124
128
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
+ }
125
133
let this_fat_ent_offset = ( fat_offset % Block :: LEN_U32 ) as usize ;
126
134
block_device
127
135
. read ( & mut blocks, this_fat_block_num, "read_fat" )
@@ -143,6 +151,10 @@ impl FatVolume {
143
151
// FAT32 => 4 bytes per entry
144
152
let fat_offset = cluster. 0 * 4 ;
145
153
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
+ }
146
158
let this_fat_ent_offset = ( fat_offset % Block :: LEN_U32 ) as usize ;
147
159
block_device
148
160
. read ( & mut blocks, this_fat_block_num, "read_fat" )
@@ -166,6 +178,11 @@ impl FatVolume {
166
178
block_device
167
179
. write ( & blocks, this_fat_block_num)
168
180
. 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
+ }
169
186
Ok ( ( ) )
170
187
}
171
188
@@ -1098,6 +1115,13 @@ where
1098
1115
blocks_per_cluster : bpb. blocks_per_cluster ( ) ,
1099
1116
first_data_block : ( first_data_block) ,
1100
1117
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
+ } ,
1101
1125
free_clusters_count : None ,
1102
1126
next_free_cluster : None ,
1103
1127
cluster_count : bpb. total_clusters ( ) ,
@@ -1135,6 +1159,13 @@ where
1135
1159
blocks_per_cluster : bpb. blocks_per_cluster ( ) ,
1136
1160
first_data_block : BlockCount ( first_data_block) ,
1137
1161
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
+ } ,
1138
1169
free_clusters_count : info_sector. free_clusters_count ( ) ,
1139
1170
next_free_cluster : info_sector. next_free_cluster ( ) ,
1140
1171
cluster_count : bpb. total_clusters ( ) ,
0 commit comments