diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2022-10-08 16:25:54 -0600 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2022-10-08 19:51:37 -0600 |
commit | b9c96ea703dcc84fcd8e3c051617c25579c4e4e1 (patch) | |
tree | 736630cc6f69d70d5f959cca32fb1a2b39b5315e /lib/btrfs | |
parent | ceff7fa1fce0d6810c42ef6d57dcc2316e63c84b (diff) |
mount: Allow ignoring file checksum errors
Diffstat (limited to 'lib/btrfs')
-rw-r--r-- | lib/btrfs/io4_fs.go | 40 |
1 files changed, 21 insertions, 19 deletions
diff --git a/lib/btrfs/io4_fs.go b/lib/btrfs/io4_fs.go index 9391820..ea81bc2 100644 --- a/lib/btrfs/io4_fs.go +++ b/lib/btrfs/io4_fs.go @@ -66,7 +66,8 @@ type Subvolume struct { Superblock() (*btrfstree.Superblock, error) ReadAt(p []byte, off btrfsvol.LogicalAddr) (int, error) } - TreeID btrfsprim.ObjID + TreeID btrfsprim.ObjID + NoChecksums bool rootOnce sync.Once rootVal btrfsitem.Root @@ -414,26 +415,27 @@ func (file *File) maybeShortReadAt(dat []byte, off int64) (int, error) { if err != nil { return 0, err } + if !file.SV.NoChecksums { + sumRun, err := LookupCSum(file.SV.FS, sb.ChecksumType, blockBeg) + if err != nil { + return 0, fmt.Errorf("checksum@%v: %w", blockBeg, err) + } + _expSum, ok := sumRun.SumForAddr(blockBeg) + if !ok { + panic(fmt.Errorf("run from LookupCSum(fs, typ, %v) did not contain %v: %#v", + blockBeg, blockBeg, sumRun)) + } + expSum := _expSum.ToFullSum() - sumRun, err := LookupCSum(file.SV.FS, sb.ChecksumType, blockBeg) - if err != nil { - return 0, fmt.Errorf("checksum@%v: %w", blockBeg, err) - } - _expSum, ok := sumRun.SumForAddr(blockBeg) - if !ok { - panic(fmt.Errorf("run from LookupCSum(fs, typ, %v) did not contain %v: %#v", - blockBeg, blockBeg, sumRun)) - } - expSum := _expSum.ToFullSum() - - actSum, err := sb.ChecksumType.Sum(block[:]) - if err != nil { - return 0, fmt.Errorf("checksum@%v: %w", blockBeg, err) - } + actSum, err := sb.ChecksumType.Sum(block[:]) + if err != nil { + return 0, fmt.Errorf("checksum@%v: %w", blockBeg, err) + } - if actSum != expSum { - return 0, fmt.Errorf("checksum@%v: actual sum %v != expected sum %v", - blockBeg, actSum, expSum) + if actSum != expSum { + return 0, fmt.Errorf("checksum@%v: actual sum %v != expected sum %v", + blockBeg, actSum, expSum) + } } return n, nil } |