From 2202cfba154b69a947ae45629ef8105de7f63ac4 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Fri, 1 Jul 2022 23:07:21 -0600 Subject: =?UTF-8?q?Rename=20TreeWalkPath=E2=86=92TreePath?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/btrfs/btree.go | 32 ++++++++++++++++---------------- pkg/btrfs/io2_fs.go | 2 +- 2 files changed, 17 insertions(+), 17 deletions(-) (limited to 'pkg/btrfs') diff --git a/pkg/btrfs/btree.go b/pkg/btrfs/btree.go index 72da1b9..0553c46 100644 --- a/pkg/btrfs/btree.go +++ b/pkg/btrfs/btree.go @@ -12,8 +12,8 @@ import ( "lukeshu.com/btrfs-tools/pkg/util" ) -// A TreeWalkPathElem essentially represents a KeyPointer. -type TreeWalkPathElem struct { +// A TreePathElem essentially represents a KeyPointer. +type TreePathElem struct { // ItemIdx is the index of this KeyPointer in the parent Node; // or -1 if this is the root and there is no KeyPointer. ItemIdx int @@ -26,7 +26,7 @@ type TreeWalkPathElem struct { NodeLevel uint8 } -func (elem TreeWalkPathElem) writeNodeTo(w io.Writer) { +func (elem TreePathElem) writeNodeTo(w io.Writer) { if elem.NodeLevel != math.MaxUint8 { fmt.Fprintf(w, "node:%d@%v", elem.NodeLevel, elem.NodeAddr) } else { @@ -38,9 +38,9 @@ func (elem TreeWalkPathElem) writeNodeTo(w io.Writer) { // // - For .Item() callbacks, the last element will always have a // NodeAddr of 0. -type TreeWalkPath []TreeWalkPathElem +type TreePath []TreePathElem -func (path TreeWalkPath) String() string { +func (path TreePath) String() string { if len(path) == 0 { return "(empty-path)" } @@ -58,14 +58,14 @@ func (path TreeWalkPath) String() string { type TreeWalkHandler struct { // Callbacks for entire nodes - PreNode func(TreeWalkPath) error - Node func(TreeWalkPath, *util.Ref[LogicalAddr, Node], error) error - PostNode func(TreeWalkPath, *util.Ref[LogicalAddr, Node]) error + PreNode func(TreePath) error + Node func(TreePath, *util.Ref[LogicalAddr, Node], error) error + PostNode func(TreePath, *util.Ref[LogicalAddr, Node]) error // Callbacks for items on internal nodes - PreKeyPointer func(TreeWalkPath, KeyPointer) error - PostKeyPointer func(TreeWalkPath, KeyPointer) error + PreKeyPointer func(TreePath, KeyPointer) error + PostKeyPointer func(TreePath, KeyPointer) error // Callbacks for items on leaf nodes - Item func(TreeWalkPath, Item) error + Item func(TreePath, Item) error } // The lifecycle of callbacks is: @@ -82,8 +82,8 @@ type TreeWalkHandler struct { // 004 .Item() // 007 .PostNode() func (fs *FS) TreeWalk(treeRoot LogicalAddr, cbs TreeWalkHandler) error { - path := TreeWalkPath{ - TreeWalkPathElem{ + path := TreePath{ + TreePathElem{ ItemIdx: -1, NodeAddr: treeRoot, NodeLevel: math.MaxUint8, @@ -92,7 +92,7 @@ func (fs *FS) TreeWalk(treeRoot LogicalAddr, cbs TreeWalkHandler) error { return fs.treeWalk(path, cbs) } -func (fs *FS) treeWalk(path TreeWalkPath, cbs TreeWalkHandler) error { +func (fs *FS) treeWalk(path TreePath, cbs TreeWalkHandler) error { if path[len(path)-1].NodeAddr == 0 { return nil } @@ -124,7 +124,7 @@ func (fs *FS) treeWalk(path TreeWalkPath, cbs TreeWalkHandler) error { } if node != nil { for i, item := range node.Data.BodyInternal { - itemPath := append(path, TreeWalkPathElem{ + itemPath := append(path, TreePathElem{ ItemIdx: i, NodeAddr: item.BlockPtr, NodeLevel: node.Data.Head.Level - 1, @@ -151,7 +151,7 @@ func (fs *FS) treeWalk(path TreeWalkPath, cbs TreeWalkHandler) error { } for i, item := range node.Data.BodyLeaf { if cbs.Item != nil { - itemPath := append(path, TreeWalkPathElem{ + itemPath := append(path, TreePathElem{ ItemIdx: i, }) if err := cbs.Item(itemPath, item); err != nil { diff --git a/pkg/btrfs/io2_fs.go b/pkg/btrfs/io2_fs.go index d71d4b2..33bfcbf 100644 --- a/pkg/btrfs/io2_fs.go +++ b/pkg/btrfs/io2_fs.go @@ -151,7 +151,7 @@ func (fs *FS) initDev(sb *util.Ref[PhysicalAddr, Superblock]) error { } } if err := fs.TreeWalk(sb.Data.ChunkTree, TreeWalkHandler{ - Item: func(_ TreeWalkPath, item Item) error { + Item: func(_ TreePath, item Item) error { if item.Head.Key.ItemType != btrfsitem.CHUNK_ITEM_KEY { return nil } -- cgit v1.2.3-2-g168b