diff options
Diffstat (limited to 'lib/btrfs')
-rw-r--r-- | lib/btrfs/btrfssum/shortsum.go | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/btrfs/btrfssum/shortsum.go b/lib/btrfs/btrfssum/shortsum.go index 2d995b5..537e0ce 100644 --- a/lib/btrfs/btrfssum/shortsum.go +++ b/lib/btrfs/btrfssum/shortsum.go @@ -8,6 +8,7 @@ import ( "context" "fmt" "io" + "math" "strings" "git.lukeshu.com/go/lowmemjson" @@ -175,6 +176,19 @@ func (sg SumRunWithGaps[Addr]) PctFull() float64 { return float64(full) / float64(total) } +func (sg SumRunWithGaps[Addr]) RunForAddr(addr Addr) (SumRun[Addr], Addr, bool) { + for _, run := range sg.Runs { + if run.Addr > addr { + return SumRun[Addr]{}, run.Addr, false + } + if run.Addr.Add(run.Size()) <= addr { + continue + } + return run, 0, true + } + return SumRun[Addr]{}, math.MaxInt64, false +} + func (sg SumRunWithGaps[Addr]) SumForAddr(addr Addr) (ShortSum, error) { if addr < sg.Addr || addr >= sg.Addr.Add(sg.Size) { return "", io.EOF @@ -192,6 +206,15 @@ func (sg SumRunWithGaps[Addr]) SumForAddr(addr Addr) (ShortSum, error) { return "", diskio.ErrWildcard } +func (sg SumRunWithGaps[Addr]) Walk(ctx context.Context, fn func(Addr, ShortSum) error) error { + for _, run := range sg.Runs { + if err := run.Walk(ctx, fn); err != nil { + return err + } + } + return nil +} + // Get implements diskio.Sequence[int, ShortSum] func (sg SumRunWithGaps[Addr]) Get(sumIdx int64) (ShortSum, error) { addr := sg.Addr.Add(btrfsvol.AddrDelta(sumIdx) * BlockSize) |