aboutsummaryrefslogtreecommitdiff
path: root/cmd/verify.go
diff options
context:
space:
mode:
authoraxtloss <axtlos@getcryst.al>2024-02-18 01:19:58 +0100
committeraxtloss <axtlos@getcryst.al>2024-02-18 01:19:58 +0100
commite6c12b02674a04ca34e27b46f6ca3261fca3c677 (patch)
tree0d5d785428436bf3fcc751eb8e2be4ca0b3bfe04 /cmd/verify.go
parent6a3db4c72485aba6187466005473e287f539e3ce (diff)
downloadfsverify-e6c12b02674a04ca34e27b46f6ca3261fca3c677.tar.gz
fsverify-e6c12b02674a04ca34e27b46f6ca3261fca3c677.tar.bz2
Add comments and function descriptions
Diffstat (limited to 'cmd/verify.go')
-rw-r--r--cmd/verify.go14
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))