diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2022-06-26 15:53:49 -0600 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2022-06-26 15:53:49 -0600 |
commit | 6a1b5c780b8fbb9ca0285286036096960458d4e6 (patch) | |
tree | d25b258039bfcdea66fbdfd698431d2673e520ec /pkg/btrfs/io2_fs.go | |
parent | fce6934cf76f4dfb04ea6eef1e2cd55c172beb1b (diff) |
Add an AddrDelta type for safer arithmentic
Diffstat (limited to 'pkg/btrfs/io2_fs.go')
-rw-r--r-- | pkg/btrfs/io2_fs.go | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/pkg/btrfs/io2_fs.go b/pkg/btrfs/io2_fs.go index 588a60a..8b76e2d 100644 --- a/pkg/btrfs/io2_fs.go +++ b/pkg/btrfs/io2_fs.go @@ -150,20 +150,20 @@ type QualifiedPhysicalAddr struct { Addr PhysicalAddr } -func (fs *FS) Resolve(laddr LogicalAddr) (paddrs map[QualifiedPhysicalAddr]struct{}, maxlen uint64) { +func (fs *FS) Resolve(laddr LogicalAddr) (paddrs map[QualifiedPhysicalAddr]struct{}, maxlen AddrDelta) { paddrs = make(map[QualifiedPhysicalAddr]struct{}) - maxlen = math.MaxUint64 + maxlen = math.MaxInt64 for _, chunk := range fs.chunks { low := LogicalAddr(chunk.Key.Offset) - high := low + LogicalAddr(chunk.Chunk.Head.Size) + high := low.Add(chunk.Chunk.Head.Size) if low <= laddr && laddr < high { - offsetWithinChunk := uint64(laddr) - chunk.Key.Offset + offsetWithinChunk := laddr.Sub(low) maxlen = util.Min(maxlen, chunk.Chunk.Head.Size-offsetWithinChunk) for _, stripe := range chunk.Chunk.Stripes { paddrs[QualifiedPhysicalAddr{ Dev: stripe.DeviceUUID, - Addr: stripe.Offset + PhysicalAddr(offsetWithinChunk), + Addr: stripe.Offset.Add(offsetWithinChunk), }] = struct{}{} } } @@ -189,7 +189,7 @@ func (fs *FS) maybeShortReadAt(dat []byte, laddr LogicalAddr) (int, error) { if len(paddrs) == 0 { return 0, fmt.Errorf("read: could not map logical address %v", laddr) } - if uint64(len(dat)) > maxlen { + if AddrDelta(len(dat)) > maxlen { dat = dat[:maxlen] } @@ -231,7 +231,7 @@ func (fs *FS) maybeShortWriteAt(dat []byte, laddr LogicalAddr) (int, error) { if len(paddrs) == 0 { return 0, fmt.Errorf("write: could not map logical address %v", laddr) } - if uint64(len(dat)) > maxlen { + if AddrDelta(len(dat)) > maxlen { dat = dat[:maxlen] } |