diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2023-01-01 22:43:58 -0700 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2023-01-01 22:43:58 -0700 |
commit | d675f41242c043ddc4c6c1a1fb8aabcfd324aae2 (patch) | |
tree | 4f2afbce761eb377ad0b0ab2e4fb2f478ff844f5 /lib/btrfs/btrfstree/root.go | |
parent | 9971e38110d5f90d15c7b78f396f2638b3952a96 (diff) | |
parent | 6e1a9fbb1e9a943e04902ed3a4958f6821e39456 (diff) |
Merge branch 'lukeshu/lint'
Diffstat (limited to 'lib/btrfs/btrfstree/root.go')
-rw-r--r-- | lib/btrfs/btrfstree/root.go | 23 |
1 files changed, 13 insertions, 10 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 } } |