diff options
Diffstat (limited to 'lib/btrfsprogs')
-rw-r--r-- | lib/btrfsprogs/btrfsinspect/print_tree.go | 17 | ||||
-rw-r--r-- | lib/btrfsprogs/btrfsutil/csums.go | 12 |
2 files changed, 11 insertions, 18 deletions
diff --git a/lib/btrfsprogs/btrfsinspect/print_tree.go b/lib/btrfsprogs/btrfsinspect/print_tree.go index d7eb6f3..4dd03c4 100644 --- a/lib/btrfsprogs/btrfsinspect/print_tree.go +++ b/lib/btrfsprogs/btrfsinspect/print_tree.go @@ -203,25 +203,22 @@ func printTree(ctx context.Context, out io.Writer, fs *btrfs.FS, treeID btrfs.Ob //case btrfsitem.SHARED_DATA_REF_KEY: // // TODO case btrfsitem.ExtentCSum: - sb, _ := fs.Superblock() - sectorSize := btrfsvol.AddrDelta(sb.SectorSize) - start := btrfsvol.LogicalAddr(item.Key.Offset) - itemSize := btrfsvol.AddrDelta(len(body.Sums)) * sectorSize fmt.Fprintf(out, "\t\trange start %d end %d length %d", - start, start.Add(itemSize), itemSize) + start, start.Add(body.Size()), body.Size()) sumsPerLine := slices.Max(1, len(btrfssum.CSum{})/body.ChecksumSize/2) - pos := start - for i, sum := range body.Sums { + i := 0 + _ = body.Walk(ctx, func(pos btrfsvol.LogicalAddr, sum btrfssum.ShortSum) error { if i%sumsPerLine == 0 { fmt.Fprintf(out, "\n\t\t") } else { fmt.Fprintf(out, " ") } - fmt.Fprintf(out, "[%d] 0x%s", pos, sum.Fmt(sb.ChecksumType)) - pos = pos.Add(sectorSize) - } + fmt.Fprintf(out, "[%d] 0x%x", pos, sum) + i++ + return nil + }) fmt.Fprintf(out, "\n") case btrfsitem.FileExtent: fmt.Fprintf(out, "\t\tgeneration %v type %v\n", diff --git a/lib/btrfsprogs/btrfsutil/csums.go b/lib/btrfsprogs/btrfsutil/csums.go index 274be68..3c3d85f 100644 --- a/lib/btrfsprogs/btrfsutil/csums.go +++ b/lib/btrfsprogs/btrfsutil/csums.go @@ -37,7 +37,7 @@ func ChecksumQualifiedPhysical(fs *btrfs.FS, alg btrfssum.CSumType, paddr btrfsv return ChecksumPhysical(dev, alg, paddr.Addr) } -func LookupCSum(fs btrfs.Trees, alg btrfssum.CSumType, laddr btrfsvol.LogicalAddr) (map[btrfsvol.LogicalAddr]btrfssum.CSum, error) { +func LookupCSum(fs btrfs.Trees, alg btrfssum.CSumType, laddr btrfsvol.LogicalAddr) (btrfssum.SumRun[btrfsvol.LogicalAddr], error) { item, err := fs.TreeSearch(btrfs.CSUM_TREE_OBJECTID, func(key btrfs.Key, size uint32) int { itemBeg := btrfsvol.LogicalAddr(key.ObjectID) numSums := int64(size) / int64(alg.Size()) @@ -52,15 +52,11 @@ func LookupCSum(fs btrfs.Trees, alg btrfssum.CSumType, laddr btrfsvol.LogicalAdd } }) if err != nil { - return nil, err + return btrfssum.SumRun[btrfsvol.LogicalAddr]{}, err } body, ok := item.Body.(btrfsitem.ExtentCSum) if !ok { - return nil, fmt.Errorf("item body is %T not ExtentCSum", item.Body) + return btrfssum.SumRun[btrfsvol.LogicalAddr]{}, fmt.Errorf("item body is %T not ExtentCSum", item.Body) } - ret := make(map[btrfsvol.LogicalAddr]btrfssum.CSum, len(body.Sums)) - for i, sum := range body.Sums { - ret[btrfsvol.LogicalAddr(item.Key.ObjectID)+(btrfsvol.LogicalAddr(i)*btrfssum.BlockSize)] = sum - } - return ret, nil + return body.SumRun, nil } |