diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2022-06-26 20:25:27 -0600 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2022-06-26 20:27:11 -0600 |
commit | 8db7bed06505569c1b41a338b5131cfd5c9d1f28 (patch) | |
tree | a33404699ab627cc71c40bdbe7062ef837c9d7d3 | |
parent | 09e3317a433add776d6539abcd7cf4f00ca984e5 (diff) |
tidy up which package things are in
-rw-r--r-- | cmd/btrfs-fsck/pass1.go | 5 | ||||
-rw-r--r-- | pkg/btrfs/Makefile | 4 | ||||
-rw-r--r-- | pkg/btrfs/aliases.go | 24 | ||||
-rw-r--r-- | pkg/btrfs/aliases_objid.go (renamed from pkg/btrfs/internal_objid.go) | 0 | ||||
-rw-r--r-- | pkg/btrfs/btrfsitem/item_blockgroup.go | 54 | ||||
-rw-r--r-- | pkg/btrfs/btrfsitem/item_chunk.go | 24 | ||||
-rw-r--r-- | pkg/btrfs/btrfsitem/item_dev.go | 5 | ||||
-rw-r--r-- | pkg/btrfs/btrfsitem/item_devextent.go | 8 | ||||
-rw-r--r-- | pkg/btrfs/btrfsitem/item_root.go | 9 | ||||
-rw-r--r-- | pkg/btrfs/btrfsvol/addr.go (renamed from pkg/btrfs/internal/addr.go) | 4 | ||||
-rw-r--r-- | pkg/btrfs/btrfsvol/addr_test.go (renamed from pkg/btrfs/internal/addr_test.go) | 8 | ||||
-rw-r--r-- | pkg/btrfs/btrfsvol/blockgroupflags.go | 51 | ||||
-rw-r--r-- | pkg/btrfs/btrfsvol/chunk.go | 3 | ||||
-rw-r--r-- | pkg/btrfs/btrfsvol/devext.go | 3 | ||||
-rw-r--r-- | pkg/btrfs/btrfsvol/lvm.go | 25 | ||||
-rw-r--r-- | pkg/btrfs/csum_test.go | 10 | ||||
-rw-r--r-- | pkg/btrfs/internal.go | 22 | ||||
-rw-r--r-- | pkg/util/uuid.go (renamed from pkg/btrfs/internal/uuid.go) | 6 | ||||
-rw-r--r-- | pkg/util/uuid_test.go (renamed from pkg/btrfs/internal/uuid_test.go) | 16 |
19 files changed, 141 insertions, 140 deletions
diff --git a/cmd/btrfs-fsck/pass1.go b/cmd/btrfs-fsck/pass1.go index 734ee40..7798650 100644 --- a/cmd/btrfs-fsck/pass1.go +++ b/cmd/btrfs-fsck/pass1.go @@ -10,6 +10,7 @@ import ( "lukeshu.com/btrfs-tools/pkg/btrfs" "lukeshu.com/btrfs-tools/pkg/btrfs/btrfsitem" + "lukeshu.com/btrfs-tools/pkg/btrfs/btrfsvol" "lukeshu.com/btrfs-tools/pkg/btrfsmisc" "lukeshu.com/btrfs-tools/pkg/util" ) @@ -339,7 +340,7 @@ func pass1ProcessBlockGroups(blockgroups []sysBlockGroup) { // organize in to a more manageable datastructure type groupAttrs struct { Size btrfs.AddrDelta - Flags btrfsitem.BlockGroupFlags + Flags btrfsvol.BlockGroupFlags } groups := make(map[btrfs.LogicalAddr]groupAttrs) for _, bg := range blockgroups { @@ -370,7 +371,7 @@ func pass1ProcessBlockGroups(blockgroups []sysBlockGroup) { type cluster struct { LAddr btrfs.LogicalAddr Size btrfs.AddrDelta - Flags btrfsitem.BlockGroupFlags + Flags btrfsvol.BlockGroupFlags } var clusters []*cluster for _, laddr := range sortedLAddrs { diff --git a/pkg/btrfs/Makefile b/pkg/btrfs/Makefile index 4bc4219..a770356 100644 --- a/pkg/btrfs/Makefile +++ b/pkg/btrfs/Makefile @@ -57,7 +57,7 @@ internal/itemtype.go: btrfsitem/items.txt $(MAKEFILE_LIST) } | gofmt >$@ files += internal/itemtype.go -internal_objid.go: internal/objid.go $(MAKEFILE_LIST) +aliases_objid.go: internal/objid.go $(MAKEFILE_LIST) { \ echo '// Code generated by Make. DO NOT EDIT.'; \ echo; \ @@ -69,7 +69,7 @@ internal_objid.go: internal/objid.go $(MAKEFILE_LIST) sed -En 's/^\s*(\S*_OBJECTIDS?)\s*=.*/\1 = internal.\1/p' <$<; \ echo ')'; \ } | gofmt >$@ -files += internal_objid.go +files += aliases_objid.go all: $(files) .PHONY: all diff --git a/pkg/btrfs/aliases.go b/pkg/btrfs/aliases.go new file mode 100644 index 0000000..22508c3 --- /dev/null +++ b/pkg/btrfs/aliases.go @@ -0,0 +1,24 @@ +package btrfs + +import ( + "lukeshu.com/btrfs-tools/pkg/btrfs/btrfsvol" + "lukeshu.com/btrfs-tools/pkg/btrfs/internal" + "lukeshu.com/btrfs-tools/pkg/util" +) + +type ( + // (u)int64 types + + Generation = internal.Generation + ObjID = internal.ObjID + LogicalAddr = btrfsvol.LogicalAddr + PhysicalAddr = btrfsvol.PhysicalAddr + AddrDelta = btrfsvol.AddrDelta + + // complex types + + Key = internal.Key + Time = internal.Time + UUID = util.UUID + QualifiedPhysicalAddr = btrfsvol.QualifiedPhysicalAddr +) diff --git a/pkg/btrfs/internal_objid.go b/pkg/btrfs/aliases_objid.go index 12a58a2..12a58a2 100644 --- a/pkg/btrfs/internal_objid.go +++ b/pkg/btrfs/aliases_objid.go diff --git a/pkg/btrfs/btrfsitem/item_blockgroup.go b/pkg/btrfs/btrfsitem/item_blockgroup.go index 737cfa0..8f7847d 100644 --- a/pkg/btrfs/btrfsitem/item_blockgroup.go +++ b/pkg/btrfs/btrfsitem/item_blockgroup.go @@ -2,61 +2,15 @@ package btrfsitem import ( "lukeshu.com/btrfs-tools/pkg/binstruct" + "lukeshu.com/btrfs-tools/pkg/btrfs/btrfsvol" "lukeshu.com/btrfs-tools/pkg/btrfs/internal" - "lukeshu.com/btrfs-tools/pkg/util" ) // key.objectid = logical_addr // key.offset = size of chunk type BlockGroup struct { // BLOCK_GROUP_ITEM=192 - Used int64 `bin:"off=0, siz=8"` - ChunkObjectID internal.ObjID `bin:"off=8, siz=8"` - Flags BlockGroupFlags `bin:"off=16, siz=8"` + Used int64 `bin:"off=0, siz=8"` + ChunkObjectID internal.ObjID `bin:"off=8, siz=8"` + Flags btrfsvol.BlockGroupFlags `bin:"off=16, siz=8"` binstruct.End `bin:"off=24"` } - -type BlockGroupFlags uint64 - -const ( - BLOCK_GROUP_DATA = BlockGroupFlags(1 << iota) - BLOCK_GROUP_SYSTEM - BLOCK_GROUP_METADATA - BLOCK_GROUP_RAID0 - BLOCK_GROUP_RAID1 - BLOCK_GROUP_DUP - BLOCK_GROUP_RAID10 - BLOCK_GROUP_RAID5 - BLOCK_GROUP_RAID6 - BLOCK_GROUP_RAID1C3 - BLOCK_GROUP_RAID1C4 - - BLOCK_GROUP_RAID_MASK = (BLOCK_GROUP_RAID1 | BLOCK_GROUP_DUP | BLOCK_GROUP_RAID10 | BLOCK_GROUP_RAID5 | BLOCK_GROUP_RAID6 | BLOCK_GROUP_RAID1C3 | BLOCK_GROUP_RAID1C4) -) - -var blockGroupFlagNames = []string{ - "DATA", - "SYSTEM", - "METADATA", - - "RAID0", - "RAID1", - "DUP", - "RAID10", - "RAID5", - "RAID6", - "RAID1C3", - "RAID1C4", -} - -func (f BlockGroupFlags) Has(req BlockGroupFlags) bool { return f&req == req } -func (f BlockGroupFlags) String() string { - ret := util.BitfieldString(f, blockGroupFlagNames, util.HexNone) - if f&BLOCK_GROUP_RAID_MASK == 0 { - if ret == "" { - ret = "single" - } else { - ret += "|single" - } - } - return ret -} diff --git a/pkg/btrfs/btrfsitem/item_chunk.go b/pkg/btrfs/btrfsitem/item_chunk.go index 8f98ba1..a77ae33 100644 --- a/pkg/btrfs/btrfsitem/item_chunk.go +++ b/pkg/btrfs/btrfsitem/item_chunk.go @@ -4,7 +4,9 @@ import ( "fmt" "lukeshu.com/btrfs-tools/pkg/binstruct" + "lukeshu.com/btrfs-tools/pkg/btrfs/btrfsvol" "lukeshu.com/btrfs-tools/pkg/btrfs/internal" + "lukeshu.com/btrfs-tools/pkg/util" ) // Maps logical address to physical. @@ -17,22 +19,22 @@ type Chunk struct { // CHUNK_ITEM=228 } type ChunkHeader struct { - Size internal.AddrDelta `bin:"off=0x0, siz=0x8"` - Owner internal.ObjID `bin:"off=0x8, siz=0x8"` // root referencing this chunk (always EXTENT_TREE_OBJECTID=2) - StripeLen uint64 `bin:"off=0x10, siz=0x8"` // ??? - Type BlockGroupFlags `bin:"off=0x18, siz=0x8"` - IOOptimalAlign uint32 `bin:"off=0x20, siz=0x4"` - IOOptimalWidth uint32 `bin:"off=0x24, siz=0x4"` - IOMinSize uint32 `bin:"off=0x28, siz=0x4"` // sector size - NumStripes uint16 `bin:"off=0x2c, siz=0x2"` // [ignored-when-writing] - SubStripes uint16 `bin:"off=0x2e, siz=0x2"` // ??? + Size btrfsvol.AddrDelta `bin:"off=0x0, siz=0x8"` + Owner internal.ObjID `bin:"off=0x8, siz=0x8"` // root referencing this chunk (always EXTENT_TREE_OBJECTID=2) + StripeLen uint64 `bin:"off=0x10, siz=0x8"` // ??? + Type btrfsvol.BlockGroupFlags `bin:"off=0x18, siz=0x8"` + IOOptimalAlign uint32 `bin:"off=0x20, siz=0x4"` + IOOptimalWidth uint32 `bin:"off=0x24, siz=0x4"` + IOMinSize uint32 `bin:"off=0x28, siz=0x4"` // sector size + NumStripes uint16 `bin:"off=0x2c, siz=0x2"` // [ignored-when-writing] + SubStripes uint16 `bin:"off=0x2e, siz=0x2"` // ??? binstruct.End `bin:"off=0x30"` } type ChunkStripe struct { DeviceID internal.ObjID `bin:"off=0x0, siz=0x8"` - Offset internal.PhysicalAddr `bin:"off=0x8, siz=0x8"` - DeviceUUID internal.UUID `bin:"off=0x10, siz=0x10"` + Offset btrfsvol.PhysicalAddr `bin:"off=0x8, siz=0x8"` + DeviceUUID util.UUID `bin:"off=0x10, siz=0x10"` binstruct.End `bin:"off=0x20"` } diff --git a/pkg/btrfs/btrfsitem/item_dev.go b/pkg/btrfs/btrfsitem/item_dev.go index 9851002..848f338 100644 --- a/pkg/btrfs/btrfsitem/item_dev.go +++ b/pkg/btrfs/btrfsitem/item_dev.go @@ -3,6 +3,7 @@ package btrfsitem import ( "lukeshu.com/btrfs-tools/pkg/binstruct" "lukeshu.com/btrfs-tools/pkg/btrfs/internal" + "lukeshu.com/btrfs-tools/pkg/util" ) type Dev struct { // DEV_ITEM=216 @@ -22,8 +23,8 @@ type Dev struct { // DEV_ITEM=216 SeekSpeed uint8 `bin:"off=0x40, siz=0x1"` Bandwidth uint8 `bin:"off=0x41, siz=0x1"` - DevUUID internal.UUID `bin:"off=0x42, siz=0x10"` - FSUUID internal.UUID `bin:"off=0x52, siz=0x10"` + DevUUID util.UUID `bin:"off=0x42, siz=0x10"` + FSUUID util.UUID `bin:"off=0x52, siz=0x10"` binstruct.End `bin:"off=0x62"` } diff --git a/pkg/btrfs/btrfsitem/item_devextent.go b/pkg/btrfs/btrfsitem/item_devextent.go index 7f08b5e..03d696a 100644 --- a/pkg/btrfs/btrfsitem/item_devextent.go +++ b/pkg/btrfs/btrfsitem/item_devextent.go @@ -2,7 +2,9 @@ package btrfsitem import ( "lukeshu.com/btrfs-tools/pkg/binstruct" + "lukeshu.com/btrfs-tools/pkg/btrfs/btrfsvol" "lukeshu.com/btrfs-tools/pkg/btrfs/internal" + "lukeshu.com/btrfs-tools/pkg/util" ) // key.objectid = device_id @@ -10,8 +12,8 @@ import ( type DevExtent struct { // DEV_EXTENT=204 ChunkTree int64 `bin:"off=0, siz=8"` ChunkObjectID internal.ObjID `bin:"off=8, siz=8"` - ChunkOffset internal.LogicalAddr `bin:"off=16, siz=8"` - Length internal.AddrDelta `bin:"off=24, siz=8"` - ChunkTreeUUID internal.UUID `bin:"off=32, siz=16"` + ChunkOffset btrfsvol.LogicalAddr `bin:"off=16, siz=8"` + Length btrfsvol.AddrDelta `bin:"off=24, siz=8"` + ChunkTreeUUID util.UUID `bin:"off=32, siz=16"` binstruct.End `bin:"off=48"` } diff --git a/pkg/btrfs/btrfsitem/item_root.go b/pkg/btrfs/btrfsitem/item_root.go index f0a961b..bdf1b7b 100644 --- a/pkg/btrfs/btrfsitem/item_root.go +++ b/pkg/btrfs/btrfsitem/item_root.go @@ -2,6 +2,7 @@ package btrfsitem import ( "lukeshu.com/btrfs-tools/pkg/binstruct" + "lukeshu.com/btrfs-tools/pkg/btrfs/btrfsvol" "lukeshu.com/btrfs-tools/pkg/btrfs/internal" "lukeshu.com/btrfs-tools/pkg/util" ) @@ -10,7 +11,7 @@ type Root struct { // ROOT_ITEM=132 Inode Inode `bin:"off=0x0, siz=0xa0"` Generation internal.Generation `bin:"off=0xa0, siz=0x8"` RootDirID int64 `bin:"off=0xa8, siz=0x8"` - ByteNr internal.LogicalAddr `bin:"off=0xb0, siz=0x8"` + ByteNr btrfsvol.LogicalAddr `bin:"off=0xb0, siz=0x8"` ByteLimit int64 `bin:"off=0xb8, siz=0x8"` BytesUsed int64 `bin:"off=0xc0, siz=0x8"` LastSnapshot int64 `bin:"off=0xc8, siz=0x8"` @@ -20,9 +21,9 @@ type Root struct { // ROOT_ITEM=132 DropLevel uint8 `bin:"off=0xed, siz=0x1"` Level uint8 `bin:"off=0xee, siz=0x1"` GenerationV2 internal.Generation `bin:"off=0xef, siz=0x8"` - UUID internal.UUID `bin:"off=0xF7, siz=0x10"` - ParentUUID internal.UUID `bin:"off=0x107, siz=0x10"` - ReceivedUUID internal.UUID `bin:"off=0x117, siz=0x10"` + UUID util.UUID `bin:"off=0xF7, siz=0x10"` + ParentUUID util.UUID `bin:"off=0x107, siz=0x10"` + ReceivedUUID util.UUID `bin:"off=0x117, siz=0x10"` CTransID int64 `bin:"off=0x127, siz=0x8"` OTransID int64 `bin:"off=0x12f, siz=0x8"` STransID int64 `bin:"off=0x137, siz=0x8"` diff --git a/pkg/btrfs/internal/addr.go b/pkg/btrfs/btrfsvol/addr.go index 09618a8..e8b578a 100644 --- a/pkg/btrfs/internal/addr.go +++ b/pkg/btrfs/btrfsvol/addr.go @@ -1,4 +1,4 @@ -package internal +package btrfsvol import ( "fmt" @@ -33,7 +33,7 @@ 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 + Dev util.UUID Addr PhysicalAddr } diff --git a/pkg/btrfs/internal/addr_test.go b/pkg/btrfs/btrfsvol/addr_test.go index 7af87bd..83af1ac 100644 --- a/pkg/btrfs/internal/addr_test.go +++ b/pkg/btrfs/btrfsvol/addr_test.go @@ -1,4 +1,4 @@ -package internal_test +package btrfsvol_test import ( "fmt" @@ -6,17 +6,17 @@ import ( "github.com/stretchr/testify/assert" - "lukeshu.com/btrfs-tools/pkg/btrfs/internal" + "lukeshu.com/btrfs-tools/pkg/btrfs/btrfsvol" ) func TestAddrFormat(t *testing.T) { t.Parallel() type TestCase struct { - InputAddr internal.LogicalAddr + InputAddr btrfsvol.LogicalAddr InputFmt string Output string } - addr := internal.LogicalAddr(0x3a41678000) + addr := btrfsvol.LogicalAddr(0x3a41678000) testcases := map[string]TestCase{ "v": TestCase{InputAddr: addr, InputFmt: "%v", Output: "0x0000003a41678000"}, "s": TestCase{InputAddr: addr, InputFmt: "%s", Output: "0x0000003a41678000"}, diff --git a/pkg/btrfs/btrfsvol/blockgroupflags.go b/pkg/btrfs/btrfsvol/blockgroupflags.go new file mode 100644 index 0000000..ba1610b --- /dev/null +++ b/pkg/btrfs/btrfsvol/blockgroupflags.go @@ -0,0 +1,51 @@ +package btrfsvol + +import ( + "lukeshu.com/btrfs-tools/pkg/util" +) + +type BlockGroupFlags uint64 + +const ( + BLOCK_GROUP_DATA = BlockGroupFlags(1 << iota) + BLOCK_GROUP_SYSTEM + BLOCK_GROUP_METADATA + BLOCK_GROUP_RAID0 + BLOCK_GROUP_RAID1 + BLOCK_GROUP_DUP + BLOCK_GROUP_RAID10 + BLOCK_GROUP_RAID5 + BLOCK_GROUP_RAID6 + BLOCK_GROUP_RAID1C3 + BLOCK_GROUP_RAID1C4 + + BLOCK_GROUP_RAID_MASK = (BLOCK_GROUP_RAID1 | BLOCK_GROUP_DUP | BLOCK_GROUP_RAID10 | BLOCK_GROUP_RAID5 | BLOCK_GROUP_RAID6 | BLOCK_GROUP_RAID1C3 | BLOCK_GROUP_RAID1C4) +) + +var blockGroupFlagNames = []string{ + "DATA", + "SYSTEM", + "METADATA", + + "RAID0", + "RAID1", + "DUP", + "RAID10", + "RAID5", + "RAID6", + "RAID1C3", + "RAID1C4", +} + +func (f BlockGroupFlags) Has(req BlockGroupFlags) bool { return f&req == req } +func (f BlockGroupFlags) String() string { + ret := util.BitfieldString(f, blockGroupFlagNames, util.HexNone) + if f&BLOCK_GROUP_RAID_MASK == 0 { + if ret == "" { + ret = "single" + } else { + ret += "|single" + } + } + return ret +} diff --git a/pkg/btrfs/btrfsvol/chunk.go b/pkg/btrfs/btrfsvol/chunk.go index 112d446..e53265f 100644 --- a/pkg/btrfs/btrfsvol/chunk.go +++ b/pkg/btrfs/btrfsvol/chunk.go @@ -4,7 +4,6 @@ import ( "fmt" "sort" - "lukeshu.com/btrfs-tools/pkg/btrfs/btrfsitem" "lukeshu.com/btrfs-tools/pkg/util" ) @@ -13,7 +12,7 @@ type chunkMapping struct { LAddr LogicalAddr PAddrs []QualifiedPhysicalAddr Size AddrDelta - Flags *btrfsitem.BlockGroupFlags + Flags *BlockGroupFlags } // return -1 if 'a' is wholly to the left of 'b' diff --git a/pkg/btrfs/btrfsvol/devext.go b/pkg/btrfs/btrfsvol/devext.go index 7696624..736d39b 100644 --- a/pkg/btrfs/btrfsvol/devext.go +++ b/pkg/btrfs/btrfsvol/devext.go @@ -3,7 +3,6 @@ package btrfsvol import ( "fmt" - "lukeshu.com/btrfs-tools/pkg/btrfs/btrfsitem" "lukeshu.com/btrfs-tools/pkg/util" ) @@ -12,7 +11,7 @@ type devextMapping struct { PAddr PhysicalAddr LAddr LogicalAddr Size AddrDelta - Flags *btrfsitem.BlockGroupFlags + Flags *BlockGroupFlags } // return -1 if 'a' is wholly to the left of 'b' diff --git a/pkg/btrfs/btrfsvol/lvm.go b/pkg/btrfs/btrfsvol/lvm.go index dc3bd06..a74e82c 100644 --- a/pkg/btrfs/btrfsvol/lvm.go +++ b/pkg/btrfs/btrfsvol/lvm.go @@ -7,27 +7,18 @@ import ( "reflect" "sort" - "lukeshu.com/btrfs-tools/pkg/btrfs/btrfsitem" - "lukeshu.com/btrfs-tools/pkg/btrfs/internal" "lukeshu.com/btrfs-tools/pkg/util" ) -type ( - LogicalAddr = internal.LogicalAddr - PhysicalAddr = internal.PhysicalAddr - AddrDelta = internal.AddrDelta - QualifiedPhysicalAddr = internal.QualifiedPhysicalAddr -) - type PhysicalVolume = util.File[PhysicalAddr] type LogicalVolume struct { name string - uuid2pv map[internal.UUID]PhysicalVolume + uuid2pv map[util.UUID]PhysicalVolume logical2physical []chunkMapping - physical2logical map[internal.UUID][]devextMapping + physical2logical map[util.UUID][]devextMapping } var _ util.File[LogicalAddr] = (*LogicalVolume)(nil) @@ -48,9 +39,9 @@ func (lv *LogicalVolume) Size() (LogicalAddr, error) { return lastChunk.LAddr.Add(lastChunk.Size), nil } -func (lv *LogicalVolume) AddPhysicalVolume(uuid internal.UUID, dev PhysicalVolume) error { +func (lv *LogicalVolume) AddPhysicalVolume(uuid util.UUID, dev PhysicalVolume) error { if lv.uuid2pv == nil { - lv.uuid2pv = make(map[internal.UUID]PhysicalVolume) + lv.uuid2pv = make(map[util.UUID]PhysicalVolume) } if other, exists := lv.uuid2pv[uuid]; exists { return fmt.Errorf("(%p).AddPhysicalVolume: cannot add physical volume %q: already have physical volume %q with uuid=%v", @@ -61,7 +52,7 @@ func (lv *LogicalVolume) AddPhysicalVolume(uuid internal.UUID, dev PhysicalVolum } func (lv *LogicalVolume) PhysicalVolumes() []PhysicalVolume { - uuids := make([]internal.UUID, 0, len(lv.uuid2pv)) + uuids := make([]util.UUID, 0, len(lv.uuid2pv)) for uuid := range lv.uuid2pv { uuids = append(uuids, uuid) } @@ -80,14 +71,14 @@ func (lv *LogicalVolume) ClearMappings() { lv.physical2logical = nil } -func (lv *LogicalVolume) AddMapping(laddr LogicalAddr, paddr QualifiedPhysicalAddr, size AddrDelta, flags *btrfsitem.BlockGroupFlags) error { +func (lv *LogicalVolume) AddMapping(laddr LogicalAddr, paddr QualifiedPhysicalAddr, size AddrDelta, flags *BlockGroupFlags) error { // sanity check if _, haveDev := lv.uuid2pv[paddr.Dev]; !haveDev { return fmt.Errorf("(%p).AddMapping: do not have a physical volume with uuid=%v", lv, paddr.Dev) } if lv.physical2logical == nil { - lv.physical2logical = make(map[internal.UUID][]devextMapping) + lv.physical2logical = make(map[util.UUID][]devextMapping) } // logical2physical @@ -171,7 +162,7 @@ func (lv *LogicalVolume) AddMapping(laddr LogicalAddr, paddr QualifiedPhysicalAd } func (lv *LogicalVolume) fsck() error { - physical2logical := make(map[internal.UUID][]devextMapping) + physical2logical := make(map[util.UUID][]devextMapping) for _, chunk := range lv.logical2physical { for _, stripe := range chunk.PAddrs { if _, devOK := lv.uuid2pv[stripe.Dev]; !devOK { diff --git a/pkg/btrfs/csum_test.go b/pkg/btrfs/csum_test.go index 335b3cc..92badb1 100644 --- a/pkg/btrfs/csum_test.go +++ b/pkg/btrfs/csum_test.go @@ -18,11 +18,11 @@ func TestCSumFormat(t *testing.T) { } csum := btrfs.CSum{0xbd, 0x7b, 0x41, 0xf4, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0} testcases := map[string]TestCase{ - "s": TestCase{InputSum: csum, InputFmt: "%s", Output: "bd7b41f400000000000000000000000000000000000000000000000000000000"}, - "x": TestCase{InputSum: csum, InputFmt: "%x", Output: "bd7b41f400000000000000000000000000000000000000000000000000000000"}, - "v": TestCase{InputSum: csum, InputFmt: "%v", Output: "bd7b41f400000000000000000000000000000000000000000000000000000000"}, - "70s": TestCase{InputSum: csum, InputFmt: "|% 70s", Output: "| bd7b41f400000000000000000000000000000000000000000000000000000000"}, - "#180v": TestCase{InputSum: csum, InputFmt: "%#180v", Output: " btrfs.CSum{0xbd, 0x7b, 0x41, 0xf4, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}"}, + "s": TestCase{InputSum: csum, InputFmt: "%s", Output: "bd7b41f400000000000000000000000000000000000000000000000000000000"}, + "x": TestCase{InputSum: csum, InputFmt: "%x", Output: "bd7b41f400000000000000000000000000000000000000000000000000000000"}, + "v": TestCase{InputSum: csum, InputFmt: "%v", Output: "bd7b41f400000000000000000000000000000000000000000000000000000000"}, + "70s": TestCase{InputSum: csum, InputFmt: "|% 70s", Output: "| bd7b41f400000000000000000000000000000000000000000000000000000000"}, + "#180v": TestCase{InputSum: csum, InputFmt: "%#180v", Output: " btrfs.CSum{0xbd, 0x7b, 0x41, 0xf4, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}"}, } for tcName, tc := range testcases { tc := tc diff --git a/pkg/btrfs/internal.go b/pkg/btrfs/internal.go deleted file mode 100644 index ad1e20b..0000000 --- a/pkg/btrfs/internal.go +++ /dev/null @@ -1,22 +0,0 @@ -package btrfs - -import ( - "lukeshu.com/btrfs-tools/pkg/btrfs/internal" -) - -type ( - // (u)int64 types - - Generation = internal.Generation - ObjID = internal.ObjID - LogicalAddr = internal.LogicalAddr - PhysicalAddr = internal.PhysicalAddr - AddrDelta = internal.AddrDelta - - // complex types - - Key = internal.Key - Time = internal.Time - UUID = internal.UUID - QualifiedPhysicalAddr = internal.QualifiedPhysicalAddr -) diff --git a/pkg/btrfs/internal/uuid.go b/pkg/util/uuid.go index ebfd247..3b4cbaf 100644 --- a/pkg/btrfs/internal/uuid.go +++ b/pkg/util/uuid.go @@ -1,11 +1,9 @@ -package internal +package util import ( "encoding/hex" "fmt" "strings" - - "lukeshu.com/btrfs-tools/pkg/util" ) type UUID [16]byte @@ -31,7 +29,7 @@ func (a UUID) Cmp(b UUID) int { } func (uuid UUID) Format(f fmt.State, verb rune) { - util.FormatByteArrayStringer(uuid, uuid[:], f, verb) + FormatByteArrayStringer(uuid, uuid[:], f, verb) } func ParseUUID(str string) (UUID, error) { diff --git a/pkg/btrfs/internal/uuid_test.go b/pkg/util/uuid_test.go index 8c78570..8b3302a 100644 --- a/pkg/btrfs/internal/uuid_test.go +++ b/pkg/util/uuid_test.go @@ -1,4 +1,4 @@ -package internal_test +package util_test import ( "fmt" @@ -6,18 +6,18 @@ import ( "github.com/stretchr/testify/assert" - "lukeshu.com/btrfs-tools/pkg/btrfs/internal" + "lukeshu.com/btrfs-tools/pkg/util" ) func TestParseUUID(t *testing.T) { t.Parallel() type TestCase struct { Input string - OutputVal internal.UUID + OutputVal util.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}}, + "basic": TestCase{Input: "a0dd94ed-e60c-42e8-8632-64e8d4765a43", OutputVal: util.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"`}, } @@ -25,7 +25,7 @@ func TestParseUUID(t *testing.T) { tc := tc t.Run(tcName, func(t *testing.T) { t.Parallel() - val, err := internal.ParseUUID(tc.Input) + val, err := util.ParseUUID(tc.Input) assert.Equal(t, tc.OutputVal, val) if tc.OutputErr == "" { assert.NoError(t, err) @@ -39,18 +39,18 @@ func TestParseUUID(t *testing.T) { func TestUUIDFormat(t *testing.T) { t.Parallel() type TestCase struct { - InputUUID internal.UUID + InputUUID util.UUID InputFmt string Output string } - uuid := internal.MustParseUUID("a0dd94ed-e60c-42e8-8632-64e8d4765a43") + uuid := util.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}"}, + "#115v": TestCase{InputUUID: uuid, InputFmt: "|%#115v", Output: "| util.UUID{0xa0, 0xdd, 0x94, 0xed, 0xe6, 0xc, 0x42, 0xe8, 0x86, 0x32, 0x64, 0xe8, 0xd4, 0x76, 0x5a, 0x43}"}, } for tcName, tc := range testcases { tc := tc |