diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2023-03-29 17:11:27 -0600 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2023-03-30 00:11:57 -0600 |
commit | 7f1391d48d63a5f8780dddc41817eaa9df3ce880 (patch) | |
tree | 976590735a86c09059e3eb22cf65e0d851d4ce08 /lib/btrfs/btrfstree/readnode.go | |
parent | 755ac780df4f653879cb376d27cad7ff8e8d7b0f (diff) |
tree-wide: Funnel all btrfstree.ReadNode[btrfsvol.LogicalAddr]() calls through btrfstree.NodeSource.ReadNode()
Diffstat (limited to 'lib/btrfs/btrfstree/readnode.go')
-rw-r--r-- | lib/btrfs/btrfstree/readnode.go | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/lib/btrfs/btrfstree/readnode.go b/lib/btrfs/btrfstree/readnode.go index ac82c62..a4ccf10 100644 --- a/lib/btrfs/btrfstree/readnode.go +++ b/lib/btrfs/btrfstree/readnode.go @@ -14,8 +14,7 @@ import ( ) type NodeFile interface { - diskio.File[btrfsvol.LogicalAddr] - Superblock() (*Superblock, error) + diskio.ReaderAt[btrfsvol.LogicalAddr] // ParentTree, given a tree ID, returns that tree's parent // tree, if it has one. @@ -29,15 +28,14 @@ type NodeFile interface { ParentTree(btrfsprim.ObjID) (btrfsprim.ObjID, btrfsprim.Generation, bool) } -// FSReadNode is a utility function to help with implementing the -// 'NodeSource' interface. -func FSReadNode( - fs NodeFile, - path Path, -) (*Node, error) { - sb, err := fs.Superblock() - if err != nil { - return nil, fmt.Errorf("btrfs.FS.ReadNode: %w", err) +// NodeExpectations returns the address to read and the expectations +// to have when reading the node pointed to by this Path. +// +// `ok` is false if the path is empty or if this Path points to an +// item rather than a node. +func (path Path) NodeExpectations(fs NodeFile) (_ btrfsvol.LogicalAddr, _ NodeExpectations, ok bool) { + if path.Node(-1).ToNodeAddr == 0 && path.Node(-1).ToNodeGeneration == 0 && path.Node(-1).ToNodeLevel == 0 { + return 0, NodeExpectations{}, false } checkOwner := func(owner btrfsprim.ObjID, gen btrfsprim.Generation) error { @@ -70,12 +68,12 @@ func FSReadNode( } } - return ReadNode[btrfsvol.LogicalAddr](fs, *sb, path.Node(-1).ToNodeAddr, NodeExpectations{ + return path.Node(-1).ToNodeAddr, NodeExpectations{ LAddr: containers.OptionalValue(path.Node(-1).ToNodeAddr), Level: containers.OptionalValue(path.Node(-1).ToNodeLevel), Generation: containers.OptionalValue(path.Node(-1).ToNodeGeneration), Owner: checkOwner, MinItem: containers.OptionalValue(path.Node(-1).ToKey), MaxItem: containers.OptionalValue(path.Node(-1).ToMaxKey), - }) + }, true } |