diff options
Diffstat (limited to 'lib/btrfsprogs/btrfsutil/scan.go')
-rw-r--r-- | lib/btrfsprogs/btrfsutil/scan.go | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/lib/btrfsprogs/btrfsutil/scan.go b/lib/btrfsprogs/btrfsutil/scan.go index d83525c..02d4124 100644 --- a/lib/btrfsprogs/btrfsutil/scan.go +++ b/lib/btrfsprogs/btrfsutil/scan.go @@ -5,6 +5,7 @@ package btrfsutil import ( + "context" "errors" "fmt" @@ -17,7 +18,7 @@ import ( // cmds/rescue-chunk-recover.c:scan_one_device(), except rather than // doing something itself when it finds a node, it simply calls a // callback function. -func ScanForNodes(dev *btrfs.Device, sb btrfs.Superblock, fn func(*util.Ref[btrfsvol.PhysicalAddr, btrfs.Node], error), prog func(btrfsvol.PhysicalAddr)) error { +func ScanForNodes(ctx context.Context, dev *btrfs.Device, sb btrfs.Superblock, fn func(*util.Ref[btrfsvol.PhysicalAddr, btrfs.Node], error), prog func(btrfsvol.PhysicalAddr)) error { devSize, err := dev.Size() if err != nil { return err @@ -29,6 +30,9 @@ func ScanForNodes(dev *btrfs.Device, sb btrfs.Superblock, fn func(*util.Ref[btrf } for pos := btrfsvol.PhysicalAddr(0); pos+btrfsvol.PhysicalAddr(sb.NodeSize) < devSize; pos += btrfsvol.PhysicalAddr(sb.SectorSize) { + if ctx.Err() != nil { + return ctx.Err() + } if util.InSlice(pos, btrfs.SuperblockAddrs) { //fmt.Printf("sector@%v is a superblock\n", pos) continue |