diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2022-06-05 18:27:23 -0600 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2022-06-05 18:27:23 -0600 |
commit | 7ef276daaa132683ff8b04004f1ce5c992097d14 (patch) | |
tree | ad58a97758e9706e169125bb4f1954a880bd0a04 | |
parent | 74b109b0a75ae6648f9381252d8beb5ce6025df3 (diff) |
arrays can be compared directly
-rw-r--r-- | pkg/btrfs/crc32c.go | 5 | ||||
-rw-r--r-- | pkg/btrfs/internal/uuid.go | 5 | ||||
-rw-r--r-- | pkg/btrfs/types_btree.go | 6 | ||||
-rw-r--r-- | pkg/btrfs/types_superblock.go | 6 | ||||
-rw-r--r-- | pkg/btrfsmisc/fsck.go | 4 |
5 files changed, 9 insertions, 17 deletions
diff --git a/pkg/btrfs/crc32c.go b/pkg/btrfs/crc32c.go index 5e050cc..4ea4169 100644 --- a/pkg/btrfs/crc32c.go +++ b/pkg/btrfs/crc32c.go @@ -1,17 +1,12 @@ package btrfs import ( - "bytes" "encoding/binary" "hash/crc32" ) type CSum [0x20]byte -func (a CSum) Equal(b CSum) bool { - return bytes.Equal(a[:], b[:]) -} - func CRC32c(data []byte) CSum { crc := crc32.Update(0, crc32.MakeTable(crc32.Castagnoli), data) diff --git a/pkg/btrfs/internal/uuid.go b/pkg/btrfs/internal/uuid.go index ff274d9..6169638 100644 --- a/pkg/btrfs/internal/uuid.go +++ b/pkg/btrfs/internal/uuid.go @@ -1,7 +1,6 @@ package internal import ( - "bytes" "encoding/hex" "strings" ) @@ -18,7 +17,3 @@ func (uuid UUID) String() string { str[20:32], }, "-") } - -func (a UUID) Equal(b UUID) bool { - return bytes.Equal(a[:], b[:]) -} diff --git a/pkg/btrfs/types_btree.go b/pkg/btrfs/types_btree.go index 96b069a..8db00e2 100644 --- a/pkg/btrfs/types_btree.go +++ b/pkg/btrfs/types_btree.go @@ -229,7 +229,7 @@ func (node Node) ValidateChecksum() error { if err != nil { return err } - if !calced.Equal(stored) { + if calced != stored { return fmt.Errorf("node checksum mismatch: stored=%s calculated=%s", stored, calced) } @@ -273,7 +273,7 @@ func (fs *FS) ReadNode(addr LogicalAddr) (util.Ref[LogicalAddr, Node], error) { // sanity checking - if !node.Head.MetadataUUID.Equal(sb.Data.EffectiveMetadataUUID()) { + if node.Head.MetadataUUID != sb.Data.EffectiveMetadataUUID() { return ret, fmt.Errorf("btrfs.FS.ReadNode: node@%d: does not look like a node", addr) } @@ -284,7 +284,7 @@ func (fs *FS) ReadNode(addr LogicalAddr) (util.Ref[LogicalAddr, Node], error) { stored := node.Head.Checksum calced := CRC32c(nodeBuf[binstruct.StaticSize(CSum{}):]) - if !calced.Equal(stored) { + if calced != stored { return ret, fmt.Errorf("btrfs.FS.ReadNode: node@%d: checksum mismatch: stored=%s calculated=%s", addr, stored, calced) } diff --git a/pkg/btrfs/types_superblock.go b/pkg/btrfs/types_superblock.go index ec8b497..9cd097b 100644 --- a/pkg/btrfs/types_superblock.go +++ b/pkg/btrfs/types_superblock.go @@ -83,7 +83,7 @@ func (sb Superblock) ValidateChecksum() error { if err != nil { return err } - if !calced.Equal(stored) { + if calced != stored { return fmt.Errorf("superblock checksum mismatch: stored=%s calculated=%s", stored, calced) } @@ -226,4 +226,6 @@ var incompatFlagNames = []string{ } func (f IncompatFlags) Has(req IncompatFlags) bool { return f&req == req } -func (f IncompatFlags) String() string { return util.BitfieldString(f, incompatFlagNames, util.HexLower) } +func (f IncompatFlags) String() string { + return util.BitfieldString(f, incompatFlagNames, util.HexLower) +} diff --git a/pkg/btrfsmisc/fsck.go b/pkg/btrfsmisc/fsck.go index 527329d..77305f8 100644 --- a/pkg/btrfsmisc/fsck.go +++ b/pkg/btrfsmisc/fsck.go @@ -35,11 +35,11 @@ func ScanForNodes(dev *btrfs.Device, sb btrfs.Superblock) error { if _, err := binstruct.Unmarshal(nodeBuf, &nodeHeader); err != nil { return fmt.Errorf("sector@%d: %w", pos, err) } - if !nodeHeader.MetadataUUID.Equal(sb.EffectiveMetadataUUID()) { + if nodeHeader.MetadataUUID != sb.EffectiveMetadataUUID() { //fmt.Printf("sector@%d does not look like a node\n", pos) continue } - if !nodeHeader.Checksum.Equal(btrfs.CRC32c(nodeBuf[0x20:])) { + if nodeHeader.Checksum != btrfs.CRC32c(nodeBuf[0x20:]) { fmt.Printf("sector@%d looks like a node but is corrupt (checksum doesn't match)\n", pos) continue } |