summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2022-06-05 11:15:55 -0600
committerLuke Shumaker <lukeshu@lukeshu.com>2022-06-05 11:15:55 -0600
commitb6c0f9893cf69eac1608e769b97fa5fe247af3b8 (patch)
treece2745d099dab04dc9dbfa9b0bb63633331e5ca5
parent65fe72e1daf67d0c9ca3e460e6ec72e0e4a948fe (diff)
more
# Conflicts: # pkg/btrfs/btrfsitem/items.txt # pkg/btrfs/btrfsitem/items_gen.go # pkg/btrfs/internal/itemtype.go
-rw-r--r--cmd/btrfs-dump-tree/main.go35
-rw-r--r--pkg/btrfs/btrfsitem/item_empty.go2
-rw-r--r--pkg/btrfs/btrfsitem/item_freespacebitmap.go12
-rw-r--r--pkg/btrfs/btrfsitem/item_freespaceinfo.go11
-rw-r--r--pkg/btrfs/btrfsitem/item_orphan.go9
-rw-r--r--pkg/btrfs/btrfsitem/items.txt5
-rw-r--r--pkg/btrfs/btrfsitem/items_gen.go41
-rw-r--r--pkg/btrfs/internal/itemtype.go6
8 files changed, 77 insertions, 44 deletions
diff --git a/cmd/btrfs-dump-tree/main.go b/cmd/btrfs-dump-tree/main.go
index d96170b..2428a6c 100644
--- a/cmd/btrfs-dump-tree/main.go
+++ b/cmd/btrfs-dump-tree/main.go
@@ -211,18 +211,10 @@ func printTree(fs *btrfs.FS, root btrfs.LogicalAddr) error {
body.Head.Refs, body.Head.Generation, body.Head.Flags)
fmt.Printf("\t\ttree block skinny level %d\n", item.Head.Key.Offset)
printExtentInlineRefs(body.Refs)
- //case btrfsitem.TREE_BLOCK_REF_KEY:
- // fmt.Printf("\t\ttree block backref\n")
- //case btrfsitem.SHARED_BLOCK_REF_KEY:
- // fmt.Printf("\t\tshared block backref\n")
//case btrfsitem.EXTENT_DATA_REF_KEY:
// // TODO
//case btrfsitem.SHARED_DATA_REF_KEY:
// // TODO
- //case btrfsitem.EXTENT_REF_V0_KEY:
- // fmt.Printf("\t\textent ref v0 (deprecated)\n")
- //case btrfsitem.CSUM_ITEM_KEY:
- // fmt.Printf("\t\tcsum item\n")
//case btrfsitem.EXTENT_CSUM_KEY:
// // TODO
//case btrfsitem.EXTENT_DATA_KEY:
@@ -230,12 +222,11 @@ func printTree(fs *btrfs.FS, root btrfs.LogicalAddr) error {
case btrfsitem.BlockGroup:
fmt.Printf("\t\tblock group used %d chunk_objectid %d flags %v\n",
body.Used, body.ChunkObjectID, body.Flags)
- //case btrfsitem.FREE_SPACE_INFO_KEY:
- // // TODO
- //case btrfsitem.FREE_SPACE_EXTENT_KEY:
- // fmt.Printf("\t\tfree space extent\n")
- //case btrfsitem.FREE_SPACE_BITMAP_KEY:
- // fmt.Printf("\t\tfree space bitmap\n")
+ case btrfsitem.FreeSpaceInfo:
+ fmt.Printf("\t\tfree space info extent count %d flags %d\n",
+ body.ExtentCount, body.Flags)
+ case btrfsitem.FreeSpaceBitmap:
+ fmt.Printf("\t\tfree space bitmap\n")
case btrfsitem.Chunk:
fmt.Printf("\t\tlength %d owner %d stripe_len %d type %v\n",
body.Size, body.Owner, body.StripeLen, body.Type)
@@ -272,7 +263,7 @@ func printTree(fs *btrfs.FS, root btrfs.LogicalAddr) error {
body.ChunkTreeUUID)
//case btrfsitem.QGROUP_STATUS_KEY:
// // TODO
- //case btrfsitem.QGROUP_RELATION_KEY, btrfsitem.QGROUP_INFO_KEY:
+ //case btrfsitem.QGROUP_INFO_KEY:
// // TODO
//case btrfsitem.QGROUP_LIMIT_KEY:
// // TODO
@@ -302,8 +293,20 @@ func printTree(fs *btrfs.FS, root btrfs.LogicalAddr) error {
// // TODO
case btrfsitem.Empty:
switch item.Head.Key.ItemType {
- case btrfsitem.ORPHAN_ITEM_KEY:
+ case btrfsitem.ORPHAN_ITEM_KEY: // 48
fmt.Printf("\t\torphan item\n")
+ case btrfsitem.TREE_BLOCK_REF_KEY: // 176
+ fmt.Printf("\t\ttree block backref\n")
+ case btrfsitem.SHARED_BLOCK_REF_KEY: // 182
+ fmt.Printf("\t\tshared block backref\n")
+ case btrfsitem.FREE_SPACE_EXTENT_KEY: // 199
+ fmt.Printf("\t\tfree space extent\n")
+ case btrfsitem.QGROUP_RELATION_KEY: // 246
+ // do nothing
+ //case btrfsitem.EXTENT_REF_V0_KEY:
+ // fmt.Printf("\t\textent ref v0 (deprecated)\n")
+ //case btrfsitem.CSUM_ITEM_KEY:
+ // fmt.Printf("\t\tcsum item\n")
default:
fmt.Printf("\t\t(error) unhandled empty item type: %v\n", item.Head.Key.ItemType)
}
diff --git a/pkg/btrfs/btrfsitem/item_empty.go b/pkg/btrfs/btrfsitem/item_empty.go
index 5a26104..db7053f 100644
--- a/pkg/btrfs/btrfsitem/item_empty.go
+++ b/pkg/btrfs/btrfsitem/item_empty.go
@@ -4,6 +4,6 @@ import (
"lukeshu.com/btrfs-tools/pkg/binstruct"
)
-type Empty struct { // UNTYPED=0, TREE_BLOCK_REF=176, SHARED_BLOCK_REF=182, QGROUP_RELATION=246
+type Empty struct { // UNTYPED=0, ORPHAN_ITEM=48, TREE_BLOCK_REF=176, SHARED_BLOCK_REF=182, FREE_SPACE_EXTENT=199, QGROUP_RELATION=246
binstruct.End `bin:"off=0"`
}
diff --git a/pkg/btrfs/btrfsitem/item_freespacebitmap.go b/pkg/btrfs/btrfsitem/item_freespacebitmap.go
new file mode 100644
index 0000000..6158eb0
--- /dev/null
+++ b/pkg/btrfs/btrfsitem/item_freespacebitmap.go
@@ -0,0 +1,12 @@
+package btrfsitem
+
+type FreeSpaceBitmap []byte // FREE_SPACE_BITMAP=200
+
+func (o *FreeSpaceBitmap) UnmarshalBinary(dat []byte) (int, error) {
+ *o = dat
+ return len(dat), nil
+}
+
+func (o FreeSpaceBitmap) MarshalBinary() ([]byte, error) {
+ return []byte(o), nil
+}
diff --git a/pkg/btrfs/btrfsitem/item_freespaceinfo.go b/pkg/btrfs/btrfsitem/item_freespaceinfo.go
new file mode 100644
index 0000000..4931844
--- /dev/null
+++ b/pkg/btrfs/btrfsitem/item_freespaceinfo.go
@@ -0,0 +1,11 @@
+package btrfsitem
+
+import (
+ "lukeshu.com/btrfs-tools/pkg/binstruct"
+)
+
+type FreeSpaceInfo struct { // FREE_SPACE_INFO=198
+ ExtentCount int32 `bin:"off=0, siz=4"`
+ Flags uint32 `bin:"off=4, siz=4"`
+ binstruct.End `bin:"off=8"`
+}
diff --git a/pkg/btrfs/btrfsitem/item_orphan.go b/pkg/btrfs/btrfsitem/item_orphan.go
deleted file mode 100644
index 6cf29b0..0000000
--- a/pkg/btrfs/btrfsitem/item_orphan.go
+++ /dev/null
@@ -1,9 +0,0 @@
-package btrfsitem
-
-import (
- "lukeshu.com/btrfs-tools/pkg/binstruct"
-)
-
-type Orphan struct { // ORPHAN_ITEM=48
- binstruct.End `bin:"off=0"`
-}
diff --git a/pkg/btrfs/btrfsitem/items.txt b/pkg/btrfs/btrfsitem/items.txt
index e713a80..73bdbe8 100644
--- a/pkg/btrfs/btrfsitem/items.txt
+++ b/pkg/btrfs/btrfsitem/items.txt
@@ -6,10 +6,13 @@ DIR_INDEX=96, DirList
DIR_ITEM=84, DirList
EXTENT_DATA_REF=178 ExtentDataRef
EXTENT_ITEM=168 Extent
+FREE_SPACE_BITMAP=200 FreeSpaceBitmap
+FREE_SPACE_EXTENT=199, Empty
+FREE_SPACE_INFO=198 FreeSpaceInfo
INODE_ITEM=1 Inode
INODE_REF=12 InodeRefList
METADATA_ITEM=169 Metadata
-ORPHAN_ITEM=48 Orphan
+ORPHAN_ITEM=48, Empty
PERSISTENT_ITEM=249 DevStats
QGROUP_RELATION=246 Empty
ROOT_ITEM=132 Root
diff --git a/pkg/btrfs/btrfsitem/items_gen.go b/pkg/btrfs/btrfsitem/items_gen.go
index 063c2e7..27fc5c2 100644
--- a/pkg/btrfs/btrfsitem/items_gen.go
+++ b/pkg/btrfs/btrfsitem/items_gen.go
@@ -17,6 +17,9 @@ const (
DIR_ITEM_KEY = internal.DIR_ITEM_KEY
EXTENT_DATA_REF_KEY = internal.EXTENT_DATA_REF_KEY
EXTENT_ITEM_KEY = internal.EXTENT_ITEM_KEY
+ FREE_SPACE_BITMAP_KEY = internal.FREE_SPACE_BITMAP_KEY
+ FREE_SPACE_EXTENT_KEY = internal.FREE_SPACE_EXTENT_KEY
+ FREE_SPACE_INFO_KEY = internal.FREE_SPACE_INFO_KEY
INODE_ITEM_KEY = internal.INODE_ITEM_KEY
INODE_REF_KEY = internal.INODE_REF_KEY
METADATA_ITEM_KEY = internal.METADATA_ITEM_KEY
@@ -42,10 +45,13 @@ var keytype2gotype = map[Type]reflect.Type{
DIR_ITEM_KEY: reflect.TypeOf(DirList{}),
EXTENT_DATA_REF_KEY: reflect.TypeOf(ExtentDataRef{}),
EXTENT_ITEM_KEY: reflect.TypeOf(Extent{}),
+ FREE_SPACE_BITMAP_KEY: reflect.TypeOf(FreeSpaceBitmap{}),
+ FREE_SPACE_EXTENT_KEY: reflect.TypeOf(Empty{}),
+ FREE_SPACE_INFO_KEY: reflect.TypeOf(FreeSpaceInfo{}),
INODE_ITEM_KEY: reflect.TypeOf(Inode{}),
INODE_REF_KEY: reflect.TypeOf(InodeRefList{}),
METADATA_ITEM_KEY: reflect.TypeOf(Metadata{}),
- ORPHAN_ITEM_KEY: reflect.TypeOf(Orphan{}),
+ ORPHAN_ITEM_KEY: reflect.TypeOf(Empty{}),
PERSISTENT_ITEM_KEY: reflect.TypeOf(DevStats{}),
QGROUP_RELATION_KEY: reflect.TypeOf(Empty{}),
ROOT_ITEM_KEY: reflect.TypeOf(Root{}),
@@ -58,19 +64,20 @@ var keytype2gotype = map[Type]reflect.Type{
XATTR_ITEM_KEY: reflect.TypeOf(DirList{}),
}
-func (BlockGroup) isItem() {}
-func (Chunk) isItem() {}
-func (Dev) isItem() {}
-func (DevExtent) isItem() {}
-func (DevStats) isItem() {}
-func (DirList) isItem() {}
-func (Empty) isItem() {}
-func (Extent) isItem() {}
-func (ExtentDataRef) isItem() {}
-func (Inode) isItem() {}
-func (InodeRefList) isItem() {}
-func (Metadata) isItem() {}
-func (Orphan) isItem() {}
-func (Root) isItem() {}
-func (SharedDataRef) isItem() {}
-func (UUIDMap) isItem() {}
+func (BlockGroup) isItem() {}
+func (Chunk) isItem() {}
+func (Dev) isItem() {}
+func (DevExtent) isItem() {}
+func (DevStats) isItem() {}
+func (DirList) isItem() {}
+func (Empty) isItem() {}
+func (Extent) isItem() {}
+func (ExtentDataRef) isItem() {}
+func (FreeSpaceBitmap) isItem() {}
+func (FreeSpaceInfo) isItem() {}
+func (Inode) isItem() {}
+func (InodeRefList) isItem() {}
+func (Metadata) isItem() {}
+func (Root) isItem() {}
+func (SharedDataRef) isItem() {}
+func (UUIDMap) isItem() {}
diff --git a/pkg/btrfs/internal/itemtype.go b/pkg/btrfs/internal/itemtype.go
index cc38d94..aa6e4f9 100644
--- a/pkg/btrfs/internal/itemtype.go
+++ b/pkg/btrfs/internal/itemtype.go
@@ -15,6 +15,9 @@ const (
DIR_ITEM_KEY = ItemType(84)
EXTENT_DATA_REF_KEY = ItemType(178)
EXTENT_ITEM_KEY = ItemType(168)
+ FREE_SPACE_BITMAP_KEY = ItemType(200)
+ FREE_SPACE_EXTENT_KEY = ItemType(199)
+ FREE_SPACE_INFO_KEY = ItemType(198)
INODE_ITEM_KEY = ItemType(1)
INODE_REF_KEY = ItemType(12)
METADATA_ITEM_KEY = ItemType(169)
@@ -41,6 +44,9 @@ func (t ItemType) String() string {
DIR_ITEM_KEY: "DIR_ITEM",
EXTENT_DATA_REF_KEY: "EXTENT_DATA_REF",
EXTENT_ITEM_KEY: "EXTENT_ITEM",
+ FREE_SPACE_BITMAP_KEY: "FREE_SPACE_BITMAP",
+ FREE_SPACE_EXTENT_KEY: "FREE_SPACE_EXTENT",
+ FREE_SPACE_INFO_KEY: "FREE_SPACE_INFO",
INODE_ITEM_KEY: "INODE_ITEM",
INODE_REF_KEY: "INODE_REF",
METADATA_ITEM_KEY: "METADATA_ITEM",