diff options
Diffstat (limited to 'cmd/verify.go')
-rw-r--r-- | cmd/verify.go | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/cmd/verify.go b/cmd/verify.go index 401787f..d0360f6 100644 --- a/cmd/verify.go +++ b/cmd/verify.go @@ -25,6 +25,7 @@ func NewVerifyCommand() *cobra.Command { return cmd } +// validateThread validates a chain of nodes against a given byte slice func validateThread(blockStart int, blockEnd int, bundleSize int, diskBytes []byte, n int, dbfile string, waitGroup *sync.WaitGroup, errChan chan error) { defer waitGroup.Done() defer close(errChan) @@ -88,14 +89,17 @@ func ValidateCommand(_ *cobra.Command, args []string) error { return fmt.Errorf("Usage: fsverify verify [disk]") } header, err := core.ReadHeader(config.FsVerifyPart) + if err != nil { + return err + } + // Check if the partition is even correct + // this does not check if the partition has been tampered with + // it only checks if the specified partition is even an fsverify partition if header.MagicNumber != 0xACAB { return fmt.Errorf("sanity bit does not match. Expected %d, got %d", 0xACAB, header.MagicNumber) } - if err != nil { - return err - } fmt.Println("Reading DB") dbfile, err := core.ReadDB(config.FsVerifyPart) if err != nil { @@ -127,6 +131,8 @@ func ValidateCommand(_ *cobra.Command, args []string) error { } diskSize := diskInfo.Size() + // If the filesystem size has increased ever since the fsverify partition was created + // it would mean that fsverify is not able to verify the entire partition, making it useless if header.FilesystemSize*header.FilesystemUnit != int(diskSize) { return fmt.Errorf("disk size does not match disk size specified in header. Expected %d, got %d", header.FilesystemSize*header.FilesystemUnit, diskSize) } @@ -142,6 +148,8 @@ func ValidateCommand(_ *cobra.Command, args []string) error { errChan := make(chan error) validateFailed = false for i := 0; i < config.ProcCount; i++ { + // To ensure that each thread only uses the byte area it is meant to use, a copy of the + // area is made diskBytes, err := core.CopyByteArea(i*(int(bundleSize)), (i+1)*(int(bundleSize)), reader) if err != nil { fmt.Println("Failed to copy byte area ", i*int(bundleSize), " ", (i+1)+int(bundleSize)) |