@@ -80,8 +80,9 @@ impl FatVolume {
80
80
return Ok ( ( ) ) ;
81
81
}
82
82
let mut blocks = [ Block :: new ( ) ] ;
83
+ trace ! ( "Reading info sector" ) ;
83
84
block_device
84
- . read ( & mut blocks, fat32_info. info_location , "read_info_sector" )
85
+ . read ( & mut blocks, fat32_info. info_location )
85
86
. map_err ( Error :: DeviceError ) ?;
86
87
let block = & mut blocks[ 0 ] ;
87
88
if let Some ( count) = self . free_clusters_count {
@@ -90,6 +91,7 @@ impl FatVolume {
90
91
if let Some ( next_free_cluster) = self . next_free_cluster {
91
92
block[ 492 ..496 ] . copy_from_slice ( & next_free_cluster. 0 . to_le_bytes ( ) ) ;
92
93
}
94
+ trace ! ( "Writing info sector" ) ;
93
95
block_device
94
96
. write ( & blocks, fat32_info. info_location )
95
97
. map_err ( Error :: DeviceError ) ?;
@@ -123,8 +125,9 @@ impl FatVolume {
123
125
let fat_offset = cluster. 0 * 2 ;
124
126
this_fat_block_num = self . lba_start + self . fat_start . offset_bytes ( fat_offset) ;
125
127
let this_fat_ent_offset = ( fat_offset % Block :: LEN_U32 ) as usize ;
128
+ trace ! ( "Reading FAT" ) ;
126
129
block_device
127
- . read ( & mut blocks, this_fat_block_num, "read_fat" )
130
+ . read ( & mut blocks, this_fat_block_num)
128
131
. map_err ( Error :: DeviceError ) ?;
129
132
// See <https://en.wikipedia.org/wiki/Design_of_the_FAT_file_system>
130
133
let entry = match new_value {
@@ -144,8 +147,9 @@ impl FatVolume {
144
147
let fat_offset = cluster. 0 * 4 ;
145
148
this_fat_block_num = self . lba_start + self . fat_start . offset_bytes ( fat_offset) ;
146
149
let this_fat_ent_offset = ( fat_offset % Block :: LEN_U32 ) as usize ;
150
+ trace ! ( "Reading FAT" ) ;
147
151
block_device
148
- . read ( & mut blocks, this_fat_block_num, "read_fat" )
152
+ . read ( & mut blocks, this_fat_block_num)
149
153
. map_err ( Error :: DeviceError ) ?;
150
154
let entry = match new_value {
151
155
ClusterId :: INVALID => 0x0FFF_FFF6 ,
@@ -163,6 +167,7 @@ impl FatVolume {
163
167
) ;
164
168
}
165
169
}
170
+ trace ! ( "Writing FAT" ) ;
166
171
block_device
167
172
. write ( & blocks, this_fat_block_num)
168
173
. map_err ( Error :: DeviceError ) ?;
@@ -187,8 +192,8 @@ impl FatVolume {
187
192
let fat_offset = cluster. 0 * 2 ;
188
193
let this_fat_block_num = self . lba_start + self . fat_start . offset_bytes ( fat_offset) ;
189
194
let this_fat_ent_offset = ( fat_offset % Block :: LEN_U32 ) as usize ;
190
- let block =
191
- fat_block_cache. read ( block_device, this_fat_block_num, "next_cluster" ) ?;
195
+ trace ! ( "Reading FAT" ) ;
196
+ let block = fat_block_cache. read ( block_device, this_fat_block_num) ?;
192
197
let fat_entry =
193
198
LittleEndian :: read_u16 ( & block[ this_fat_ent_offset..=this_fat_ent_offset + 1 ] ) ;
194
199
match fat_entry {
@@ -210,8 +215,8 @@ impl FatVolume {
210
215
let fat_offset = cluster. 0 * 4 ;
211
216
let this_fat_block_num = self . lba_start + self . fat_start . offset_bytes ( fat_offset) ;
212
217
let this_fat_ent_offset = ( fat_offset % Block :: LEN_U32 ) as usize ;
213
- let block =
214
- fat_block_cache. read ( block_device, this_fat_block_num, "next_cluster" ) ?;
218
+ trace ! ( "Reading FAT" ) ;
219
+ let block = fat_block_cache. read ( block_device, this_fat_block_num) ?;
215
220
let fat_entry =
216
221
LittleEndian :: read_u32 ( & block[ this_fat_ent_offset..=this_fat_ent_offset + 3 ] )
217
222
& 0x0FFF_FFFF ;
@@ -310,8 +315,9 @@ impl FatVolume {
310
315
let mut blocks = [ Block :: new ( ) ] ;
311
316
while let Some ( cluster) = current_cluster {
312
317
for block in first_dir_block_num. range ( dir_size) {
318
+ trace ! ( "Reading directory" ) ;
313
319
block_device
314
- . read ( & mut blocks, block, "read_dir" )
320
+ . read ( & mut blocks, block)
315
321
. map_err ( Error :: DeviceError ) ?;
316
322
for ( i, dir_entry_bytes) in
317
323
blocks[ 0 ] . chunks_exact_mut ( OnDiskDirEntry :: LEN ) . enumerate ( )
@@ -330,6 +336,7 @@ impl FatVolume {
330
336
) ;
331
337
dir_entry_bytes
332
338
. copy_from_slice ( & entry. serialize ( FatType :: Fat16 ) [ ..] ) ;
339
+ trace ! ( "Updating directory" ) ;
333
340
block_device
334
341
. write ( & blocks, block)
335
342
. map_err ( Error :: DeviceError ) ?;
@@ -375,8 +382,9 @@ impl FatVolume {
375
382
// Loop through the blocks in the cluster
376
383
for block in first_dir_block_num. range ( dir_size) {
377
384
// Read a block of directory entries
385
+ trace ! ( "Reading directory" ) ;
378
386
block_device
379
- . read ( & mut blocks, block, "read_dir" )
387
+ . read ( & mut blocks, block)
380
388
. map_err ( Error :: DeviceError ) ?;
381
389
// Are any entries in the block we just loaded blank? If so
382
390
// we can use them.
@@ -397,6 +405,7 @@ impl FatVolume {
397
405
) ;
398
406
dir_entry_bytes
399
407
. copy_from_slice ( & entry. serialize ( FatType :: Fat32 ) [ ..] ) ;
408
+ trace ! ( "Updating directory" ) ;
400
409
block_device
401
410
. write ( & blocks, block)
402
411
. map_err ( Error :: DeviceError ) ?;
@@ -481,7 +490,8 @@ impl FatVolume {
481
490
let mut block_cache = BlockCache :: empty ( ) ;
482
491
while let Some ( cluster) = current_cluster {
483
492
for block_idx in first_dir_block_num. range ( dir_size) {
484
- let block = block_cache. read ( block_device, block_idx, "read_dir" ) ?;
493
+ trace ! ( "Reading FAT" ) ;
494
+ let block = block_cache. read ( block_device, block_idx) ?;
485
495
for ( i, dir_entry_bytes) in block. chunks_exact ( OnDiskDirEntry :: LEN ) . enumerate ( ) {
486
496
let dir_entry = OnDiskDirEntry :: new ( dir_entry_bytes) ;
487
497
if dir_entry. is_end ( ) {
@@ -532,8 +542,9 @@ impl FatVolume {
532
542
while let Some ( cluster) = current_cluster {
533
543
let block_idx = self . cluster_to_block ( cluster) ;
534
544
for block in block_idx. range ( BlockCount ( u32:: from ( self . blocks_per_cluster ) ) ) {
545
+ trace ! ( "Reading FAT" ) ;
535
546
block_device
536
- . read ( & mut blocks, block, "read_dir" )
547
+ . read ( & mut blocks, block)
537
548
. map_err ( Error :: DeviceError ) ?;
538
549
for ( i, dir_entry_bytes) in
539
550
blocks[ 0 ] . chunks_exact_mut ( OnDiskDirEntry :: LEN ) . enumerate ( )
@@ -658,8 +669,9 @@ impl FatVolume {
658
669
D : BlockDevice ,
659
670
{
660
671
let mut blocks = [ Block :: new ( ) ] ;
672
+ trace ! ( "Reading directory" ) ;
661
673
block_device
662
- . read ( & mut blocks, block, "read_dir" )
674
+ . read ( & mut blocks, block)
663
675
. map_err ( Error :: DeviceError ) ?;
664
676
for ( i, dir_entry_bytes) in blocks[ 0 ] . chunks_exact_mut ( OnDiskDirEntry :: LEN ) . enumerate ( ) {
665
677
let dir_entry = OnDiskDirEntry :: new ( dir_entry_bytes) ;
@@ -792,8 +804,9 @@ impl FatVolume {
792
804
D : BlockDevice ,
793
805
{
794
806
let mut blocks = [ Block :: new ( ) ] ;
807
+ trace ! ( "Reading directory" ) ;
795
808
block_device
796
- . read ( & mut blocks, block, "read_dir" )
809
+ . read ( & mut blocks, block)
797
810
. map_err ( Error :: DeviceError ) ?;
798
811
for ( i, dir_entry_bytes) in blocks[ 0 ] . chunks_exact_mut ( OnDiskDirEntry :: LEN ) . enumerate ( ) {
799
812
let dir_entry = OnDiskDirEntry :: new ( dir_entry_bytes) ;
@@ -805,6 +818,7 @@ impl FatVolume {
805
818
let start = i * OnDiskDirEntry :: LEN ;
806
819
// set first byte to the 'unused' marker
807
820
blocks[ 0 ] . contents [ start] = 0xE5 ;
821
+ trace ! ( "Updating directory" ) ;
808
822
return block_device
809
823
. write ( & blocks, block)
810
824
. map_err ( Error :: DeviceError ) ;
@@ -842,7 +856,7 @@ impl FatVolume {
842
856
. map_err ( |_| Error :: ConversionError ) ?;
843
857
trace ! ( "Reading block {:?}" , this_fat_block_num) ;
844
858
block_device
845
- . read ( & mut blocks, this_fat_block_num, "next_cluster" )
859
+ . read ( & mut blocks, this_fat_block_num)
846
860
. map_err ( Error :: DeviceError ) ?;
847
861
848
862
while this_fat_ent_offset <= Block :: LEN - 2 {
@@ -873,7 +887,7 @@ impl FatVolume {
873
887
. map_err ( |_| Error :: ConversionError ) ?;
874
888
trace ! ( "Reading block {:?}" , this_fat_block_num) ;
875
889
block_device
876
- . read ( & mut blocks, this_fat_block_num, "next_cluster" )
890
+ . read ( & mut blocks, this_fat_block_num)
877
891
. map_err ( Error :: DeviceError ) ?;
878
892
879
893
while this_fat_ent_offset <= Block :: LEN - 4 {
@@ -969,6 +983,7 @@ impl FatVolume {
969
983
let first_block = self . cluster_to_block ( new_cluster) ;
970
984
let num_blocks = BlockCount ( u32:: from ( self . blocks_per_cluster ) ) ;
971
985
for block in first_block. range ( num_blocks) {
986
+ trace ! ( "Zeroing cluster" ) ;
972
987
block_device
973
988
. write ( & blocks, block)
974
989
. map_err ( Error :: DeviceError ) ?;
@@ -1041,14 +1056,16 @@ impl FatVolume {
1041
1056
FatSpecificInfo :: Fat32 ( _) => FatType :: Fat32 ,
1042
1057
} ;
1043
1058
let mut blocks = [ Block :: new ( ) ] ;
1059
+ trace ! ( "Reading directory for update" ) ;
1044
1060
block_device
1045
- . read ( & mut blocks, entry. entry_block , "read" )
1061
+ . read ( & mut blocks, entry. entry_block )
1046
1062
. map_err ( Error :: DeviceError ) ?;
1047
1063
let block = & mut blocks[ 0 ] ;
1048
1064
1049
1065
let start = usize:: try_from ( entry. entry_offset ) . map_err ( |_| Error :: ConversionError ) ?;
1050
1066
block[ start..start + 32 ] . copy_from_slice ( & entry. serialize ( fat_type) [ ..] ) ;
1051
1067
1068
+ trace ! ( "Updating directory" ) ;
1052
1069
block_device
1053
1070
. write ( & blocks, entry. entry_block )
1054
1071
. map_err ( Error :: DeviceError ) ?;
@@ -1068,8 +1085,9 @@ where
1068
1085
D :: Error : core:: fmt:: Debug ,
1069
1086
{
1070
1087
let mut blocks = [ Block :: new ( ) ] ;
1088
+ trace ! ( "Reading BPB" ) ;
1071
1089
block_device
1072
- . read ( & mut blocks, lba_start, "read_bpb" )
1090
+ . read ( & mut blocks, lba_start)
1073
1091
. map_err ( Error :: DeviceError ) ?;
1074
1092
let block = & blocks[ 0 ] ;
1075
1093
let bpb = Bpb :: create_from_bytes ( block) . map_err ( Error :: FormatError ) ?;
@@ -1112,12 +1130,9 @@ where
1112
1130
// Safe to unwrap since this is a Fat32 Type
1113
1131
let info_location = bpb. fs_info_block ( ) . unwrap ( ) ;
1114
1132
let mut info_blocks = [ Block :: new ( ) ] ;
1133
+ trace ! ( "Reading info block" ) ;
1115
1134
block_device
1116
- . read (
1117
- & mut info_blocks,
1118
- lba_start + info_location,
1119
- "read_info_sector" ,
1120
- )
1135
+ . read ( & mut info_blocks, lba_start + info_location)
1121
1136
. map_err ( Error :: DeviceError ) ?;
1122
1137
let info_block = & info_blocks[ 0 ] ;
1123
1138
let info_sector =
0 commit comments