1
+ use std:: fmt;
1
2
use std:: io:: { self , Read , Write } ;
2
3
3
4
use crate :: internal:: { consts, Validation , Version } ;
4
5
use crate :: { ReadLeNumber , WriteLeNumber } ;
5
6
6
7
//===========================================================================//
7
8
8
- #[ derive( Clone , Debug , PartialEq , Eq ) ]
9
+ #[ derive( Clone , PartialEq , Eq ) ]
9
10
pub struct Header {
10
11
pub version : Version ,
11
12
pub num_dir_sectors : u32 ,
@@ -18,6 +19,47 @@ pub struct Header {
18
19
pub initial_difat_entries : [ u32 ; consts:: NUM_DIFAT_ENTRIES_IN_HEADER ] ,
19
20
}
20
21
22
+ struct Sector ( u32 ) ;
23
+
24
+ impl fmt:: Debug for Sector {
25
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
26
+ match self . 0 {
27
+ consts:: FREE_SECTOR => f. write_str ( "FREE" ) ,
28
+ consts:: END_OF_CHAIN => f. write_str ( "EOC" ) ,
29
+ consts:: DIFAT_SECTOR => f. write_str ( "DIFAT" ) ,
30
+ consts:: FAT_SECTOR => f. write_str ( "FAT" ) ,
31
+ i => write ! ( f, "{i}" ) ,
32
+ }
33
+ }
34
+ }
35
+
36
+ impl fmt:: Debug for Header {
37
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
38
+ let start_nonfree = self
39
+ . initial_difat_entries
40
+ . iter ( )
41
+ . rev ( )
42
+ . skip_while ( |elt| * * elt == consts:: FREE_SECTOR )
43
+ . count ( ) ;
44
+ f. debug_struct ( "Header" )
45
+ . field ( "version" , & self . version )
46
+ . field ( "num_dir_sectors" , & self . num_dir_sectors )
47
+ . field ( "num_fat_sectors" , & self . num_fat_sectors )
48
+ . field ( "first_dir_sector" , & Sector ( self . first_dir_sector ) )
49
+ . field ( "first_minifat_sector" , & Sector ( self . first_minifat_sector ) )
50
+ . field ( "num_minifat_sectors" , & self . num_minifat_sectors )
51
+ . field ( "first_difat_sector" , & Sector ( self . first_difat_sector ) )
52
+ . field ( "num_difat_sectors" , & self . num_difat_sectors )
53
+ . field (
54
+ "initial_difat_entries" ,
55
+ & consts:: prettify (
56
+ & self . initial_difat_entries [ ..start_nonfree] ,
57
+ ) ,
58
+ )
59
+ . finish ( )
60
+ }
61
+ }
62
+
21
63
impl Header {
22
64
pub fn read_from < R : Read > (
23
65
reader : & mut R ,
0 commit comments