summaryrefslogtreecommitdiff
path: root/lib/btrfs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/btrfs')
-rw-r--r--lib/btrfs/btrfstree/root.go23
-rw-r--r--lib/btrfs/csums.go16
-rw-r--r--lib/btrfs/io4_fs.go24
3 files changed, 38 insertions, 25 deletions
diff --git a/lib/btrfs/btrfstree/root.go b/lib/btrfs/btrfstree/root.go
index 12df0b2..6ec45b5 100644
--- a/lib/btrfs/btrfstree/root.go
+++ b/lib/btrfs/btrfstree/root.go
@@ -1,4 +1,4 @@
-// Copyright (C) 2022 Luke Shumaker <lukeshu@lukeshu.com>
+// Copyright (C) 2022-2023 Luke Shumaker <lukeshu@lukeshu.com>
//
// SPDX-License-Identifier: GPL-2.0-or-later
@@ -71,15 +71,18 @@ func LookupTreeRoot(fs TreeOperator, sb Superblock, treeID btrfsprim.ObjID) (*Tr
if err != nil {
return nil, err
}
- rootItemBody, ok := rootItem.Body.(btrfsitem.Root)
- if !ok {
- return nil, fmt.Errorf("malformed ROOT_ITEM for tree %v", treeID)
+ switch rootItemBody := rootItem.Body.(type) {
+ case btrfsitem.Root:
+ return &TreeRoot{
+ TreeID: treeID,
+ RootNode: rootItemBody.ByteNr,
+ Level: rootItemBody.Level,
+ Generation: rootItemBody.Generation,
+ }, nil
+ case btrfsitem.Error:
+ return nil, fmt.Errorf("malformed ROOT_ITEM for tree %v: %w", treeID, rootItemBody.Err)
+ default:
+ panic(fmt.Errorf("should not happen: ROOT_ITEM has unexpected item type: %T", rootItemBody))
}
- return &TreeRoot{
- TreeID: treeID,
- RootNode: rootItemBody.ByteNr,
- Level: rootItemBody.Level,
- Generation: rootItemBody.Generation,
- }, nil
}
}
diff --git a/lib/btrfs/csums.go b/lib/btrfs/csums.go
index bbd19bd..a32f090 100644
--- a/lib/btrfs/csums.go
+++ b/lib/btrfs/csums.go
@@ -1,4 +1,4 @@
-// Copyright (C) 2022 Luke Shumaker <lukeshu@lukeshu.com>
+// Copyright (C) 2022-2023 Luke Shumaker <lukeshu@lukeshu.com>
//
// SPDX-License-Identifier: GPL-2.0-or-later
@@ -56,9 +56,15 @@ func LookupCSum(fs btrfstree.TreeOperator, alg btrfssum.CSumType, laddr btrfsvol
if err != nil {
return btrfssum.SumRun[btrfsvol.LogicalAddr]{}, err
}
- body, ok := item.Body.(btrfsitem.ExtentCSum)
- if !ok {
- return btrfssum.SumRun[btrfsvol.LogicalAddr]{}, fmt.Errorf("item body is %T not ExtentCSum", item.Body)
+ if item.Key.ItemType != btrfsitem.EXTENT_CSUM_KEY {
+ return btrfssum.SumRun[btrfsvol.LogicalAddr]{}, fmt.Errorf("item type is %v, not EXTENT_CSUM", item.Key.ItemType)
+ }
+ switch body := item.Body.(type) {
+ case btrfsitem.ExtentCSum:
+ return body.SumRun, nil
+ case btrfsitem.Error:
+ return btrfssum.SumRun[btrfsvol.LogicalAddr]{}, body.Err
+ default:
+ panic(fmt.Errorf("should not happen: EXTENT_CSUM has unexpected item type: %T", body))
}
- return body.SumRun, nil
}
diff --git a/lib/btrfs/io4_fs.go b/lib/btrfs/io4_fs.go
index d7c2770..d9c7cdb 100644
--- a/lib/btrfs/io4_fs.go
+++ b/lib/btrfs/io4_fs.go
@@ -87,13 +87,15 @@ func (sv *Subvolume) init() {
return
}
- rootBody, ok := root.Body.(btrfsitem.Root)
- if !ok {
- sv.rootErr = fmt.Errorf("FS_TREE ROOT_ITEM has malformed body")
- return
+ switch rootBody := root.Body.(type) {
+ case btrfsitem.Root:
+ sv.rootVal = rootBody
+ case btrfsitem.Error:
+ sv.rootErr = fmt.Errorf("FS_TREE ROOT_ITEM has malformed body: %w", rootBody.Err)
+ default:
+ panic(fmt.Errorf("should not happen: ROOT_ITEM has unexpected item type: %T", rootBody))
}
- sv.rootVal = rootBody
})
}
@@ -117,12 +119,14 @@ func (sv *Subvolume) LoadBareInode(inode btrfsprim.ObjID) (*BareInode, error) {
return
}
- itemBody, ok := item.Body.(btrfsitem.Inode)
- if !ok {
- val.Errs = append(val.Errs, fmt.Errorf("malformed inode"))
- return
+ switch itemBody := item.Body.(type) {
+ case btrfsitem.Inode:
+ val.InodeItem = &itemBody
+ case btrfsitem.Error:
+ val.Errs = append(val.Errs, fmt.Errorf("malformed inode: %w", itemBody.Err))
+ default:
+ panic(fmt.Errorf("should not happen: INODE_ITEM has unexpected item type: %T", itemBody))
}
- val.InodeItem = &itemBody
return
})