diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2023-03-18 00:49:01 -0400 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2023-03-30 10:06:52 -0600 |
commit | 933220af61abd26cb660febac15ed214479e2ba7 (patch) | |
tree | a50e5a1a8846f6fd446fa1078cf2a153ae726862 /lib | |
parent | 72b20c1d798551bfa2bb46f5521553144b45c09f (diff) |
btrfsutil: OldRebuiltForrest: Implement the new btrfstree.Forrest
Diffstat (limited to 'lib')
-rw-r--r-- | lib/btrfsutil/old_rebuilt_forrest.go | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/lib/btrfsutil/old_rebuilt_forrest.go b/lib/btrfsutil/old_rebuilt_forrest.go index e853be7..a462a60 100644 --- a/lib/btrfsutil/old_rebuilt_forrest.go +++ b/lib/btrfsutil/old_rebuilt_forrest.go @@ -96,7 +96,10 @@ type OldRebuiltForrest struct { trees map[btrfsprim.ObjID]oldRebuiltTree } -var _ btrfstree.TreeOperator = (*OldRebuiltForrest)(nil) +var ( + _ btrfstree.TreeOperator = (*OldRebuiltForrest)(nil) + _ btrfs.ReadableFS = (*OldRebuiltForrest)(nil) +) // NewOldRebuiltForrest wraps a *btrfs.FS to support looking up // information from broken trees. @@ -123,8 +126,18 @@ func NewOldRebuiltForrest(ctx context.Context, inner *btrfs.FS) *OldRebuiltForre } } -// RebuiltTree returns a handle for an individual tree. An error is -// indicated by the ret.RootErr member. +// ForrestLookup implements btrfstree.Forrest. +func (bt *OldRebuiltForrest) ForrestLookup(ctx context.Context, treeID btrfsprim.ObjID) (btrfstree.Tree, error) { + tree := bt.RebuiltTree(ctx, treeID) + if tree.RootErr != nil { + return nil, tree.RootErr + } + return tree, nil +} + +// RebuiltTree is a variant of ForrestLookup that returns a concrete +// type instead of an interface. An error is indicated by the +// ret.RootErr member. func (bt *OldRebuiltForrest) RebuiltTree(ctx context.Context, treeID btrfsprim.ObjID) oldRebuiltTree { if treeID == btrfsprim.ROOT_TREE_OBJECTID { bt.rootTreeMu.Lock() @@ -439,6 +452,11 @@ func (bt *OldRebuiltForrest) ReadAt(p []byte, off btrfsvol.LogicalAddr) (int, er return bt.inner.ReadAt(p, off) } +// Name implements btrfs.ReadableFS. +func (bt *OldRebuiltForrest) Name() string { + return bt.inner.Name() +} + // TreeCheckOwner implements btrfstree.Tree. func (tree oldRebuiltTree) TreeCheckOwner(ctx context.Context, failOpen bool, owner btrfsprim.ObjID, gen btrfsprim.Generation) error { var uuidTree oldRebuiltTree |