diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2023-04-13 13:18:47 -0600 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2023-04-13 13:18:47 -0600 |
commit | 163e8a157ab812a8eafa3a1d2d2b8c0e45431559 (patch) | |
tree | 29a58434fd79f2c91a3603ed8e05cd22cf09d2af /cmd/btrfs-rec/inspect/rebuildtrees/scan.go | |
parent | f37ad3c90dab9b77e7c2796e963f5992458ad4a4 (diff) | |
parent | 1879a68976052d06cc62473a0712df9ce89b5013 (diff) |
Merge branch 'lukeshu/rebuilt-misc'
Diffstat (limited to 'cmd/btrfs-rec/inspect/rebuildtrees/scan.go')
-rw-r--r-- | cmd/btrfs-rec/inspect/rebuildtrees/scan.go | 43 |
1 files changed, 33 insertions, 10 deletions
diff --git a/cmd/btrfs-rec/inspect/rebuildtrees/scan.go b/cmd/btrfs-rec/inspect/rebuildtrees/scan.go index b1469ff..72557ea 100644 --- a/cmd/btrfs-rec/inspect/rebuildtrees/scan.go +++ b/cmd/btrfs-rec/inspect/rebuildtrees/scan.go @@ -31,14 +31,21 @@ type FlagsAndErr struct { Err error } -type ScanDevicesResult struct { - Superblock btrfstree.Superblock +// ExtentDataRefPtr is a pointer to a *btrfsitem.ExtentDataRef, +// whether it be to an EXTENT_DATA_REF item proper, or to an inline +// ref inside of another EXTENT_ITEM or METADATA_ITEM. +type ExtentDataRefPtr struct { + btrfsutil.ItemPtr + RefNum int // Only for EXTENT_ITEM and METADATA_ITEM +} +type ScanDevicesResult struct { Graph btrfsutil.Graph - Flags map[btrfsutil.ItemPtr]FlagsAndErr // INODE_ITEM - Names map[btrfsutil.ItemPtr][]byte // DIR_INDEX - Sizes map[btrfsutil.ItemPtr]SizeAndErr // EXTENT_CSUM and EXTENT_DATA + Flags map[btrfsutil.ItemPtr]FlagsAndErr // INODE_ITEM + Names map[btrfsutil.ItemPtr][]byte // DIR_INDEX + Sizes map[btrfsutil.ItemPtr]SizeAndErr // EXTENT_CSUM and EXTENT_DATA + DataBackrefs map[btrfsutil.ItemPtr][]btrfsprim.ObjID // EXTENT_DATA_REF, EXTENT_ITEM, and METADATA_ITEM } func ScanDevices(_ctx context.Context, fs *btrfs.FS, nodeList []btrfsvol.LogicalAddr) (ScanDevicesResult, error) { @@ -53,12 +60,12 @@ func ScanDevices(_ctx context.Context, fs *btrfs.FS, nodeList []btrfsvol.Logical // read-roots ////////////////////////////////////////////////////////////////// ctx = dlog.WithField(_ctx, "btrfs.inspect.rebuild-trees.read.substep", "read-roots") ret := ScanDevicesResult{ - Superblock: *sb, - Graph: btrfsutil.NewGraph(ctx, *sb), - Flags: make(map[btrfsutil.ItemPtr]FlagsAndErr), - Names: make(map[btrfsutil.ItemPtr][]byte), - Sizes: make(map[btrfsutil.ItemPtr]SizeAndErr), + + Flags: make(map[btrfsutil.ItemPtr]FlagsAndErr), + Names: make(map[btrfsutil.ItemPtr][]byte), + Sizes: make(map[btrfsutil.ItemPtr]SizeAndErr), + DataBackrefs: make(map[btrfsutil.ItemPtr][]btrfsprim.ObjID), } // read-nodes ////////////////////////////////////////////////////////////////// @@ -132,6 +139,22 @@ func (o *ScanDevicesResult) insertNode(node *btrfstree.Node) { Size: uint64(size), Err: err, } + case *btrfsitem.Extent: + o.DataBackrefs[ptr] = make([]btrfsprim.ObjID, len(itemBody.Refs)) + for i, ref := range itemBody.Refs { + if refBody, ok := ref.Body.(*btrfsitem.ExtentDataRef); ok { + o.DataBackrefs[ptr][i] = refBody.Root + } + } + case *btrfsitem.Metadata: + o.DataBackrefs[ptr] = make([]btrfsprim.ObjID, len(itemBody.Refs)) + for i, ref := range itemBody.Refs { + if refBody, ok := ref.Body.(*btrfsitem.ExtentDataRef); ok { + o.DataBackrefs[ptr][i] = refBody.Root + } + } + case *btrfsitem.ExtentDataRef: + o.DataBackrefs[ptr] = []btrfsprim.ObjID{itemBody.Root} case *btrfsitem.Error: switch item.Key.ItemType { case btrfsprim.INODE_ITEM_KEY: |