summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2023-03-10 15:22:07 -0700
committerLuke Shumaker <lukeshu@lukeshu.com>2023-03-17 22:30:37 -0400
commit17e5d1366a77bbe0e8d32b7bf16829a4f855e854 (patch)
tree9d9d106cb997f05d22eb397396b04edd8bbeb58d
parent5ae8f865cdd8607f29fa37267dad2b436e9c9103 (diff)
tree-wide: s/TreePath/Path/g
btrfstree.TreePath stutters.
-rw-r--r--cmd/btrfs-rec/inspect/dumptrees/print_tree.go8
-rw-r--r--cmd/btrfs-rec/inspect_lstrees.go6
-rw-r--r--cmd/btrfs-rec/inspect_spewitems.go4
-rw-r--r--lib/btrfs/btrfstree/btree.go20
-rw-r--r--lib/btrfs/btrfstree/btree_tree.go32
-rw-r--r--lib/btrfs/btrfstree/path.go22
-rw-r--r--lib/btrfs/btrfstree/readnode.go2
-rw-r--r--lib/btrfs/io2_lv.go2
-rw-r--r--lib/btrfs/io3_btree.go4
-rw-r--r--lib/btrfsutil/old_rebuilt_forrest.go10
-rw-r--r--lib/btrfsutil/rebuilt_forrest.go2
-rw-r--r--lib/btrfsutil/walk.go4
12 files changed, 58 insertions, 58 deletions
diff --git a/cmd/btrfs-rec/inspect/dumptrees/print_tree.go b/cmd/btrfs-rec/inspect/dumptrees/print_tree.go
index 9572f3a..60303e9 100644
--- a/cmd/btrfs-rec/inspect/dumptrees/print_tree.go
+++ b/cmd/btrfs-rec/inspect/dumptrees/print_tree.go
@@ -53,7 +53,7 @@ func DumpTrees(ctx context.Context, out io.Writer, fs *btrfs.FS) {
dlog.Error(ctx, err)
},
btrfstree.TreeWalkHandler{
- Item: func(_ btrfstree.TreePath, item btrfstree.Item) error {
+ Item: func(_ btrfstree.Path, item btrfstree.Item) error {
if item.Key.ItemType != btrfsitem.ROOT_ITEM_KEY {
return nil
}
@@ -99,12 +99,12 @@ var nodeHeaderSize = binstruct.StaticSize(btrfstree.NodeHeader{})
func printTree(ctx context.Context, out io.Writer, fs *btrfs.FS, treeID btrfsprim.ObjID) {
var itemOffset uint32
handlers := btrfstree.TreeWalkHandler{
- Node: func(path btrfstree.TreePath, node *btrfstree.Node) error {
+ Node: func(path btrfstree.Path, node *btrfstree.Node) error {
printHeaderInfo(out, node)
itemOffset = node.Size - uint32(nodeHeaderSize)
return nil
},
- PreKeyPointer: func(path btrfstree.TreePath, item btrfstree.KeyPointer) error {
+ PreKeyPointer: func(path btrfstree.Path, item btrfstree.KeyPointer) error {
treeID := path[0].FromTree
textui.Fprintf(out, "\tkey %v block %v gen %v\n",
item.Key.Format(treeID),
@@ -112,7 +112,7 @@ func printTree(ctx context.Context, out io.Writer, fs *btrfs.FS, treeID btrfspri
item.Generation)
return nil
},
- Item: func(path btrfstree.TreePath, item btrfstree.Item) error {
+ Item: func(path btrfstree.Path, item btrfstree.Item) error {
treeID := path[0].FromTree
i := path.Node(-1).FromItemSlot
bs, _ := binstruct.Marshal(item.Body)
diff --git a/cmd/btrfs-rec/inspect_lstrees.go b/cmd/btrfs-rec/inspect_lstrees.go
index 70f4f51..1541012 100644
--- a/cmd/btrfs-rec/inspect_lstrees.go
+++ b/cmd/btrfs-rec/inspect_lstrees.go
@@ -75,16 +75,16 @@ func init() {
treeErrCnt++
},
TreeWalkHandler: btrfstree.TreeWalkHandler{
- Node: func(path btrfstree.TreePath, node *btrfstree.Node) error {
+ Node: func(path btrfstree.Path, node *btrfstree.Node) error {
visitedNodes.Insert(path.Node(-1).ToNodeAddr)
return nil
},
- Item: func(_ btrfstree.TreePath, item btrfstree.Item) error {
+ Item: func(_ btrfstree.Path, item btrfstree.Item) error {
typ := item.Key.ItemType
treeItemCnt[typ]++
return nil
},
- BadItem: func(_ btrfstree.TreePath, item btrfstree.Item) error {
+ BadItem: func(_ btrfstree.Path, item btrfstree.Item) error {
typ := item.Key.ItemType
treeItemCnt[typ]++
return nil
diff --git a/cmd/btrfs-rec/inspect_spewitems.go b/cmd/btrfs-rec/inspect_spewitems.go
index d8a65ae..b83e989 100644
--- a/cmd/btrfs-rec/inspect_spewitems.go
+++ b/cmd/btrfs-rec/inspect_spewitems.go
@@ -34,13 +34,13 @@ func init() {
dlog.Error(ctx, err)
},
TreeWalkHandler: btrfstree.TreeWalkHandler{
- Item: func(path btrfstree.TreePath, item btrfstree.Item) error {
+ Item: func(path btrfstree.Path, item btrfstree.Item) error {
textui.Fprintf(os.Stdout, "%s = ", path)
spew.Dump(item)
_, _ = os.Stdout.WriteString("\n")
return nil
},
- BadItem: func(path btrfstree.TreePath, item btrfstree.Item) error {
+ BadItem: func(path btrfstree.Path, item btrfstree.Item) error {
textui.Fprintf(os.Stdout, "%s = ", path)
spew.Dump(item)
_, _ = os.Stdout.WriteString("\n")
diff --git a/lib/btrfs/btrfstree/btree.go b/lib/btrfs/btrfstree/btree.go
index c71aad5..e91fcc1 100644
--- a/lib/btrfs/btrfstree/btree.go
+++ b/lib/btrfs/btrfstree/btree.go
@@ -69,20 +69,20 @@ type TreeWalkHandler struct {
// node immediately stops getting processed; if PreNode, Node,
// or BadNode return io/fs.SkipDir then key pointers and items
// within the node are not processed.
- PreNode func(TreePath) error
- Node func(TreePath, *Node) error
- BadNode func(TreePath, *Node, error) error
- PostNode func(TreePath, *Node) error
+ PreNode func(Path) error
+ Node func(Path, *Node) error
+ BadNode func(Path, *Node, error) error
+ PostNode func(Path, *Node) error
// Callbacks for items on interior nodes
- PreKeyPointer func(TreePath, KeyPointer) error
- PostKeyPointer func(TreePath, KeyPointer) error
+ PreKeyPointer func(Path, KeyPointer) error
+ PostKeyPointer func(Path, KeyPointer) error
// Callbacks for items on leaf nodes
- Item func(TreePath, Item) error
- BadItem func(TreePath, Item) error
+ Item func(Path, Item) error
+ BadItem func(Path, Item) error
}
type TreeError struct {
- Path TreePath
+ Path Path
Err error
}
@@ -94,5 +94,5 @@ func (e *TreeError) Error() string {
type NodeSource interface {
Superblock() (*Superblock, error)
- ReadNode(TreePath) (*Node, error)
+ ReadNode(Path) (*Node, error)
}
diff --git a/lib/btrfs/btrfstree/btree_tree.go b/lib/btrfs/btrfstree/btree_tree.go
index 7561314..459f481 100644
--- a/lib/btrfs/btrfstree/btree_tree.go
+++ b/lib/btrfs/btrfstree/btree_tree.go
@@ -26,11 +26,11 @@ type TreeOperatorImpl struct {
func (fs TreeOperatorImpl) TreeWalk(ctx context.Context, treeID btrfsprim.ObjID, errHandle func(*TreeError), cbs TreeWalkHandler) {
sb, err := fs.Superblock()
if err != nil {
- errHandle(&TreeError{Path: TreePath{{FromTree: treeID, ToMaxKey: btrfsprim.MaxKey}}, Err: err})
+ errHandle(&TreeError{Path: Path{{FromTree: treeID, ToMaxKey: btrfsprim.MaxKey}}, Err: err})
}
rootInfo, err := LookupTreeRoot(fs, *sb, treeID)
if err != nil {
- errHandle(&TreeError{Path: TreePath{{FromTree: treeID, ToMaxKey: btrfsprim.MaxKey}}, Err: err})
+ errHandle(&TreeError{Path: Path{{FromTree: treeID, ToMaxKey: btrfsprim.MaxKey}}, Err: err})
return
}
fs.RawTreeWalk(ctx, *rootInfo, errHandle, cbs)
@@ -39,7 +39,7 @@ func (fs TreeOperatorImpl) TreeWalk(ctx context.Context, treeID btrfsprim.ObjID,
// RawTreeWalk is a utility method to help with implementing the
// 'TreeOperator' interface.
func (fs TreeOperatorImpl) RawTreeWalk(ctx context.Context, rootInfo TreeRoot, errHandle func(*TreeError), cbs TreeWalkHandler) {
- path := TreePath{{
+ path := Path{{
FromTree: rootInfo.TreeID,
FromItemSlot: -1,
ToNodeAddr: rootInfo.RootNode,
@@ -50,7 +50,7 @@ func (fs TreeOperatorImpl) RawTreeWalk(ctx context.Context, rootInfo TreeRoot, e
fs.treeWalk(ctx, path, errHandle, cbs)
}
-func (fs TreeOperatorImpl) treeWalk(ctx context.Context, path TreePath, errHandle func(*TreeError), cbs TreeWalkHandler) {
+func (fs TreeOperatorImpl) treeWalk(ctx context.Context, path Path, errHandle func(*TreeError), cbs TreeWalkHandler) {
if ctx.Err() != nil {
return
}
@@ -100,7 +100,7 @@ func (fs TreeOperatorImpl) treeWalk(ctx context.Context, path TreePath, errHandl
if i+1 < len(node.BodyInterior) {
toMaxKey = node.BodyInterior[i+1].Key.Mm()
}
- itemPath := append(path, TreePathElem{
+ itemPath := append(path, PathElem{
FromTree: node.Head.Owner,
FromItemSlot: i,
ToNodeAddr: item.BlockPtr,
@@ -128,7 +128,7 @@ func (fs TreeOperatorImpl) treeWalk(ctx context.Context, path TreePath, errHandl
}
}
for i, item := range node.BodyLeaf {
- itemPath := append(path, TreePathElem{
+ itemPath := append(path, PathElem{
FromTree: node.Head.Owner,
FromItemSlot: i,
ToKey: item.Key,
@@ -167,8 +167,8 @@ func (fs TreeOperatorImpl) treeWalk(ctx context.Context, path TreePath, errHandl
}
}
-func (fs TreeOperatorImpl) treeSearch(treeRoot TreeRoot, fn func(btrfsprim.Key, uint32) int) (TreePath, *Node, error) {
- path := TreePath{{
+func (fs TreeOperatorImpl) treeSearch(treeRoot TreeRoot, fn func(btrfsprim.Key, uint32) int) (Path, *Node, error) {
+ path := Path{{
FromTree: treeRoot.TreeID,
FromItemSlot: -1,
ToNodeAddr: treeRoot.RootNode,
@@ -209,7 +209,7 @@ func (fs TreeOperatorImpl) treeSearch(treeRoot TreeRoot, fn func(btrfsprim.Key,
if lastGood+1 < len(node.BodyInterior) {
toMaxKey = node.BodyInterior[lastGood+1].Key.Mm()
}
- path = append(path, TreePathElem{
+ path = append(path, PathElem{
FromTree: node.Head.Owner,
FromItemSlot: lastGood,
ToNodeAddr: node.BodyInterior[lastGood].BlockPtr,
@@ -239,7 +239,7 @@ func (fs TreeOperatorImpl) treeSearch(treeRoot TreeRoot, fn func(btrfsprim.Key,
node.Free()
return nil, nil, ErrNoItem
}
- path = append(path, TreePathElem{
+ path = append(path, PathElem{
FromTree: node.Head.Owner,
FromItemSlot: slot,
ToKey: node.BodyLeaf[slot].Key,
@@ -250,7 +250,7 @@ func (fs TreeOperatorImpl) treeSearch(treeRoot TreeRoot, fn func(btrfsprim.Key,
}
}
-func (fs TreeOperatorImpl) prev(path TreePath, node *Node) (TreePath, *Node, error) {
+func (fs TreeOperatorImpl) prev(path Path, node *Node) (Path, *Node, error) {
var err error
path = path.DeepCopy()
@@ -285,7 +285,7 @@ func (fs TreeOperatorImpl) prev(path TreePath, node *Node) (TreePath, *Node, err
}
}
if node.Head.Level > 0 {
- path = append(path, TreePathElem{
+ path = append(path, PathElem{
FromTree: node.Head.Owner,
FromItemSlot: len(node.BodyInterior) - 1,
ToNodeAddr: node.BodyInterior[len(node.BodyInterior)-1].BlockPtr,
@@ -295,7 +295,7 @@ func (fs TreeOperatorImpl) prev(path TreePath, node *Node) (TreePath, *Node, err
ToMaxKey: path.Node(-1).ToMaxKey,
})
} else {
- path = append(path, TreePathElem{
+ path = append(path, PathElem{
FromTree: node.Head.Owner,
FromItemSlot: len(node.BodyLeaf) - 1,
ToKey: node.BodyLeaf[len(node.BodyLeaf)-1].Key,
@@ -315,7 +315,7 @@ func (fs TreeOperatorImpl) prev(path TreePath, node *Node) (TreePath, *Node, err
return path, node, nil
}
-func (fs TreeOperatorImpl) next(path TreePath, node *Node) (TreePath, *Node, error) {
+func (fs TreeOperatorImpl) next(path Path, node *Node) (Path, *Node, error) {
var err error
path = path.DeepCopy()
@@ -373,7 +373,7 @@ func (fs TreeOperatorImpl) next(path TreePath, node *Node) (TreePath, *Node, err
if len(node.BodyInterior) > 1 {
toMaxKey = node.BodyInterior[1].Key.Mm()
}
- path = append(path, TreePathElem{
+ path = append(path, PathElem{
FromTree: node.Head.Owner,
FromItemSlot: 0,
ToNodeAddr: node.BodyInterior[0].BlockPtr,
@@ -383,7 +383,7 @@ func (fs TreeOperatorImpl) next(path TreePath, node *Node) (TreePath, *Node, err
ToMaxKey: toMaxKey,
})
} else {
- path = append(path, TreePathElem{
+ path = append(path, PathElem{
FromTree: node.Head.Owner,
FromItemSlot: 0,
ToKey: node.BodyInterior[0].Key,
diff --git a/lib/btrfs/btrfstree/path.go b/lib/btrfs/btrfstree/path.go
index b9ab5bc..c07d8a0 100644
--- a/lib/btrfs/btrfstree/path.go
+++ b/lib/btrfs/btrfstree/path.go
@@ -13,7 +13,7 @@ import (
"git.lukeshu.com/btrfs-progs-ng/lib/btrfs/btrfsvol"
)
-// TreePath is a path from the superblock (i.e. the root of the btrfs
+// Path is a path from the superblock (i.e. the root of the btrfs
// system) to the a node or item within one of the btrees in the
// system.
//
@@ -61,10 +61,10 @@ import (
// | <--------------- pathElem={from_tree:A, from_slot:1,
// | to_addr:0, to_gen: 0, to_lvl:0}
// [item]
-type TreePath []TreePathElem
+type Path []PathElem
-// A TreePathElem essentially represents a KeyPointer.
-type TreePathElem struct {
+// A PathElem essentially represents a KeyPointer.
+type PathElem struct {
// FromTree is the owning tree ID of the parent node; or the
// well-known tree ID if this is the root.
FromTree btrfsprim.ObjID
@@ -94,17 +94,17 @@ type TreePathElem struct {
ToMaxKey btrfsprim.Key
}
-func (elem TreePathElem) writeNodeTo(w io.Writer) {
+func (elem PathElem) writeNodeTo(w io.Writer) {
fmt.Fprintf(w, "node:%d@%v", elem.ToNodeLevel, elem.ToNodeAddr)
}
-func (path TreePath) String() string {
+func (path Path) String() string {
if len(path) == 0 {
return "(empty-path)"
}
var ret strings.Builder
fmt.Fprintf(&ret, "%s->", path[0].FromTree.Format(btrfsprim.ROOT_TREE_OBJECTID))
- if len(path) == 1 && path[0] == (TreePathElem{FromTree: path[0].FromTree, FromItemSlot: -1}) {
+ if len(path) == 1 && path[0] == (PathElem{FromTree: path[0].FromTree, FromItemSlot: -1}) {
ret.WriteString("(empty-path)")
} else {
path[0].writeNodeTo(&ret)
@@ -119,11 +119,11 @@ func (path TreePath) String() string {
return ret.String()
}
-func (path TreePath) DeepCopy() TreePath {
- return append(TreePath(nil), path...)
+func (path Path) DeepCopy() Path {
+ return append(Path(nil), path...)
}
-func (path TreePath) Parent() TreePath {
+func (path Path) Parent() Path {
return path[:len(path)-1]
}
@@ -131,7 +131,7 @@ func (path TreePath) Parent() TreePath {
// `&path[x]`, but negative values of x move down from the end of path
// (similar to how lists work in many other languages, such as
// Python).
-func (path TreePath) Node(x int) *TreePathElem {
+func (path Path) Node(x int) *PathElem {
if x < 0 {
x += len(path)
}
diff --git a/lib/btrfs/btrfstree/readnode.go b/lib/btrfs/btrfstree/readnode.go
index 1c242ac..c5d9145 100644
--- a/lib/btrfs/btrfstree/readnode.go
+++ b/lib/btrfs/btrfstree/readnode.go
@@ -33,7 +33,7 @@ type NodeFile interface {
// 'NodeSource' interface.
func FSReadNode(
fs NodeFile,
- path TreePath,
+ path Path,
) (*Node, error) {
sb, err := fs.Superblock()
if err != nil {
diff --git a/lib/btrfs/io2_lv.go b/lib/btrfs/io2_lv.go
index 856ac20..d05d51f 100644
--- a/lib/btrfs/io2_lv.go
+++ b/lib/btrfs/io2_lv.go
@@ -168,7 +168,7 @@ func (fs *FS) initDev(ctx context.Context, sb btrfstree.Superblock) error {
errs = append(errs, err)
},
btrfstree.TreeWalkHandler{
- Item: func(_ btrfstree.TreePath, item btrfstree.Item) error {
+ Item: func(_ btrfstree.Path, item btrfstree.Item) error {
if item.Key.ItemType != btrfsitem.CHUNK_ITEM_KEY {
return nil
}
diff --git a/lib/btrfs/io3_btree.go b/lib/btrfs/io3_btree.go
index 467bbde..80ab10f 100644
--- a/lib/btrfs/io3_btree.go
+++ b/lib/btrfs/io3_btree.go
@@ -17,7 +17,7 @@ import (
// btrfstree.NodeSource ////////////////////////////////////////////////////////
// ReadNode implements btrfstree.NodeSource.
-func (fs *FS) ReadNode(path btrfstree.TreePath) (*btrfstree.Node, error) {
+func (fs *FS) ReadNode(path btrfstree.Path) (*btrfstree.Node, error) {
return btrfstree.FSReadNode(fs, path)
}
@@ -37,7 +37,7 @@ func (fs *FS) populateTreeUUIDs(ctx context.Context) {
// do nothing
},
btrfstree.TreeWalkHandler{
- Item: func(_ btrfstree.TreePath, item btrfstree.Item) error {
+ Item: func(_ btrfstree.Path, item btrfstree.Item) error {
itemBody, ok := item.Body.(*btrfsitem.Root)
if !ok {
return nil
diff --git a/lib/btrfsutil/old_rebuilt_forrest.go b/lib/btrfsutil/old_rebuilt_forrest.go
index 8bc02df..5f6c718 100644
--- a/lib/btrfsutil/old_rebuilt_forrest.go
+++ b/lib/btrfsutil/old_rebuilt_forrest.go
@@ -178,7 +178,7 @@ func (bt *OldRebuiltForrest) rawTreeWalk(root btrfstree.TreeRoot, cacheEntry old
var curNode nodeInfo
cbs := btrfstree.TreeWalkHandler{
- BadNode: func(path btrfstree.TreePath, node *btrfstree.Node, err error) error {
+ BadNode: func(path btrfstree.Path, node *btrfstree.Node, err error) error {
if node != nil {
curNode = nodeInfo{
LAddr: path.Node(-1).ToNodeAddr,
@@ -191,7 +191,7 @@ func (bt *OldRebuiltForrest) rawTreeWalk(root btrfstree.TreeRoot, cacheEntry old
}
return err
},
- Node: func(path btrfstree.TreePath, node *btrfstree.Node) error {
+ Node: func(path btrfstree.Path, node *btrfstree.Node) error {
curNode = nodeInfo{
LAddr: path.Node(-1).ToNodeAddr,
Level: node.Head.Level,
@@ -202,7 +202,7 @@ func (bt *OldRebuiltForrest) rawTreeWalk(root btrfstree.TreeRoot, cacheEntry old
}
return nil
},
- Item: func(path btrfstree.TreePath, item btrfstree.Item) error {
+ Item: func(path btrfstree.Path, item btrfstree.Item) error {
if cacheEntry.Items.Search(func(v oldRebuiltTreeValue) int { return item.Key.Compare(v.Key) }) != nil {
// This is a panic because I'm not really sure what the best way to
// handle this is, and so if this happens I want the program to crash
@@ -340,7 +340,7 @@ func (bt *OldRebuiltForrest) TreeWalk(ctx context.Context, treeID btrfsprim.ObjI
tree := bt.RebuiltTree(treeID)
if tree.RootErr != nil {
errHandle(&btrfstree.TreeError{
- Path: btrfstree.TreePath{{
+ Path: btrfstree.Path{{
FromTree: treeID,
ToMaxKey: btrfsprim.MaxKey,
}},
@@ -365,7 +365,7 @@ func (bt *OldRebuiltForrest) TreeWalk(ctx context.Context, treeID btrfsprim.ObjI
}
item := node.BodyLeaf[indexItem.Value.Slot]
- itemPath := btrfstree.TreePath{
+ itemPath := btrfstree.Path{
{
FromTree: treeID,
ToNodeAddr: indexItem.Value.Node.LAddr,
diff --git a/lib/btrfsutil/rebuilt_forrest.go b/lib/btrfsutil/rebuilt_forrest.go
index 70ece13..0e8f5ad 100644
--- a/lib/btrfsutil/rebuilt_forrest.go
+++ b/lib/btrfsutil/rebuilt_forrest.go
@@ -40,7 +40,7 @@ type RebuiltForrestCallbacks interface {
// - it consumes an already-read Graph instead of reading the graph
// itself
//
-// - it does not use `btrfstree.TreePath`
+// - it does not use `btrfstree.Path`
//
// - it does not keep track of errors encountered in a tree
//
diff --git a/lib/btrfsutil/walk.go b/lib/btrfsutil/walk.go
index 355976a..bbdf992 100644
--- a/lib/btrfsutil/walk.go
+++ b/lib/btrfsutil/walk.go
@@ -1,4 +1,4 @@
-// Copyright (C) 2022 Luke Shumaker <lukeshu@lukeshu.com>
+// Copyright (C) 2022-2023 Luke Shumaker <lukeshu@lukeshu.com>
//
// SPDX-License-Identifier: GPL-2.0-or-later
@@ -61,7 +61,7 @@ func WalkAllTrees(ctx context.Context, fs btrfstree.TreeOperator, cbs WalkAllTre
},
}
origItem := cbs.Item
- cbs.Item = func(path btrfstree.TreePath, item btrfstree.Item) error {
+ cbs.Item = func(path btrfstree.Path, item btrfstree.Item) error {
if item.Key.ItemType == btrfsitem.ROOT_ITEM_KEY {
trees = append(trees, struct {
Name string