5
5
"bytes"
6
6
"encoding/binary"
7
7
"fmt"
8
- "math"
9
8
"os"
10
9
"os/exec"
11
10
"regexp"
@@ -25,6 +24,7 @@ const (
25
24
testRootDirFile = "testdata/dist/root_directory.bin"
26
25
testSuperblockFile = "testdata/dist/superblock.bin"
27
26
testFilesystemStats = "testdata/dist/stats.txt"
27
+ testKBWrittenFile = "testdata/dist/lifetime_kb.txt"
28
28
)
29
29
30
30
// TestMain sets up the test environment and runs the tests
@@ -500,22 +500,6 @@ var testSuperblockFuncs = map[string]testSuperblockFunc{
500
500
sb .reservedBlocksDefaultGID = uint16 (gid )
501
501
return nil
502
502
},
503
- "Lifetime writes" : func (sb * superblock , value string ) error {
504
- parts := strings .Split (value , " " )
505
- if len (parts ) < 2 {
506
- return fmt .Errorf ("invalid lifetime writes string %s" , value )
507
- }
508
- writes , err := strconv .ParseUint (parts [0 ], 10 , 64 )
509
- if err != nil {
510
- return fmt .Errorf ("Lifetime writes: %w" , err )
511
- }
512
- // if this is in MB, we need to convert to KB
513
- if parts [1 ] == "MB" {
514
- writes *= uint64 (KB )
515
- }
516
- sb .totalKBWritten = writes
517
- return nil
518
- },
519
503
"Filesystem flags" : func (sb * superblock , value string ) error {
520
504
flags := strings .Split (value , " " )
521
505
for _ , flag := range flags {
@@ -655,6 +639,7 @@ func testGetValidSuperblockAndGDTs() (sb *superblock, gd []groupDescriptor, supe
655
639
}
656
640
}
657
641
}
642
+
658
643
// these have been fixed. If they ever change, we will need to modify here.
659
644
sb .errorFirstTime = time .Unix (0 , 0 ).UTC ()
660
645
sb .errorLastTime = time .Unix (0 , 0 ).UTC ()
@@ -665,18 +650,15 @@ func testGetValidSuperblockAndGDTs() (sb *superblock, gd []groupDescriptor, supe
665
650
sb .journalSuperblockUUID = & juuid
666
651
sb .clusterSize = 1
667
652
668
- // this is a bit strange, but necessary. The totalKB written given by all tools round, just enough to make our calculations off
669
- // so we will adjust the value of sb to match expected if it is within 1%; good enough
670
- parsed , err := superblockFromBytes ( superblockBytes )
653
+ // lifetime writes in KB is done separately, because debug -R "stats" and dumpe2fs only
654
+ // round it out
655
+ KBWritten , err := os . ReadFile ( testKBWrittenFile )
671
656
if err != nil {
672
- return nil , nil , nil , nil , fmt .Errorf ("Failed to parse superblock bytes : %w" , err )
657
+ return nil , nil , nil , nil , fmt .Errorf ("failed to read %s : %w" , testKBWrittenFile , err )
673
658
}
674
-
675
- sbKBWritten := float64 (sb .totalKBWritten )
676
- parsedKBWritten := float64 (parsed .totalKBWritten )
677
- KBdiff := math .Abs (parsedKBWritten - sbKBWritten )
678
- if KBdiff / sbKBWritten < 0.01 {
679
- sb .totalKBWritten = parsed .totalKBWritten
659
+ sb .totalKBWritten , err = strconv .ParseUint (strings .TrimSpace (string (KBWritten )), 10 , 64 )
660
+ if err != nil {
661
+ return nil , nil , nil , nil , fmt .Errorf ("failed to parse KB written: %w" , err )
680
662
}
681
663
682
664
return sb , descs , superblockBytes , gdtBytes [:64 * len (descs )], nil
0 commit comments