summaryrefslogtreecommitdiff
path: root/pkg/btrfs/internal
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/btrfs/internal')
-rw-r--r--pkg/btrfs/internal/addr.go45
-rw-r--r--pkg/btrfs/internal/addr_test.go36
-rw-r--r--pkg/btrfs/internal/uuid.go74
-rw-r--r--pkg/btrfs/internal/uuid_test.go63
4 files changed, 0 insertions, 218 deletions
diff --git a/pkg/btrfs/internal/addr.go b/pkg/btrfs/internal/addr.go
deleted file mode 100644
index 09618a8..0000000
--- a/pkg/btrfs/internal/addr.go
+++ /dev/null
@@ -1,45 +0,0 @@
-package internal
-
-import (
- "fmt"
-
- "lukeshu.com/btrfs-tools/pkg/util"
-)
-
-type (
- PhysicalAddr int64
- LogicalAddr int64
- AddrDelta int64
-)
-
-func formatAddr(addr int64, f fmt.State, verb rune) {
- switch verb {
- case 'v', 's', 'q':
- str := fmt.Sprintf("%#016x", addr)
- fmt.Fprintf(f, util.FmtStateString(f, verb), str)
- default:
- fmt.Fprintf(f, util.FmtStateString(f, verb), addr)
- }
-}
-
-func (a PhysicalAddr) Format(f fmt.State, verb rune) { formatAddr(int64(a), f, verb) }
-func (a LogicalAddr) Format(f fmt.State, verb rune) { formatAddr(int64(a), f, verb) }
-func (d AddrDelta) Format(f fmt.State, verb rune) { formatAddr(int64(d), f, verb) }
-
-func (a PhysicalAddr) Sub(b PhysicalAddr) AddrDelta { return AddrDelta(a - b) }
-func (a LogicalAddr) Sub(b LogicalAddr) AddrDelta { return AddrDelta(a - b) }
-
-func (a PhysicalAddr) Add(b AddrDelta) PhysicalAddr { return a + PhysicalAddr(b) }
-func (a LogicalAddr) Add(b AddrDelta) LogicalAddr { return a + LogicalAddr(b) }
-
-type QualifiedPhysicalAddr struct {
- Dev UUID
- Addr PhysicalAddr
-}
-
-func (a QualifiedPhysicalAddr) Cmp(b QualifiedPhysicalAddr) int {
- if d := a.Dev.Cmp(b.Dev); d != 0 {
- return d
- }
- return int(a.Addr - b.Addr)
-}
diff --git a/pkg/btrfs/internal/addr_test.go b/pkg/btrfs/internal/addr_test.go
deleted file mode 100644
index 7af87bd..0000000
--- a/pkg/btrfs/internal/addr_test.go
+++ /dev/null
@@ -1,36 +0,0 @@
-package internal_test
-
-import (
- "fmt"
- "testing"
-
- "github.com/stretchr/testify/assert"
-
- "lukeshu.com/btrfs-tools/pkg/btrfs/internal"
-)
-
-func TestAddrFormat(t *testing.T) {
- t.Parallel()
- type TestCase struct {
- InputAddr internal.LogicalAddr
- InputFmt string
- Output string
- }
- addr := internal.LogicalAddr(0x3a41678000)
- testcases := map[string]TestCase{
- "v": TestCase{InputAddr: addr, InputFmt: "%v", Output: "0x0000003a41678000"},
- "s": TestCase{InputAddr: addr, InputFmt: "%s", Output: "0x0000003a41678000"},
- "q": TestCase{InputAddr: addr, InputFmt: "%q", Output: `"0x0000003a41678000"`},
- "x": TestCase{InputAddr: addr, InputFmt: "%x", Output: "3a41678000"},
- "d": TestCase{InputAddr: addr, InputFmt: "%d", Output: "250205405184"},
- "neg": TestCase{InputAddr: -1, InputFmt: "%v", Output: "-0x000000000000001"},
- }
- for tcName, tc := range testcases {
- tc := tc
- t.Run(tcName, func(t *testing.T) {
- t.Parallel()
- actual := fmt.Sprintf(tc.InputFmt, tc.InputAddr)
- assert.Equal(t, tc.Output, actual)
- })
- }
-}
diff --git a/pkg/btrfs/internal/uuid.go b/pkg/btrfs/internal/uuid.go
deleted file mode 100644
index ebfd247..0000000
--- a/pkg/btrfs/internal/uuid.go
+++ /dev/null
@@ -1,74 +0,0 @@
-package internal
-
-import (
- "encoding/hex"
- "fmt"
- "strings"
-
- "lukeshu.com/btrfs-tools/pkg/util"
-)
-
-type UUID [16]byte
-
-func (uuid UUID) String() string {
- str := hex.EncodeToString(uuid[:])
- return strings.Join([]string{
- str[:8],
- str[8:12],
- str[12:16],
- str[16:20],
- str[20:32],
- }, "-")
-}
-
-func (a UUID) Cmp(b UUID) int {
- for i := range a {
- if d := int(a[i]) - int(b[i]); d != 0 {
- return d
- }
- }
- return 0
-}
-
-func (uuid UUID) Format(f fmt.State, verb rune) {
- util.FormatByteArrayStringer(uuid, uuid[:], f, verb)
-}
-
-func ParseUUID(str string) (UUID, error) {
- var ret UUID
- j := 0
- for i := 0; i < len(str); i++ {
- if j >= len(ret)*2 {
- return UUID{}, fmt.Errorf("too long to be a UUID: %q|%q", str[:i], str[i:])
- }
- c := str[i]
- var v byte
- switch {
- case '0' <= c && c <= '9':
- v = c - '0'
- case 'a' <= c && c <= 'f':
- v = c - 'a' + 10
- case 'A' <= c && c <= 'F':
- v = c - 'A' + 10
- case c == '-':
- continue
- default:
- return UUID{}, fmt.Errorf("illegal byte in UUID: %q|%q|%q", str[:i], str[i:i+1], str[i+1:])
- }
- if j%2 == 0 {
- ret[j/2] = v << 4
- } else {
- ret[j/2] = (ret[j/2] & 0xf0) | (v & 0x0f)
- }
- j++
- }
- return ret, nil
-}
-
-func MustParseUUID(str string) UUID {
- ret, err := ParseUUID(str)
- if err != nil {
- panic(err)
- }
- return ret
-}
diff --git a/pkg/btrfs/internal/uuid_test.go b/pkg/btrfs/internal/uuid_test.go
deleted file mode 100644
index 8c78570..0000000
--- a/pkg/btrfs/internal/uuid_test.go
+++ /dev/null
@@ -1,63 +0,0 @@
-package internal_test
-
-import (
- "fmt"
- "testing"
-
- "github.com/stretchr/testify/assert"
-
- "lukeshu.com/btrfs-tools/pkg/btrfs/internal"
-)
-
-func TestParseUUID(t *testing.T) {
- t.Parallel()
- type TestCase struct {
- Input string
- OutputVal internal.UUID
- OutputErr string
- }
- testcases := map[string]TestCase{
- "basic": TestCase{Input: "a0dd94ed-e60c-42e8-8632-64e8d4765a43", OutputVal: internal.UUID{0xa0, 0xdd, 0x94, 0xed, 0xe6, 0x0c, 0x42, 0xe8, 0x86, 0x32, 0x64, 0xe8, 0xd4, 0x76, 0x5a, 0x43}},
- "too-long": TestCase{Input: "a0dd94ed-e60c-42e8-8632-64e8d4765a43a", OutputErr: `too long to be a UUID: "a0dd94ed-e60c-42e8-8632-64e8d4765a43"|"a"`},
- "bad char": TestCase{Input: "a0dd94ej-e60c-42e8-8632-64e8d4765a43a", OutputErr: `illegal byte in UUID: "a0dd94e"|"j"|"-e60c-42e8-8632-64e8d4765a43a"`},
- }
- for tcName, tc := range testcases {
- tc := tc
- t.Run(tcName, func(t *testing.T) {
- t.Parallel()
- val, err := internal.ParseUUID(tc.Input)
- assert.Equal(t, tc.OutputVal, val)
- if tc.OutputErr == "" {
- assert.NoError(t, err)
- } else {
- assert.EqualError(t, err, tc.OutputErr)
- }
- })
- }
-}
-
-func TestUUIDFormat(t *testing.T) {
- t.Parallel()
- type TestCase struct {
- InputUUID internal.UUID
- InputFmt string
- Output string
- }
- uuid := internal.MustParseUUID("a0dd94ed-e60c-42e8-8632-64e8d4765a43")
- testcases := map[string]TestCase{
- "s": TestCase{InputUUID: uuid, InputFmt: "%s", Output: "a0dd94ed-e60c-42e8-8632-64e8d4765a43"},
- "x": TestCase{InputUUID: uuid, InputFmt: "%x", Output: "a0dd94ede60c42e8863264e8d4765a43"},
- "X": TestCase{InputUUID: uuid, InputFmt: "%X", Output: "A0DD94EDE60C42E8863264E8D4765A43"},
- "v": TestCase{InputUUID: uuid, InputFmt: "%v", Output: "a0dd94ed-e60c-42e8-8632-64e8d4765a43"},
- "40s": TestCase{InputUUID: uuid, InputFmt: "|% 40s", Output: "| a0dd94ed-e60c-42e8-8632-64e8d4765a43"},
- "#115v": TestCase{InputUUID: uuid, InputFmt: "|%#115v", Output: "| internal.UUID{0xa0, 0xdd, 0x94, 0xed, 0xe6, 0xc, 0x42, 0xe8, 0x86, 0x32, 0x64, 0xe8, 0xd4, 0x76, 0x5a, 0x43}"},
- }
- for tcName, tc := range testcases {
- tc := tc
- t.Run(tcName, func(t *testing.T) {
- t.Parallel()
- actual := fmt.Sprintf(tc.InputFmt, tc.InputUUID)
- assert.Equal(t, tc.Output, actual)
- })
- }
-}