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 --- cmd/btrfs-dump-tree/main.go | 2 +- cmd/btrfs-fsck/pass1.go | 2 +- cmd/btrfs-fsck/pass2.go | 4 ++-- cmd/btrfs-ls-trees/main.go | 2 +- pkg/btrfs/btree.go | 32 ++++++++++++++++---------------- pkg/btrfs/io2_fs.go | 2 +- pkg/btrfsmisc/print_tree.go | 6 +++--- pkg/btrfsmisc/walk.go | 8 ++++---- 8 files changed, 29 insertions(+), 29 deletions(-) diff --git a/cmd/btrfs-dump-tree/main.go b/cmd/btrfs-dump-tree/main.go index c7e4beb..7f1aba4 100644 --- a/cmd/btrfs-dump-tree/main.go +++ b/cmd/btrfs-dump-tree/main.go @@ -64,7 +64,7 @@ func Main(imgfilename string) (err error) { } } if err := fs.TreeWalk(superblock.Data.RootTree, btrfs.TreeWalkHandler{ - Item: func(_ btrfs.TreeWalkPath, item btrfs.Item) error { + Item: func(_ btrfs.TreePath, item btrfs.Item) error { if item.Head.Key.ItemType != btrfsitem.ROOT_ITEM_KEY { return nil } diff --git a/cmd/btrfs-fsck/pass1.go b/cmd/btrfs-fsck/pass1.go index 36bc1ae..e75e4fe 100644 --- a/cmd/btrfs-fsck/pass1.go +++ b/cmd/btrfs-fsck/pass1.go @@ -24,7 +24,7 @@ func pass1(fs *btrfs.FS, superblock *util.Ref[btrfs.PhysicalAddr, btrfs.Superblo visitedNodes := make(map[btrfs.LogicalAddr]struct{}) btrfsmisc.WalkFS(fs, btrfsmisc.WalkFSHandler{ TreeWalkHandler: btrfs.TreeWalkHandler{ - Node: func(path btrfs.TreeWalkPath, node *util.Ref[btrfs.LogicalAddr, btrfs.Node], err error) error { + Node: func(path btrfs.TreePath, node *util.Ref[btrfs.LogicalAddr, btrfs.Node], err error) error { if err != nil { err = fmt.Errorf("%v: %w", path, err) fmt.Printf("Pass 1: ... walk fs: error: %v\n", err) diff --git a/cmd/btrfs-fsck/pass2.go b/cmd/btrfs-fsck/pass2.go index bcc57a5..989b79f 100644 --- a/cmd/btrfs-fsck/pass2.go +++ b/cmd/btrfs-fsck/pass2.go @@ -15,7 +15,7 @@ func pass2(fs *btrfs.FS, foundNodes map[btrfs.LogicalAddr]struct{}) { visitedNodes := make(map[btrfs.LogicalAddr]struct{}) btrfsmisc.WalkFS(fs, btrfsmisc.WalkFSHandler{ TreeWalkHandler: btrfs.TreeWalkHandler{ - Node: func(path btrfs.TreeWalkPath, node *util.Ref[btrfs.LogicalAddr, btrfs.Node], err error) error { + Node: func(path btrfs.TreePath, node *util.Ref[btrfs.LogicalAddr, btrfs.Node], err error) error { visitedNodes[node.Addr] = struct{}{} return nil }, @@ -38,7 +38,7 @@ func pass2(fs *btrfs.FS, foundNodes map[btrfs.LogicalAddr]struct{}) { } for potentialRoot := range orphanedRoots { if err := fs.TreeWalk(potentialRoot, btrfs.TreeWalkHandler{ - Node: func(path btrfs.TreeWalkPath, _ *util.Ref[btrfs.LogicalAddr, btrfs.Node], _ error) error { + Node: func(path btrfs.TreePath, _ *util.Ref[btrfs.LogicalAddr, btrfs.Node], _ error) error { nodeAddr := path[len(path)-1].NodeAddr if nodeAddr != potentialRoot { delete(orphanedRoots, nodeAddr) diff --git a/cmd/btrfs-ls-trees/main.go b/cmd/btrfs-ls-trees/main.go index 96638ed..395ef07 100644 --- a/cmd/btrfs-ls-trees/main.go +++ b/cmd/btrfs-ls-trees/main.go @@ -46,7 +46,7 @@ func Main(imgfilenames ...string) (err error) { treeErrCnt++ }, TreeWalkHandler: btrfs.TreeWalkHandler{ - Item: func(_ btrfs.TreeWalkPath, item btrfs.Item) error { + Item: func(_ btrfs.TreePath, item btrfs.Item) error { typ := item.Head.Key.ItemType treeItemCnt[typ] = treeItemCnt[typ] + 1 return nil 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 } diff --git a/pkg/btrfsmisc/print_tree.go b/pkg/btrfsmisc/print_tree.go index 3f1dd46..80d279c 100644 --- a/pkg/btrfsmisc/print_tree.go +++ b/pkg/btrfsmisc/print_tree.go @@ -15,7 +15,7 @@ import ( // kernel-shared/print-tree.c:btrfs_print_leaf() func PrintTree(fs *btrfs.FS, root btrfs.LogicalAddr) error { return fs.TreeWalk(root, btrfs.TreeWalkHandler{ - Node: func(path btrfs.TreeWalkPath, nodeRef *util.Ref[btrfs.LogicalAddr, btrfs.Node], err error) error { + Node: func(path btrfs.TreePath, nodeRef *util.Ref[btrfs.LogicalAddr, btrfs.Node], err error) error { if err != nil { fmt.Fprintf(os.Stderr, "error: %v: %v\n", path, err) } @@ -24,14 +24,14 @@ func PrintTree(fs *btrfs.FS, root btrfs.LogicalAddr) error { } return nil }, - PreKeyPointer: func(_ btrfs.TreeWalkPath, item btrfs.KeyPointer) error { + PreKeyPointer: func(_ btrfs.TreePath, item btrfs.KeyPointer) error { fmt.Printf("\t%v block %v gen %v\n", FmtKey(item.Key), item.BlockPtr, item.Generation) return nil }, - Item: func(path btrfs.TreeWalkPath, item btrfs.Item) error { + Item: func(path btrfs.TreePath, item btrfs.Item) error { i := path[len(path)-1].ItemIdx fmt.Printf("\titem %v %v itemoff %v itemsize %v\n", i, diff --git a/pkg/btrfsmisc/walk.go b/pkg/btrfsmisc/walk.go index 545afb9..8017b69 100644 --- a/pkg/btrfsmisc/walk.go +++ b/pkg/btrfsmisc/walk.go @@ -10,7 +10,7 @@ import ( type WalkErr struct { TreeName string - Path btrfs.TreeWalkPath + Path btrfs.TreePath Err error } @@ -37,7 +37,7 @@ type WalkFSHandler struct { // will always be of type WalkErr. func WalkFS(fs *btrfs.FS, cbs WalkFSHandler) { var treeName string - handleErr := func(path btrfs.TreeWalkPath, err error) { + handleErr := func(path btrfs.TreePath, err error) { cbs.Err(WalkErr{ TreeName: treeName, Path: path, @@ -50,7 +50,7 @@ func WalkFS(fs *btrfs.FS, cbs WalkFSHandler) { Root btrfs.LogicalAddr } origItem := cbs.Item - cbs.Item = func(path btrfs.TreeWalkPath, item btrfs.Item) error { + cbs.Item = func(path btrfs.TreePath, item btrfs.Item) error { if item.Head.Key.ItemType == btrfsitem.ROOT_ITEM_KEY { root, ok := item.Body.(btrfsitem.Root) if !ok { @@ -73,7 +73,7 @@ func WalkFS(fs *btrfs.FS, cbs WalkFSHandler) { } origNode := cbs.Node - cbs.Node = func(path btrfs.TreeWalkPath, node *util.Ref[btrfs.LogicalAddr, btrfs.Node], err error) error { + cbs.Node = func(path btrfs.TreePath, node *util.Ref[btrfs.LogicalAddr, btrfs.Node], err error) error { if err != nil { handleErr(path, err) } -- cgit v1.2.3-2-g168b