summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2022-06-04 22:53:09 -0600
committerLuke Shumaker <lukeshu@lukeshu.com>2022-06-04 22:53:09 -0600
commit67aab484a523dfcbf32f4fc68ace2474ade96a5f (patch)
tree64093a2d351b1b3c4a4b1612e39ee9de8a2bc7c4
parent02fccc8c29d6f638efee0302868242d805bd7711 (diff)
more
-rw-r--r--cmd/btrfs-dump-tree/main.go33
-rw-r--r--pkg/btrfs/btrfsitem/item_blockgroup.go38
-rw-r--r--pkg/btrfs/btrfsitem/item_chunk.go18
3 files changed, 74 insertions, 15 deletions
diff --git a/cmd/btrfs-dump-tree/main.go b/cmd/btrfs-dump-tree/main.go
index 195d001..b87778b 100644
--- a/cmd/btrfs-dump-tree/main.go
+++ b/cmd/btrfs-dump-tree/main.go
@@ -118,8 +118,6 @@ func printTree(fs *btrfs.FS, root btrfs.LogicalAddr) error {
item.Head.DataOffset,
item.Head.DataSize)
switch body := item.Body.(type) {
- //case btrfsitem.UNTYPED_KEY:
- // // TODO
case btrfsitem.Inode:
fmt.Printf(""+
"\t\tgeneration %d transid %d size %d nbytes %d\n"+
@@ -204,10 +202,33 @@ func printTree(fs *btrfs.FS, root btrfs.LogicalAddr) error {
// fmt.Printf("\t\tfree space extent\n")
//case btrfsitem.FREE_SPACE_BITMAP_KEY:
// fmt.Printf("\t\tfree space bitmap\n")
- //case btrfsitem.CHUNK_ITEM_KEY:
- // // TODO(!)
- //case btrfsitem.DEV_ITEM_KEY:
- // // TODO
+ case btrfsitem.Chunk:
+ fmt.Printf("\t\tlength %d owner %d stripe_len %d type %v\n",
+ body.Size, body.Owner, body.StripeLen, body.Type)
+ fmt.Printf("\t\tio_align %d io_width %d sector_size %d\n",
+ body.IOOptimalAlign, body.IOOptimalWidth, body.IOMinSize)
+ fmt.Printf("\t\tnum_stripes %d sub_stripes %d\n",
+ body.NumStripes, body.SubStripes)
+ for i, stripe := range body.Stripes {
+ fmt.Printf("\t\t\tstripe %d devid %d offset %d\n",
+ i, stripe.DeviceID, stripe.Offset)
+ fmt.Printf("\t\t\tdev_uuid %s\n",
+ stripe.DeviceUUID)
+ }
+ case btrfsitem.Dev:
+ fmt.Printf(""+
+ "\t\tdevid %d total_bytes %d bytes_used %d\n"+
+ "\t\tio_align %d io_width %d sector_size %d type %d\n"+
+ "\t\tgeneration %d start_offset %d dev_group %d\n"+
+ "\t\tseek_speed %d bandwidth %d\n"+
+ "\t\tuuid %s\n"+
+ "\t\tfsid %s\n",
+ body.DeviceID, 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.DEV_EXTENT_KEY:
// // TODO
//case btrfsitem.QGROUP_STATUS_KEY:
diff --git a/pkg/btrfs/btrfsitem/item_blockgroup.go b/pkg/btrfs/btrfsitem/item_blockgroup.go
new file mode 100644
index 0000000..162adb1
--- /dev/null
+++ b/pkg/btrfs/btrfsitem/item_blockgroup.go
@@ -0,0 +1,38 @@
+package btrfsitem
+
+import (
+ "lukeshu.com/btrfs-tools/pkg/util"
+)
+
+type BlockGroupFlags uint64
+
+const (
+ BLOCK_GROUP_DATA = BlockGroupFlags(1 << iota)
+ BLOCK_GROUP_SYSTEM
+ BLOCK_GROUP_METADATA
+ BLOCK_GROUP_RAID0
+ BLOCK_GROUP_RAID1
+ BLOCK_GROUP_DUP
+ BLOCK_GROUP_RAID10
+ BLOCK_GROUP_RAID5
+ BLOCK_GROUP_RAID6
+ BLOCK_GROUP_RAID1C3
+ BLOCK_GROUP_RAID1C4
+)
+
+var blockGroupFlagNames = []string{
+ "DATA",
+ "SYSTEM",
+ "METADATA",
+ "RAID0",
+ "RAID1",
+ "DUP",
+ "RAID10",
+ "RAID5",
+ "RAID6",
+ "RAID1C3",
+ "RAID1C4",
+}
+
+func (f BlockGroupFlags) Has(req BlockGroupFlags) bool { return f&req == req }
+func (f BlockGroupFlags) String() string { return util.BitfieldString(f, blockGroupFlagNames) }
diff --git a/pkg/btrfs/btrfsitem/item_chunk.go b/pkg/btrfs/btrfsitem/item_chunk.go
index 7bb65b1..826ecc6 100644
--- a/pkg/btrfs/btrfsitem/item_chunk.go
+++ b/pkg/btrfs/btrfsitem/item_chunk.go
@@ -9,15 +9,15 @@ import (
type Chunk struct { // CHUNK_ITEM=228
// Maps logical address to physical.
- Size uint64 `bin:"off=0x0, siz=0x8"` // size of chunk (bytes)
- Owner internal.ObjID `bin:"off=0x8, siz=0x8"` // root referencing this chunk (2)
- StripeLen uint64 `bin:"off=0x10, siz=0x8"` // stripe length
- Type uint64 `bin:"off=0x18, siz=0x8"` // type (same as flags for block group?)
- IOOptimalAlign uint32 `bin:"off=0x20, siz=0x4"` // optimal io alignment
- IOOptimalWidth uint32 `bin:"off=0x24, siz=0x4"` // optimal io width
- IoMinSize uint32 `bin:"off=0x28, siz=0x4"` // minimal io size (sector size)
- NumStripes uint16 `bin:"off=0x2c, siz=0x2"` // number of stripes
- SubStripes uint16 `bin:"off=0x2e, siz=0x2"` // sub stripes
+ Size uint64 `bin:"off=0x0, siz=0x8"` // size of chunk (bytes)
+ Owner internal.ObjID `bin:"off=0x8, siz=0x8"` // root referencing this chunk (2)
+ StripeLen uint64 `bin:"off=0x10, siz=0x8"` // stripe length
+ Type BlockGroupFlags `bin:"off=0x18, siz=0x8"` // type (same as flags for block group?)
+ IOOptimalAlign uint32 `bin:"off=0x20, siz=0x4"` // optimal io alignment
+ IOOptimalWidth uint32 `bin:"off=0x24, siz=0x4"` // optimal io width
+ IOMinSize uint32 `bin:"off=0x28, siz=0x4"` // minimal io size (sector size)
+ NumStripes uint16 `bin:"off=0x2c, siz=0x2"` // number of stripes
+ SubStripes uint16 `bin:"off=0x2e, siz=0x2"` // sub stripes
binstruct.End `bin:"off=0x30"`
Stripes []ChunkStripe `bin:"-"`
}