diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2022-07-12 19:34:42 -0600 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2022-07-12 19:34:42 -0600 |
commit | d250398e68fae70bd765a7f90389b58a4eeb4ee2 (patch) | |
tree | 2fb30dabf280ff85d04b46a14e90a4997f768fa3 /lib | |
parent | bba3428e8f034802b4b5ceb772bde1285a65ee50 (diff) |
check for bad items
Big indentation change in print_tree.go; small actual change.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/btrfs/btrfsitem/items.go | 2 | ||||
-rw-r--r-- | lib/btrfs/io3_btree.go | 37 | ||||
-rw-r--r-- | lib/btrfsprogs/btrfsinspect/print_tree.go | 492 |
3 files changed, 273 insertions, 258 deletions
diff --git a/lib/btrfs/btrfsitem/items.go b/lib/btrfs/btrfsitem/items.go index 30980d3..769a0a8 100644 --- a/lib/btrfs/btrfsitem/items.go +++ b/lib/btrfs/btrfsitem/items.go @@ -35,7 +35,7 @@ func (o *Error) UnmarshalBinary(dat []byte) (int, error) { return len(dat), nil } -// Rather than returning a separate error value, return an Error item. +// Rather than returning a separate error value, return an Error item. func UnmarshalItem(key internal.Key, csumType btrfssum.CSumType, dat []byte) Item { var gotyp reflect.Type if key.ItemType == UNTYPED_KEY { diff --git a/lib/btrfs/io3_btree.go b/lib/btrfs/io3_btree.go index 759e378..a02a857 100644 --- a/lib/btrfs/io3_btree.go +++ b/lib/btrfs/io3_btree.go @@ -208,7 +208,8 @@ type TreeWalkHandler struct { PreKeyPointer func(TreePath, KeyPointer) error PostKeyPointer func(TreePath, KeyPointer) error // Callbacks for items on leaf nodes - Item func(TreePath, Item) error + Item func(TreePath, Item) error + BadItem func(TreePath, Item) error } // The lifecycle of callbacks is: @@ -222,7 +223,7 @@ type TreeWalkHandler struct { // 005 (recurse) // 006 .PostKeyPointer() // else: -// 004 .Item() +// 004 .Item() (or .BadItem()) // 007 .PostNode() func (fs *FS) TreeWalk(treeID ObjID, errHandle func(*TreeError), cbs TreeWalkHandler) { path := TreePath{ @@ -259,8 +260,10 @@ func (fs *FS) treeWalk(path TreePath, errHandle func(*TreeError), cbs TreeWalkHa if err != nil { errHandle(&TreeError{Path: path, Err: err}) } else { - if err := cbs.Node(path, node); err != nil { - errHandle(&TreeError{Path: path, Err: err}) + if cbs.Node != nil { + if err := cbs.Node(path, node); err != nil { + errHandle(&TreeError{Path: path, Err: err}) + } } } if node != nil { @@ -272,23 +275,33 @@ func (fs *FS) treeWalk(path TreePath, errHandle func(*TreeError), cbs TreeWalkHa }) if cbs.PreKeyPointer != nil { if err := cbs.PreKeyPointer(itemPath, item); err != nil { - errHandle(&TreeError{Path: path, Err: err}) + errHandle(&TreeError{Path: itemPath, Err: err}) } } fs.treeWalk(itemPath, errHandle, cbs) if cbs.PostKeyPointer != nil { if err := cbs.PostKeyPointer(itemPath, item); err != nil { - errHandle(&TreeError{Path: path, Err: err}) + errHandle(&TreeError{Path: itemPath, Err: err}) } } } for i, item := range node.Data.BodyLeaf { - if cbs.Item != nil { - itemPath := path.Append(TreePathElem{ - ItemIdx: i, - }) - if err := cbs.Item(itemPath, item); err != nil { - errHandle(&TreeError{Path: path, Err: err}) + itemPath := path.Append(TreePathElem{ + ItemIdx: i, + }) + if errBody, isErr := item.Body.(btrfsitem.Error); isErr { + if cbs.BadItem == nil { + errHandle(&TreeError{Path: itemPath, Err: errBody.Err}) + } else { + if err := cbs.BadItem(itemPath, item); err != nil { + errHandle(&TreeError{Path: itemPath, Err: err}) + } + } + } else { + if cbs.Item != nil { + if err := cbs.Item(itemPath, item); err != nil { + errHandle(&TreeError{Path: itemPath, Err: err}) + } } } } diff --git a/lib/btrfsprogs/btrfsinspect/print_tree.go b/lib/btrfsprogs/btrfsinspect/print_tree.go index 78a9df6..2de9818 100644 --- a/lib/btrfsprogs/btrfsinspect/print_tree.go +++ b/lib/btrfsprogs/btrfsinspect/print_tree.go @@ -92,260 +92,262 @@ func DumpTrees(ctx context.Context, out io.Writer, fs *btrfs.FS) { // kernel-shared/print-tree.c:btrfs_print_leaf() func printTree(ctx context.Context, out io.Writer, fs *btrfs.FS, treeID btrfs.ObjID) { var itemOffset uint32 - fs.TreeWalk( - treeID, - func(err *btrfs.TreeError) { - dlog.Error(ctx, err) + handlers := btrfs.TreeWalkHandler{ + Node: func(path btrfs.TreePath, nodeRef *util.Ref[btrfsvol.LogicalAddr, btrfs.Node]) error { + printHeaderInfo(out, nodeRef.Data) + itemOffset = nodeRef.Data.Size - uint32(binstruct.StaticSize(btrfs.NodeHeader{})) + return nil }, - btrfs.TreeWalkHandler{ - Node: func(path btrfs.TreePath, nodeRef *util.Ref[btrfsvol.LogicalAddr, btrfs.Node]) error { - printHeaderInfo(out, nodeRef.Data) - itemOffset = nodeRef.Data.Size - uint32(binstruct.StaticSize(btrfs.NodeHeader{})) - return nil - }, - PreKeyPointer: func(_ btrfs.TreePath, item btrfs.KeyPointer) error { - fmt.Fprintf(out, "\t%v block %v gen %v\n", - fmtKey(item.Key), - item.BlockPtr, - item.Generation) - return nil - }, - Item: func(path btrfs.TreePath, item btrfs.Item) error { - i := path.Nodes[len(path.Nodes)-1].ItemIdx - bs, _ := binstruct.Marshal(item.Body) - itemSize := uint32(len(bs)) - itemOffset -= itemSize - fmt.Fprintf(out, "\titem %v %v itemoff %v itemsize %v\n", - i, - fmtKey(item.Key), - itemOffset, - itemSize) - switch body := item.Body.(type) { - case btrfsitem.FreeSpaceHeader: - fmt.Fprintf(out, "\t\tlocation %v\n", fmtKey(body.Location)) - fmt.Fprintf(out, "\t\tcache generation %v entries %v bitmaps %v\n", - body.Generation, body.NumEntries, body.NumBitmaps) - case btrfsitem.Inode: - fmt.Fprintf(out, ""+ - "\t\tgeneration %v transid %v size %v nbytes %v\n"+ - "\t\tblock group %v mode %o links %v uid %v gid %v rdev %v\n"+ - "\t\tsequence %v flags %v\n", - body.Generation, body.TransID, body.Size, body.NumBytes, - body.BlockGroup, body.Mode, body.NLink, body.UID, body.GID, body.RDev, - body.Sequence, body.Flags) - fmt.Fprintf(out, "\t\tatime %v\n", fmtTime(body.ATime)) + PreKeyPointer: func(_ btrfs.TreePath, item btrfs.KeyPointer) error { + fmt.Fprintf(out, "\t%v block %v gen %v\n", + fmtKey(item.Key), + item.BlockPtr, + item.Generation) + return nil + }, + Item: func(path btrfs.TreePath, item btrfs.Item) error { + i := path.Nodes[len(path.Nodes)-1].ItemIdx + bs, _ := binstruct.Marshal(item.Body) + itemSize := uint32(len(bs)) + itemOffset -= itemSize + fmt.Fprintf(out, "\titem %v %v itemoff %v itemsize %v\n", + i, + fmtKey(item.Key), + itemOffset, + itemSize) + switch body := item.Body.(type) { + case btrfsitem.FreeSpaceHeader: + fmt.Fprintf(out, "\t\tlocation %v\n", fmtKey(body.Location)) + fmt.Fprintf(out, "\t\tcache generation %v entries %v bitmaps %v\n", + body.Generation, body.NumEntries, body.NumBitmaps) + case btrfsitem.Inode: + fmt.Fprintf(out, ""+ + "\t\tgeneration %v transid %v size %v nbytes %v\n"+ + "\t\tblock group %v mode %o links %v uid %v gid %v rdev %v\n"+ + "\t\tsequence %v flags %v\n", + body.Generation, body.TransID, body.Size, body.NumBytes, + body.BlockGroup, body.Mode, body.NLink, body.UID, body.GID, body.RDev, + body.Sequence, body.Flags) + fmt.Fprintf(out, "\t\tatime %v\n", fmtTime(body.ATime)) + fmt.Fprintf(out, "\t\tctime %v\n", fmtTime(body.CTime)) + fmt.Fprintf(out, "\t\tmtime %v\n", fmtTime(body.MTime)) + fmt.Fprintf(out, "\t\totime %v\n", fmtTime(body.OTime)) + case btrfsitem.InodeRef: + fmt.Fprintf(out, "\t\tindex %v namelen %v name: %s\n", + body.Index, body.NameLen, body.Name) + //case btrfsitem.INODE_EXTREF_KEY: + // // TODO + case btrfsitem.DirEntry: + fmt.Fprintf(out, "\t\tlocation %v type %v\n", + fmtKey(body.Location), body.Type) + fmt.Fprintf(out, "\t\ttransid %v data_len %v name_len %v\n", + body.TransID, body.DataLen, body.NameLen) + fmt.Fprintf(out, "\t\tname: %s\n", body.Name) + if len(body.Data) > 0 { + fmt.Fprintf(out, "\t\tdata %v\n", body.Data) + } + //case btrfsitem.DIR_LOG_INDEX_KEY, btrfsitem.DIR_LOG_ITEM_KEY: + // // TODO + case btrfsitem.Root: + fmt.Fprintf(out, "\t\tgeneration %v root_dirid %v bytenr %d byte_limit %v bytes_used %v\n", + body.Generation, body.RootDirID, body.ByteNr, body.ByteLimit, body.BytesUsed) + fmt.Fprintf(out, "\t\tlast_snapshot %v flags %v refs %v\n", + body.LastSnapshot, body.Flags, body.Refs) + fmt.Fprintf(out, "\t\tdrop_progress %v drop_level %v\n", + fmtKey(body.DropProgress), body.DropLevel) + fmt.Fprintf(out, "\t\tlevel %v generation_v2 %v\n", + body.Level, body.GenerationV2) + if body.Generation == body.GenerationV2 { + fmt.Fprintf(out, "\t\tuuid %v\n", body.UUID) + fmt.Fprintf(out, "\t\tparent_uuid %v\n", body.ParentUUID) + fmt.Fprintf(out, "\t\treceived_uuid %v\n", body.ReceivedUUID) + fmt.Fprintf(out, "\t\tctransid %v otransid %v stransid %v rtransid %v\n", + body.CTransID, body.OTransID, body.STransID, body.RTransID) fmt.Fprintf(out, "\t\tctime %v\n", fmtTime(body.CTime)) - fmt.Fprintf(out, "\t\tmtime %v\n", fmtTime(body.MTime)) fmt.Fprintf(out, "\t\totime %v\n", fmtTime(body.OTime)) - case btrfsitem.InodeRef: - fmt.Fprintf(out, "\t\tindex %v namelen %v name: %s\n", - body.Index, body.NameLen, body.Name) - //case btrfsitem.INODE_EXTREF_KEY: - // // TODO - case btrfsitem.DirEntry: - fmt.Fprintf(out, "\t\tlocation %v type %v\n", - fmtKey(body.Location), body.Type) - fmt.Fprintf(out, "\t\ttransid %v data_len %v name_len %v\n", - body.TransID, body.DataLen, body.NameLen) - fmt.Fprintf(out, "\t\tname: %s\n", body.Name) - if len(body.Data) > 0 { - fmt.Fprintf(out, "\t\tdata %v\n", body.Data) - } - //case btrfsitem.DIR_LOG_INDEX_KEY, btrfsitem.DIR_LOG_ITEM_KEY: - // // TODO - case btrfsitem.Root: - fmt.Fprintf(out, "\t\tgeneration %v root_dirid %v bytenr %d byte_limit %v bytes_used %v\n", - body.Generation, body.RootDirID, body.ByteNr, body.ByteLimit, body.BytesUsed) - fmt.Fprintf(out, "\t\tlast_snapshot %v flags %v refs %v\n", - body.LastSnapshot, body.Flags, body.Refs) - fmt.Fprintf(out, "\t\tdrop_progress %v drop_level %v\n", - fmtKey(body.DropProgress), body.DropLevel) - fmt.Fprintf(out, "\t\tlevel %v generation_v2 %v\n", - body.Level, body.GenerationV2) - if body.Generation == body.GenerationV2 { - fmt.Fprintf(out, "\t\tuuid %v\n", body.UUID) - fmt.Fprintf(out, "\t\tparent_uuid %v\n", body.ParentUUID) - fmt.Fprintf(out, "\t\treceived_uuid %v\n", body.ReceivedUUID) - fmt.Fprintf(out, "\t\tctransid %v otransid %v stransid %v rtransid %v\n", - body.CTransID, body.OTransID, body.STransID, body.RTransID) - fmt.Fprintf(out, "\t\tctime %v\n", fmtTime(body.CTime)) - fmt.Fprintf(out, "\t\totime %v\n", fmtTime(body.OTime)) - fmt.Fprintf(out, "\t\tstime %v\n", fmtTime(body.STime)) - fmt.Fprintf(out, "\t\trtime %v\n", fmtTime(body.RTime)) - } - case btrfsitem.RootRef: - var tag string - switch item.Key.ItemType { - case btrfsitem.ROOT_REF_KEY: - tag = "ref" - case btrfsitem.ROOT_BACKREF_KEY: - tag = "backref" - default: - tag = fmt.Sprintf("(error: unhandled RootRef item type: %v)", item.Key.ItemType) - } - fmt.Fprintf(out, "\t\troot %v key dirid %v sequence %v name %s\n", - tag, body.DirID, body.Sequence, body.Name) - case btrfsitem.Extent: - fmt.Fprintf(out, "\t\trefs %v gen %v flags %v\n", - body.Head.Refs, body.Head.Generation, body.Head.Flags) - if body.Head.Flags.Has(btrfsitem.EXTENT_FLAG_TREE_BLOCK) { - fmt.Fprintf(out, "\t\ttree block %v level %v\n", - fmtKey(body.Info.Key), body.Info.Level) - } - printExtentInlineRefs(out, body.Refs) - case btrfsitem.Metadata: - fmt.Fprintf(out, "\t\trefs %v gen %v flags %v\n", - body.Head.Refs, body.Head.Generation, body.Head.Flags) - fmt.Fprintf(out, "\t\ttree block skinny level %v\n", item.Key.Offset) - printExtentInlineRefs(out, body.Refs) - //case btrfsitem.EXTENT_DATA_REF_KEY: - // // TODO - //case btrfsitem.SHARED_DATA_REF_KEY: - // // TODO - case btrfsitem.ExtentCSum: - sb, _ := fs.Superblock() - sectorSize := btrfsvol.AddrDelta(sb.Data.SectorSize) + fmt.Fprintf(out, "\t\tstime %v\n", fmtTime(body.STime)) + fmt.Fprintf(out, "\t\trtime %v\n", fmtTime(body.RTime)) + } + case btrfsitem.RootRef: + var tag string + switch item.Key.ItemType { + case btrfsitem.ROOT_REF_KEY: + tag = "ref" + case btrfsitem.ROOT_BACKREF_KEY: + tag = "backref" + default: + tag = fmt.Sprintf("(error: unhandled RootRef item type: %v)", item.Key.ItemType) + } + fmt.Fprintf(out, "\t\troot %v key dirid %v sequence %v name %s\n", + tag, body.DirID, body.Sequence, body.Name) + case btrfsitem.Extent: + fmt.Fprintf(out, "\t\trefs %v gen %v flags %v\n", + body.Head.Refs, body.Head.Generation, body.Head.Flags) + if body.Head.Flags.Has(btrfsitem.EXTENT_FLAG_TREE_BLOCK) { + fmt.Fprintf(out, "\t\ttree block %v level %v\n", + fmtKey(body.Info.Key), body.Info.Level) + } + printExtentInlineRefs(out, body.Refs) + case btrfsitem.Metadata: + fmt.Fprintf(out, "\t\trefs %v gen %v flags %v\n", + body.Head.Refs, body.Head.Generation, body.Head.Flags) + fmt.Fprintf(out, "\t\ttree block skinny level %v\n", item.Key.Offset) + printExtentInlineRefs(out, body.Refs) + //case btrfsitem.EXTENT_DATA_REF_KEY: + // // TODO + //case btrfsitem.SHARED_DATA_REF_KEY: + // // TODO + case btrfsitem.ExtentCSum: + sb, _ := fs.Superblock() + sectorSize := btrfsvol.AddrDelta(sb.Data.SectorSize) - start := btrfsvol.LogicalAddr(item.Key.Offset) - itemSize := btrfsvol.AddrDelta(len(body.Sums)) * sectorSize - fmt.Fprintf(out, "\t\trange start %d end %d length %d", - start, start.Add(itemSize), itemSize) - sumsPerLine := util.Max(1, len(btrfssum.CSum{})/body.ChecksumSize/2) + start := btrfsvol.LogicalAddr(item.Key.Offset) + itemSize := btrfsvol.AddrDelta(len(body.Sums)) * sectorSize + fmt.Fprintf(out, "\t\trange start %d end %d length %d", + start, start.Add(itemSize), itemSize) + sumsPerLine := util.Max(1, len(btrfssum.CSum{})/body.ChecksumSize/2) - pos := start - for i, sum := range body.Sums { - if i%sumsPerLine == 0 { - fmt.Fprintf(out, "\n\t\t") - } else { - fmt.Fprintf(out, " ") - } - fmt.Fprintf(out, "[%d] 0x%s", pos, sum.Fmt(sb.Data.ChecksumType)) - pos = pos.Add(sectorSize) - } - fmt.Fprintf(out, "\n") - case btrfsitem.FileExtent: - fmt.Fprintf(out, "\t\tgeneration %v type %v\n", - body.Generation, body.Type) - switch body.Type { - case btrfsitem.FILE_EXTENT_INLINE: - fmt.Fprintf(out, "\t\tinline extent data size %v ram_bytes %v compression %v\n", - len(body.BodyInline), body.RAMBytes, body.Compression) - case btrfsitem.FILE_EXTENT_PREALLOC: - fmt.Fprintf(out, "\t\tprealloc data disk byte %v nr %v\n", - body.BodyExtent.DiskByteNr, - body.BodyExtent.DiskNumBytes) - fmt.Fprintf(out, "\t\tprealloc data offset %v nr %v\n", - body.BodyExtent.Offset, - body.BodyExtent.NumBytes) - case btrfsitem.FILE_EXTENT_REG: - fmt.Fprintf(out, "\t\textent data disk byte %d nr %d\n", - body.BodyExtent.DiskByteNr, - body.BodyExtent.DiskNumBytes) - fmt.Fprintf(out, "\t\textent data offset %d nr %d ram %v\n", - body.BodyExtent.Offset, - body.BodyExtent.NumBytes, - body.RAMBytes) - fmt.Fprintf(out, "\t\textent compression %v\n", - body.Compression) - default: - fmt.Fprintf(out, "\t\t(error) unknown file extent type %v", body.Type) + pos := start + for i, sum := range body.Sums { + if i%sumsPerLine == 0 { + fmt.Fprintf(out, "\n\t\t") + } else { + fmt.Fprintf(out, " ") } - case btrfsitem.BlockGroup: - fmt.Fprintf(out, "\t\tblock group used %v chunk_objectid %v flags %v\n", - body.Used, body.ChunkObjectID, body.Flags) - case btrfsitem.FreeSpaceInfo: - fmt.Fprintf(out, "\t\tfree space info extent count %v flags %v\n", - body.ExtentCount, body.Flags) - case btrfsitem.FreeSpaceBitmap: - fmt.Fprintf(out, "\t\tfree space bitmap\n") - case btrfsitem.Chunk: - fmt.Fprintf(out, "\t\tlength %d owner %d stripe_len %v type %v\n", - body.Head.Size, body.Head.Owner, body.Head.StripeLen, body.Head.Type) - fmt.Fprintf(out, "\t\tio_align %v io_width %v sector_size %v\n", - body.Head.IOOptimalAlign, body.Head.IOOptimalWidth, body.Head.IOMinSize) - fmt.Fprintf(out, "\t\tnum_stripes %v sub_stripes %v\n", - body.Head.NumStripes, body.Head.SubStripes) - for i, stripe := range body.Stripes { - fmt.Fprintf(out, "\t\t\tstripe %v devid %d offset %d\n", - i, stripe.DeviceID, stripe.Offset) - fmt.Fprintf(out, "\t\t\tdev_uuid %v\n", - stripe.DeviceUUID) - } - case btrfsitem.Dev: - fmt.Fprintf(out, ""+ - "\t\tdevid %d total_bytes %v bytes_used %v\n"+ - "\t\tio_align %v io_width %v sector_size %v type %v\n"+ - "\t\tgeneration %v start_offset %v dev_group %v\n"+ - "\t\tseek_speed %v bandwidth %v\n"+ - "\t\tuuid %v\n"+ - "\t\tfsid %v\n", - body.DevID, body.NumBytes, body.NumBytesUsed, - body.IOOptimalAlign, body.IOOptimalWidth, body.IOMinSize, body.Type, - body.Generation, body.StartOffset, body.DevGroup, - body.SeekSpeed, body.Bandwidth, - body.DevUUID, - body.FSUUID) - case btrfsitem.DevExtent: - fmt.Fprintf(out, ""+ - "\t\tdev extent chunk_tree %v\n"+ - "\t\tchunk_objectid %v chunk_offset %d length %d\n"+ - "\t\tchunk_tree_uuid %v\n", - body.ChunkTree, body.ChunkObjectID, body.ChunkOffset, body.Length, - body.ChunkTreeUUID) - //case btrfsitem.QGROUP_STATUS_KEY: - // // TODO - //case btrfsitem.QGROUP_INFO_KEY: - // // TODO - //case btrfsitem.QGROUP_LIMIT_KEY: - // // TODO - case btrfsitem.UUIDMap: - fmt.Fprintf(out, "\t\tsubvol_id %d\n", body.ObjID) - //case btrfsitem.STRING_ITEM_KEY: - // // TODO - case btrfsitem.DevStats: - fmt.Fprintf(out, "\t\tpersistent item objectid %v offset %v\n", - item.Key.ObjectID.Format(item.Key.ItemType), item.Key.Offset) - switch item.Key.ObjectID { - case btrfs.DEV_STATS_OBJECTID: - fmt.Fprintf(out, "\t\tdevice stats\n") - fmt.Fprintf(out, "\t\twrite_errs %v read_errs %v flush_errs %v corruption_errs %v generation %v\n", - body.Values[btrfsitem.DEV_STAT_WRITE_ERRS], - body.Values[btrfsitem.DEV_STAT_READ_ERRS], - body.Values[btrfsitem.DEV_STAT_FLUSH_ERRS], - body.Values[btrfsitem.DEV_STAT_CORRUPTION_ERRS], - body.Values[btrfsitem.DEV_STAT_GENERATION_ERRS]) - default: - fmt.Fprintf(out, "\t\tunknown persistent item objectid %v\n", item.Key.ObjectID) - } - //case btrfsitem.TEMPORARY_ITEM_KEY: - // // TODO - case btrfsitem.Empty: - switch item.Key.ItemType { - case btrfsitem.ORPHAN_ITEM_KEY: // 48 - fmt.Fprintf(out, "\t\torphan item\n") - case btrfsitem.TREE_BLOCK_REF_KEY: // 176 - fmt.Fprintf(out, "\t\ttree block backref\n") - case btrfsitem.SHARED_BLOCK_REF_KEY: // 182 - fmt.Fprintf(out, "\t\tshared block backref\n") - case btrfsitem.FREE_SPACE_EXTENT_KEY: // 199 - fmt.Fprintf(out, "\t\tfree space extent\n") - case btrfsitem.QGROUP_RELATION_KEY: // 246 - // do nothing - //case btrfsitem.EXTENT_REF_V0_KEY: - // fmt.Fprintf(out, "\t\textent ref v0 (deprecated)\n") - //case btrfsitem.CSUM_ITEM_KEY: - // fmt.Fprintf(out, "\t\tcsum item\n") - default: - fmt.Fprintf(out, "\t\t(error) unhandled empty item type: %v\n", item.Key.ItemType) - } - case btrfsitem.Error: - fmt.Fprintf(out, "\t\t(error) error item: %v\n", body.Err) + fmt.Fprintf(out, "[%d] 0x%s", pos, sum.Fmt(sb.Data.ChecksumType)) + pos = pos.Add(sectorSize) + } + fmt.Fprintf(out, "\n") + case btrfsitem.FileExtent: + fmt.Fprintf(out, "\t\tgeneration %v type %v\n", + body.Generation, body.Type) + switch body.Type { + case btrfsitem.FILE_EXTENT_INLINE: + fmt.Fprintf(out, "\t\tinline extent data size %v ram_bytes %v compression %v\n", + len(body.BodyInline), body.RAMBytes, body.Compression) + case btrfsitem.FILE_EXTENT_PREALLOC: + fmt.Fprintf(out, "\t\tprealloc data disk byte %v nr %v\n", + body.BodyExtent.DiskByteNr, + body.BodyExtent.DiskNumBytes) + fmt.Fprintf(out, "\t\tprealloc data offset %v nr %v\n", + body.BodyExtent.Offset, + body.BodyExtent.NumBytes) + case btrfsitem.FILE_EXTENT_REG: + fmt.Fprintf(out, "\t\textent data disk byte %d nr %d\n", + body.BodyExtent.DiskByteNr, + body.BodyExtent.DiskNumBytes) + fmt.Fprintf(out, "\t\textent data offset %d nr %d ram %v\n", + body.BodyExtent.Offset, + body.BodyExtent.NumBytes, + body.RAMBytes) + fmt.Fprintf(out, "\t\textent compression %v\n", + body.Compression) default: - fmt.Fprintf(out, "\t\t(error) unhandled item type: %T\n", body) + fmt.Fprintf(out, "\t\t(error) unknown file extent type %v", body.Type) } - return nil - }, + case btrfsitem.BlockGroup: + fmt.Fprintf(out, "\t\tblock group used %v chunk_objectid %v flags %v\n", + body.Used, body.ChunkObjectID, body.Flags) + case btrfsitem.FreeSpaceInfo: + fmt.Fprintf(out, "\t\tfree space info extent count %v flags %v\n", + body.ExtentCount, body.Flags) + case btrfsitem.FreeSpaceBitmap: + fmt.Fprintf(out, "\t\tfree space bitmap\n") + case btrfsitem.Chunk: + fmt.Fprintf(out, "\t\tlength %d owner %d stripe_len %v type %v\n", + body.Head.Size, body.Head.Owner, body.Head.StripeLen, body.Head.Type) + fmt.Fprintf(out, "\t\tio_align %v io_width %v sector_size %v\n", + body.Head.IOOptimalAlign, body.Head.IOOptimalWidth, body.Head.IOMinSize) + fmt.Fprintf(out, "\t\tnum_stripes %v sub_stripes %v\n", + body.Head.NumStripes, body.Head.SubStripes) + for i, stripe := range body.Stripes { + fmt.Fprintf(out, "\t\t\tstripe %v devid %d offset %d\n", + i, stripe.DeviceID, stripe.Offset) + fmt.Fprintf(out, "\t\t\tdev_uuid %v\n", + stripe.DeviceUUID) + } + case btrfsitem.Dev: + fmt.Fprintf(out, ""+ + "\t\tdevid %d total_bytes %v bytes_used %v\n"+ + "\t\tio_align %v io_width %v sector_size %v type %v\n"+ + "\t\tgeneration %v start_offset %v dev_group %v\n"+ + "\t\tseek_speed %v bandwidth %v\n"+ + "\t\tuuid %v\n"+ + "\t\tfsid %v\n", + body.DevID, body.NumBytes, body.NumBytesUsed, + body.IOOptimalAlign, body.IOOptimalWidth, body.IOMinSize, body.Type, + body.Generation, body.StartOffset, body.DevGroup, + body.SeekSpeed, body.Bandwidth, + body.DevUUID, + body.FSUUID) + case btrfsitem.DevExtent: + fmt.Fprintf(out, ""+ + "\t\tdev extent chunk_tree %v\n"+ + "\t\tchunk_objectid %v chunk_offset %d length %d\n"+ + "\t\tchunk_tree_uuid %v\n", + body.ChunkTree, body.ChunkObjectID, body.ChunkOffset, body.Length, + body.ChunkTreeUUID) + //case btrfsitem.QGROUP_STATUS_KEY: + // // TODO + //case btrfsitem.QGROUP_INFO_KEY: + // // TODO + //case btrfsitem.QGROUP_LIMIT_KEY: + // // TODO + case btrfsitem.UUIDMap: + fmt.Fprintf(out, "\t\tsubvol_id %d\n", body.ObjID) + //case btrfsitem.STRING_ITEM_KEY: + // // TODO + case btrfsitem.DevStats: + fmt.Fprintf(out, "\t\tpersistent item objectid %v offset %v\n", + item.Key.ObjectID.Format(item.Key.ItemType), item.Key.Offset) + switch item.Key.ObjectID { + case btrfs.DEV_STATS_OBJECTID: + fmt.Fprintf(out, "\t\tdevice stats\n") + fmt.Fprintf(out, "\t\twrite_errs %v read_errs %v flush_errs %v corruption_errs %v generation %v\n", + body.Values[btrfsitem.DEV_STAT_WRITE_ERRS], + body.Values[btrfsitem.DEV_STAT_READ_ERRS], + body.Values[btrfsitem.DEV_STAT_FLUSH_ERRS], + body.Values[btrfsitem.DEV_STAT_CORRUPTION_ERRS], + body.Values[btrfsitem.DEV_STAT_GENERATION_ERRS]) + default: + fmt.Fprintf(out, "\t\tunknown persistent item objectid %v\n", item.Key.ObjectID) + } + //case btrfsitem.TEMPORARY_ITEM_KEY: + // // TODO + case btrfsitem.Empty: + switch item.Key.ItemType { + case btrfsitem.ORPHAN_ITEM_KEY: // 48 + fmt.Fprintf(out, "\t\torphan item\n") + case btrfsitem.TREE_BLOCK_REF_KEY: // 176 + fmt.Fprintf(out, "\t\ttree block backref\n") + case btrfsitem.SHARED_BLOCK_REF_KEY: // 182 + fmt.Fprintf(out, "\t\tshared block backref\n") + case btrfsitem.FREE_SPACE_EXTENT_KEY: // 199 + fmt.Fprintf(out, "\t\tfree space extent\n") + case btrfsitem.QGROUP_RELATION_KEY: // 246 + // do nothing + //case btrfsitem.EXTENT_REF_V0_KEY: + // fmt.Fprintf(out, "\t\textent ref v0 (deprecated)\n") + //case btrfsitem.CSUM_ITEM_KEY: + // fmt.Fprintf(out, "\t\tcsum item\n") + default: + fmt.Fprintf(out, "\t\t(error) unhandled empty item type: %v\n", item.Key.ItemType) + } + case btrfsitem.Error: + fmt.Fprintf(out, "\t\t(error) error item: %v\n", body.Err) + default: + fmt.Fprintf(out, "\t\t(error) unhandled item type: %T\n", body) + } + return nil + }, + } + handlers.BadItem = handlers.Item + fs.TreeWalk( + treeID, + func(err *btrfs.TreeError) { + dlog.Error(ctx, err) }, + handlers, ) } |