diff options
Diffstat (limited to 'lib/btrfs')
-rw-r--r-- | lib/btrfs/btrfsitem/items.go | 1 | ||||
-rw-r--r-- | lib/btrfs/btrfssum/csum_test.go | 1 | ||||
-rw-r--r-- | lib/btrfs/btrfstree/ops.go | 2 | ||||
-rw-r--r-- | lib/btrfs/btrfstree/types_node.go | 14 | ||||
-rw-r--r-- | lib/btrfs/btrfsvol/lvm.go | 3 | ||||
-rw-r--r-- | lib/btrfs/io2_lv.go | 1 | ||||
-rw-r--r-- | lib/btrfs/io3_btree.go | 3 | ||||
-rw-r--r-- | lib/btrfs/io4_fs.go | 1 |
8 files changed, 18 insertions, 8 deletions
diff --git a/lib/btrfs/btrfsitem/items.go b/lib/btrfs/btrfsitem/items.go index d300179..67f96fa 100644 --- a/lib/btrfs/btrfsitem/items.go +++ b/lib/btrfs/btrfsitem/items.go @@ -70,7 +70,6 @@ func UnmarshalItem(key btrfsprim.Key, csumType btrfssum.CSumType, dat []byte) It Dat: dat, Err: fmt.Errorf("btrfsitem.UnmarshalItem({ItemType:%v}, dat): %w", key.ItemType, err), } - } if n < len(dat) { return Error{ diff --git a/lib/btrfs/btrfssum/csum_test.go b/lib/btrfs/btrfssum/csum_test.go index 5c17779..0a4aef6 100644 --- a/lib/btrfs/btrfssum/csum_test.go +++ b/lib/btrfs/btrfssum/csum_test.go @@ -22,7 +22,6 @@ func TestCSumFormat(t *testing.T) { } csum := btrfssum.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": {InputSum: csum, InputFmt: "%s", Output: "bd7b41f400000000000000000000000000000000000000000000000000000000"}, "x": {InputSum: csum, InputFmt: "%x", Output: "bd7b41f400000000000000000000000000000000000000000000000000000000"}, "v": {InputSum: csum, InputFmt: "%v", Output: "bd7b41f400000000000000000000000000000000000000000000000000000000"}, diff --git a/lib/btrfs/btrfstree/ops.go b/lib/btrfs/btrfstree/ops.go index ddab630..537773a 100644 --- a/lib/btrfs/btrfstree/ops.go +++ b/lib/btrfs/btrfstree/ops.go @@ -504,7 +504,7 @@ func (fs TreeOperatorImpl) TreeSearchAll(treeID btrfsprim.ObjID, fn func(btrfspr } middleItem := middleNode.Data.BodyLeaf[middlePath.Node(-1).FromItemIdx] - var ret = []Item{middleItem} + ret := []Item{middleItem} var errs derror.MultiError for prevPath, prevNode := middlePath, middleNode; true; { prevPath, prevNode, err = fs.prev(prevPath, prevNode) diff --git a/lib/btrfs/btrfstree/types_node.go b/lib/btrfs/btrfstree/types_node.go index d2e91de..b709d34 100644 --- a/lib/btrfs/btrfstree/types_node.go +++ b/lib/btrfs/btrfstree/types_node.go @@ -26,11 +26,13 @@ type NodeFlags uint64 func (NodeFlags) BinaryStaticSize() int { return 7 } + func (f NodeFlags) MarshalBinary() ([]byte, error) { var bs [8]byte binary.LittleEndian.PutUint64(bs[:], uint64(f)) return bs[:7], nil } + func (f *NodeFlags) UnmarshalBinary(dat []byte) (int, error) { var bs [8]byte copy(bs[:7], dat[:7]) @@ -418,9 +420,11 @@ func (e *IOError) Unwrap() error { return e.Err } // NodeError are ErrNotANode and *IOError. func ReadNode[Addr ~int64](fs diskio.File[Addr], sb Superblock, addr Addr, exp NodeExpectations) (*diskio.Ref[Addr, Node], error) { if int(sb.NodeSize) < binstruct.StaticSize(NodeHeader{}) { - return nil, &NodeError[Addr]{Op: "btrfstree.ReadNode", NodeAddr: addr, + return nil, &NodeError[Addr]{ + Op: "btrfstree.ReadNode", NodeAddr: addr, Err: fmt.Errorf("superblock.NodeSize=%v is too small to contain even a node header (%v bytes)", - sb.NodeSize, binstruct.StaticSize(NodeHeader{}))} + sb.NodeSize, binstruct.StaticSize(NodeHeader{})), + } } nodeBuf := make([]byte, sb.NodeSize) if _, err := fs.ReadAt(nodeBuf, addr); err != nil { @@ -456,9 +460,11 @@ func ReadNode[Addr ~int64](fs diskio.File[Addr], sb Superblock, addr Addr, exp N return nodeRef, &NodeError[Addr]{Op: "btrfstree.ReadNode", NodeAddr: addr, Err: err} } if stored != calced { - return nodeRef, &NodeError[Addr]{Op: "btrfstree.ReadNode", NodeAddr: addr, + return nodeRef, &NodeError[Addr]{ + Op: "btrfstree.ReadNode", NodeAddr: addr, Err: fmt.Errorf("looks like a node but is corrupt: checksum mismatch: stored=%v calculated=%v", - stored, calced)} + stored, calced), + } } // parse (main) diff --git a/lib/btrfs/btrfsvol/lvm.go b/lib/btrfs/btrfsvol/lvm.go index 605524b..1cb1ded 100644 --- a/lib/btrfs/btrfsvol/lvm.go +++ b/lib/btrfs/btrfsvol/lvm.go @@ -82,6 +82,7 @@ func (lv *LogicalVolume[PhysicalVolume]) Close() error { } return nil } + func (lv *LogicalVolume[PhysicalVolume]) AddPhysicalVolume(id DeviceID, dev PhysicalVolume) error { lv.init() if other, exists := lv.id2pv[id]; exists { @@ -121,9 +122,11 @@ type Mapping struct { func (lv *LogicalVolume[PhysicalVolume]) CouldAddMapping(m Mapping) bool { return lv.addMapping(m, true) == nil } + func (lv *LogicalVolume[PhysicalVolume]) AddMapping(m Mapping) error { return lv.addMapping(m, false) } + func (lv *LogicalVolume[PhysicalVolume]) addMapping(m Mapping, dryRun bool) error { lv.init() // sanity check diff --git a/lib/btrfs/io2_lv.go b/lib/btrfs/io2_lv.go index 3f82cd0..ac7ea70 100644 --- a/lib/btrfs/io2_lv.go +++ b/lib/btrfs/io2_lv.go @@ -70,6 +70,7 @@ func (fs *FS) Size() btrfsvol.LogicalAddr { func (fs *FS) ReadAt(p []byte, off btrfsvol.LogicalAddr) (int, error) { return fs.LV.ReadAt(p, off) } + func (fs *FS) WriteAt(p []byte, off btrfsvol.LogicalAddr) (int, error) { return fs.LV.WriteAt(p, off) } diff --git a/lib/btrfs/io3_btree.go b/lib/btrfs/io3_btree.go index b8c1a6d..8ec4b41 100644 --- a/lib/btrfs/io3_btree.go +++ b/lib/btrfs/io3_btree.go @@ -17,12 +17,15 @@ import ( func (fs *FS) TreeWalk(ctx context.Context, treeID btrfsprim.ObjID, errHandle func(*btrfstree.TreeError), cbs btrfstree.TreeWalkHandler) { btrfstree.TreeOperatorImpl{NodeSource: fs}.TreeWalk(ctx, treeID, errHandle, cbs) } + func (fs *FS) TreeLookup(treeID btrfsprim.ObjID, key btrfsprim.Key) (btrfstree.Item, error) { return btrfstree.TreeOperatorImpl{NodeSource: fs}.TreeLookup(treeID, key) } + func (fs *FS) TreeSearch(treeID btrfsprim.ObjID, fn func(key btrfsprim.Key, size uint32) int) (btrfstree.Item, error) { return btrfstree.TreeOperatorImpl{NodeSource: fs}.TreeSearch(treeID, fn) } + func (fs *FS) TreeSearchAll(treeID btrfsprim.ObjID, fn func(key btrfsprim.Key, size uint32) int) ([]btrfstree.Item, error) { return btrfstree.TreeOperatorImpl{NodeSource: fs}.TreeSearchAll(treeID, fn) } diff --git a/lib/btrfs/io4_fs.go b/lib/btrfs/io4_fs.go index d9c7cdb..3848ef1 100644 --- a/lib/btrfs/io4_fs.go +++ b/lib/btrfs/io4_fs.go @@ -95,7 +95,6 @@ func (sv *Subvolume) init() { default: panic(fmt.Errorf("should not happen: ROOT_ITEM has unexpected item type: %T", rootBody)) } - }) } |