aboutsummaryrefslogtreecommitdiff
path: root/verifysetup/cmd
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 /verifysetup/cmd
parent6a3db4c72485aba6187466005473e287f539e3ce (diff)
downloadfsverify-e6c12b02674a04ca34e27b46f6ca3261fca3c677.tar.gz
fsverify-e6c12b02674a04ca34e27b46f6ca3261fca3c677.tar.bz2
Add comments and function descriptions
Diffstat (limited to 'verifysetup/cmd')
-rw-r--r--verifysetup/cmd/setup.go21
1 files changed, 21 insertions, 0 deletions
diff --git a/verifysetup/cmd/setup.go b/verifysetup/cmd/setup.go
index c2ba790..e946dd7 100644
--- a/verifysetup/cmd/setup.go
+++ b/verifysetup/cmd/setup.go
@@ -28,12 +28,15 @@ func NewSetupCommand() *cobra.Command {
return cmd
}
+// checksumBlock is a function to create a chain of Nodes to verify an area of a block device.
+// It is meant to be run as a goroutine, taking a waitGroup as a parameter.
func checksumBlock(blockStart int, blockEnd int, bundleSize int, diskBytes []byte, nodeChannel chan verify.Node, n int, waitGroup *sync.WaitGroup) {
defer waitGroup.Done()
defer close(nodeChannel)
var reader *bytes.Reader
node := verify.Node{}
+ // A block is 2000 bytes big
blockCount := math.Floor(float64(bundleSize / 2000))
for i := 0; i < int(blockCount); i++ {
@@ -51,6 +54,8 @@ func checksumBlock(blockStart int, blockEnd int, bundleSize int, diskBytes []byt
nodeChannel <- node
}
+ // Since it is unlikely that the bundleSize is perfectly divisible by 2000
+ // a final node has to be created that includes the last amount of bytes
block, err := core.ReadBlock(int(blockCount*2000), len(diskBytes), reader)
if err != nil {
fmt.Printf("%d:: final attempted reading from %d to %d. Error %s\n", blockStart, int(blockCount*2000)+2000, len(diskBytes), err)
@@ -65,6 +70,10 @@ func SetupCommand(_ *cobra.Command, args []string) error {
if len(args) != 3 && len(args) != 4 {
return fmt.Errorf("Usage: verifysetup setup [partition] [procCount] [fsverify partition output] <minisign directory>")
}
+
+ // The minisign directory argument is optional
+ // which is why the existence of the argument is checked
+ // before minisignDir is set to a directory
var minisignDir string
if len(args) != 4 {
minisignDir = "./minisign/"
@@ -75,6 +84,7 @@ func SetupCommand(_ *cobra.Command, args []string) error {
if err != nil {
return err
}
+
fmt.Println("Using partition: ", args[0])
disk, err := os.Open(args[0])
if err != nil {
@@ -86,6 +96,7 @@ func SetupCommand(_ *cobra.Command, args []string) error {
if err != nil {
return err
}
+
diskSize := diskInfo.Size()
bundleSize := math.Floor(float64(diskSize / int64(procCount)))
blockCount := math.Ceil(float64(bundleSize / 2000))
@@ -95,10 +106,14 @@ func SetupCommand(_ *cobra.Command, args []string) error {
return err
}
+ // To decrease the amount of file operations
+ // a single reader is created that gets used for the goroutines
reader := bytes.NewReader(diskBytes)
var waitGroup sync.WaitGroup
nodeChannels := make([]chan verify.Node, procCount+1)
for i := 0; i < procCount; i++ {
+ // Ensuring that each thread only reads the area it is meant to read
+ // by making a copy of the area which it gets access to
diskBytesCopy, err := verify.CopyByteArea(i*(int(bundleSize)), (i+1)*(int(bundleSize)), reader)
if err != nil {
return err
@@ -115,6 +130,10 @@ func SetupCommand(_ *cobra.Command, args []string) error {
return err
}
+ // All generated nodes are written to the database at once
+ // while this is worse for the speed of verifysetup.
+ // it ensures that no write conflicts happen
+ // which could be caused by multiple threads accessing the same database
for i := 0; i < procCount; i++ {
channel := nodeChannels[i]
err = db.Batch(func(tx *bolt.Tx) error {
@@ -141,6 +160,8 @@ func SetupCommand(_ *cobra.Command, args []string) error {
return err
}
+ // The untrusted Signature is stored in a special way
+ // requiring special decoding of it to represent it as a string
var UntrustedSignature [2 + 8 + ed25519.SignatureSize]byte
binary.LittleEndian.PutUint16(UntrustedSignature[:2], sig.Algorithm)
binary.LittleEndian.PutUint64(UntrustedSignature[2:10], sig.KeyID)