diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2022-07-11 21:10:54 -0600 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2022-07-11 21:17:09 -0600 |
commit | 839dfa5d0aeadee9cb0f8581341922138f9595f0 (patch) | |
tree | 42130616613f57f0b9d40a7490a0f576aa94f35a /cmd/btrfs-ls-trees/main.go | |
parent | 0f853e1ead10347be8c5715d6bb797dd5e643e2f (diff) |
Move all of the small-ish tools to be part of btrfs-rec
Diffstat (limited to 'cmd/btrfs-ls-trees/main.go')
-rw-r--r-- | cmd/btrfs-ls-trees/main.go | 77 |
1 files changed, 0 insertions, 77 deletions
diff --git a/cmd/btrfs-ls-trees/main.go b/cmd/btrfs-ls-trees/main.go deleted file mode 100644 index a0ae460..0000000 --- a/cmd/btrfs-ls-trees/main.go +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright (C) 2022 Luke Shumaker <lukeshu@lukeshu.com> -// -// SPDX-License-Identifier: GPL-2.0-or-later - -package main - -import ( - "fmt" - "os" - "strconv" - "text/tabwriter" - - "git.lukeshu.com/btrfs-progs-ng/lib/btrfs" - "git.lukeshu.com/btrfs-progs-ng/lib/btrfs/btrfsitem" - "git.lukeshu.com/btrfs-progs-ng/lib/btrfsprogs/btrfsutil" - "git.lukeshu.com/btrfs-progs-ng/lib/util" -) - -func main() { - if err := Main(os.Args[1:]...); err != nil { - fmt.Fprintf(os.Stderr, "%v: error: %v\n", os.Args[0], err) - os.Exit(1) - } -} - -func Main(imgfilenames ...string) (err error) { - maybeSetErr := func(_err error) { - if _err != nil && err == nil { - err = _err - } - } - - fs, err := btrfsutil.Open(os.O_RDONLY, imgfilenames...) - if err != nil { - return err - } - defer func() { - maybeSetErr(fs.Close()) - }() - - var treeErrCnt int - var treeItemCnt map[btrfsitem.Type]int - btrfsutil.WalkAllTrees(fs, btrfsutil.WalkAllTreesHandler{ - PreTree: func(name string, treeID btrfs.ObjID) { - treeErrCnt = 0 - treeItemCnt = make(map[btrfsitem.Type]int) - fmt.Printf("tree id=%v name=%q\n", treeID, name) - }, - Err: func(_ error) { - treeErrCnt++ - }, - TreeWalkHandler: btrfs.TreeWalkHandler{ - Item: func(_ btrfs.TreePath, item btrfs.Item) error { - typ := item.Head.Key.ItemType - treeItemCnt[typ] = treeItemCnt[typ] + 1 - return nil - }, - }, - PostTree: func(_ string, _ btrfs.ObjID) { - totalItems := 0 - for _, cnt := range treeItemCnt { - totalItems += cnt - } - numWidth := len(strconv.Itoa(util.Max(treeErrCnt, totalItems))) - - table := tabwriter.NewWriter(os.Stdout, 0, 8, 2, ' ', 0) - fmt.Fprintf(table, " errors\t% *s\n", numWidth, strconv.Itoa(treeErrCnt)) - for _, typ := range util.SortedMapKeys(treeItemCnt) { - fmt.Fprintf(table, " %v items\t% *s\n", typ, numWidth, strconv.Itoa(treeItemCnt[typ])) - } - fmt.Fprintf(table, " total items\t% *s\n", numWidth, strconv.Itoa(totalItems)) - table.Flush() - }, - }) - - return nil -} |