diff options
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/btrfs/btree.go | 48 | ||||
-rw-r--r-- | pkg/btrfs/io2_fs.go | 4 | ||||
-rw-r--r-- | pkg/btrfsmisc/print_tree.go | 8 | ||||
-rw-r--r-- | pkg/btrfsmisc/walk.go | 20 |
4 files changed, 40 insertions, 40 deletions
diff --git a/pkg/btrfs/btree.go b/pkg/btrfs/btree.go index d2ba2dd..99c909f 100644 --- a/pkg/btrfs/btree.go +++ b/pkg/btrfs/btree.go @@ -11,8 +11,8 @@ import ( "lukeshu.com/btrfs-tools/pkg/util" ) -// A WalkTreePathElem essentially represents a KeyPointer. -type WalkTreePathElem struct { +// A TreeWalkPathElem essentially represents a KeyPointer. +type TreeWalkPathElem 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 @@ -25,7 +25,7 @@ type WalkTreePathElem struct { NodeLevel uint8 } -func (elem WalkTreePathElem) writeNodeTo(w io.Writer) { +func (elem TreeWalkPathElem) writeNodeTo(w io.Writer) { if elem.NodeLevel != math.MaxUint8 { fmt.Fprintf(w, "node:%d@%v", elem.NodeLevel, elem.NodeAddr) } else { @@ -37,9 +37,9 @@ func (elem WalkTreePathElem) writeNodeTo(w io.Writer) { // // - For .Item() callbacks, the last element will always have a // NodeAddr of 0. -type WalkTreePath []WalkTreePathElem +type TreeWalkPath []TreeWalkPathElem -func (path WalkTreePath) String() string { +func (path TreeWalkPath) String() string { if len(path) == 0 { return "(empty-path)" } @@ -55,16 +55,16 @@ func (path WalkTreePath) String() string { return ret.String() } -type WalkTreeHandler struct { +type TreeWalkHandler struct { // Callbacks for entire nodes - PreNode func(WalkTreePath) error - Node func(WalkTreePath, *util.Ref[LogicalAddr, Node], error) error - PostNode func(WalkTreePath, *util.Ref[LogicalAddr, Node]) error + PreNode func(TreeWalkPath) error + Node func(TreeWalkPath, *util.Ref[LogicalAddr, Node], error) error + PostNode func(TreeWalkPath, *util.Ref[LogicalAddr, Node]) error // Callbacks for items on internal nodes - PreKeyPointer func(WalkTreePath, KeyPointer) error - PostKeyPointer func(WalkTreePath, KeyPointer) error + PreKeyPointer func(TreeWalkPath, KeyPointer) error + PostKeyPointer func(TreeWalkPath, KeyPointer) error // Callbacks for items on leaf nodes - Item func(WalkTreePath, Item) error + Item func(TreeWalkPath, Item) error } // The lifecycle of callbacks is: @@ -80,18 +80,18 @@ type WalkTreeHandler struct { // else: // 004 .Item() // 007 .PostNode() -func (fs *FS) WalkTree(nodeAddr LogicalAddr, cbs WalkTreeHandler) error { - path := WalkTreePath{ - WalkTreePathElem{ +func (fs *FS) TreeWalk(treeRoot LogicalAddr, cbs TreeWalkHandler) error { + path := TreeWalkPath{ + TreeWalkPathElem{ ItemIdx: -1, - NodeAddr: nodeAddr, + NodeAddr: treeRoot, NodeLevel: math.MaxUint8, }, } - return fs.walkTree(path, cbs) + return fs.treeWalk(path, cbs) } -func (fs *FS) walkTree(path WalkTreePath, cbs WalkTreeHandler) error { +func (fs *FS) treeWalk(path TreeWalkPath, cbs TreeWalkHandler) error { if path[len(path)-1].NodeAddr == 0 { return nil } @@ -107,7 +107,7 @@ func (fs *FS) walkTree(path WalkTreePath, cbs WalkTreeHandler) error { node, err := fs.ReadNode(path[len(path)-1].NodeAddr) if node != nil { if exp := path[len(path)-1].NodeLevel; exp != math.MaxUint8 && node.Data.Head.Level != exp && err == nil { - err = fmt.Errorf("btrfs.FS.WalkTree: node@%v: expected level %v but has level %v", + err = fmt.Errorf("btrfs.FS.TreeWalk: node@%v: expected level %v but has level %v", node.Addr, exp, node.Data.Head.Level) } path[len(path)-1].NodeLevel = node.Data.Head.Level @@ -119,11 +119,11 @@ func (fs *FS) walkTree(path WalkTreePath, cbs WalkTreeHandler) error { if errors.Is(err, iofs.SkipDir) { return nil } - return fmt.Errorf("btrfs.FS.WalkTree: %w", err) + return fmt.Errorf("btrfs.FS.TreeWalk: %w", err) } if node != nil { for i, item := range node.Data.BodyInternal { - itemPath := append(path, WalkTreePathElem{ + itemPath := append(path, TreeWalkPathElem{ ItemIdx: i, NodeAddr: item.BlockPtr, NodeLevel: node.Data.Head.Level - 1, @@ -136,7 +136,7 @@ func (fs *FS) walkTree(path WalkTreePath, cbs WalkTreeHandler) error { return err } } - if err := fs.walkTree(itemPath, cbs); err != nil { + if err := fs.treeWalk(itemPath, cbs); err != nil { return err } if cbs.PostKeyPointer != nil { @@ -150,14 +150,14 @@ func (fs *FS) walkTree(path WalkTreePath, cbs WalkTreeHandler) error { } for i, item := range node.Data.BodyLeaf { if cbs.Item != nil { - itemPath := append(path, WalkTreePathElem{ + itemPath := append(path, TreeWalkPathElem{ ItemIdx: i, }) if err := cbs.Item(itemPath, item); err != nil { if errors.Is(err, iofs.SkipDir) { continue } - return fmt.Errorf("btrfs.FS.WalkTree: callback: %w", err) + return fmt.Errorf("btrfs.FS.TreeWalk: callback: %w", err) } } } diff --git a/pkg/btrfs/io2_fs.go b/pkg/btrfs/io2_fs.go index 740e6e6..d71d4b2 100644 --- a/pkg/btrfs/io2_fs.go +++ b/pkg/btrfs/io2_fs.go @@ -150,8 +150,8 @@ func (fs *FS) initDev(sb *util.Ref[PhysicalAddr, Superblock]) error { } } } - if err := fs.WalkTree(sb.Data.ChunkTree, WalkTreeHandler{ - Item: func(_ WalkTreePath, item Item) error { + if err := fs.TreeWalk(sb.Data.ChunkTree, TreeWalkHandler{ + Item: func(_ TreeWalkPath, 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 c11a294..3f1dd46 100644 --- a/pkg/btrfsmisc/print_tree.go +++ b/pkg/btrfsmisc/print_tree.go @@ -14,8 +14,8 @@ import ( // kernel-shared/print-tree.c:btrfs_print_tree() and // kernel-shared/print-tree.c:btrfs_print_leaf() func PrintTree(fs *btrfs.FS, root btrfs.LogicalAddr) error { - return fs.WalkTree(root, btrfs.WalkTreeHandler{ - Node: func(path btrfs.WalkTreePath, nodeRef *util.Ref[btrfs.LogicalAddr, btrfs.Node], err error) error { + return fs.TreeWalk(root, btrfs.TreeWalkHandler{ + Node: func(path btrfs.TreeWalkPath, 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.WalkTreePath, item btrfs.KeyPointer) error { + PreKeyPointer: func(_ btrfs.TreeWalkPath, 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.WalkTreePath, item btrfs.Item) error { + Item: func(path btrfs.TreeWalkPath, 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 a82bd5f..545afb9 100644 --- a/pkg/btrfsmisc/walk.go +++ b/pkg/btrfsmisc/walk.go @@ -10,7 +10,7 @@ import ( type WalkErr struct { TreeName string - Path btrfs.WalkTreePath + Path btrfs.TreeWalkPath Err error } @@ -29,7 +29,7 @@ type WalkFSHandler struct { PreTree func(name string, laddr btrfs.LogicalAddr) PostTree func(name string, laddr btrfs.LogicalAddr) // Callbacks for nodes or smaller - btrfs.WalkTreeHandler + btrfs.TreeWalkHandler } // WalkFS walks all trees in a *btrfs.FS. Rather than returning an @@ -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.WalkTreePath, err error) { + handleErr := func(path btrfs.TreeWalkPath, 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.WalkTreePath, item btrfs.Item) error { + cbs.Item = func(path btrfs.TreeWalkPath, 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.WalkTreePath, node *util.Ref[btrfs.LogicalAddr, btrfs.Node], err error) error { + cbs.Node = func(path btrfs.TreeWalkPath, node *util.Ref[btrfs.LogicalAddr, btrfs.Node], err error) error { if err != nil { handleErr(path, err) } @@ -92,28 +92,28 @@ func WalkFS(fs *btrfs.FS, cbs WalkFSHandler) { treeName = "root tree" cbs.PreTree(treeName, superblock.Data.RootTree) - if err := fs.WalkTree(superblock.Data.RootTree, cbs.WalkTreeHandler); err != nil { + if err := fs.TreeWalk(superblock.Data.RootTree, cbs.TreeWalkHandler); err != nil { handleErr(nil, err) } cbs.PostTree(treeName, superblock.Data.RootTree) treeName = "chunk tree" cbs.PreTree(treeName, superblock.Data.ChunkTree) - if err := fs.WalkTree(superblock.Data.ChunkTree, cbs.WalkTreeHandler); err != nil { + if err := fs.TreeWalk(superblock.Data.ChunkTree, cbs.TreeWalkHandler); err != nil { handleErr(nil, err) } cbs.PostTree(treeName, superblock.Data.ChunkTree) treeName = "log tree" cbs.PreTree(treeName, superblock.Data.LogTree) - if err := fs.WalkTree(superblock.Data.LogTree, cbs.WalkTreeHandler); err != nil { + if err := fs.TreeWalk(superblock.Data.LogTree, cbs.TreeWalkHandler); err != nil { handleErr(nil, err) } cbs.PostTree(treeName, superblock.Data.LogTree) treeName = "block group tree" cbs.PreTree(treeName, superblock.Data.BlockGroupRoot) - if err := fs.WalkTree(superblock.Data.BlockGroupRoot, cbs.WalkTreeHandler); err != nil { + if err := fs.TreeWalk(superblock.Data.BlockGroupRoot, cbs.TreeWalkHandler); err != nil { handleErr(nil, err) } cbs.PostTree(treeName, superblock.Data.BlockGroupRoot) @@ -121,7 +121,7 @@ func WalkFS(fs *btrfs.FS, cbs WalkFSHandler) { for _, tree := range foundTrees { treeName = tree.Name cbs.PreTree(treeName, tree.Root) - if err := fs.WalkTree(tree.Root, cbs.WalkTreeHandler); err != nil { + if err := fs.TreeWalk(tree.Root, cbs.TreeWalkHandler); err != nil { handleErr(nil, err) } cbs.PostTree(treeName, tree.Root) |