diff options
Diffstat (limited to 'lib/btrfs')
-rw-r--r-- | lib/btrfs/io2_lv.go | 4 | ||||
-rw-r--r-- | lib/btrfs/io3_btree.go | 6 | ||||
-rw-r--r-- | lib/btrfs/io4_fs.go | 20 | ||||
-rw-r--r-- | lib/btrfs/types_node.go | 28 |
4 files changed, 31 insertions, 27 deletions
diff --git a/lib/btrfs/io2_lv.go b/lib/btrfs/io2_lv.go index aac902b..b36796b 100644 --- a/lib/btrfs/io2_lv.go +++ b/lib/btrfs/io2_lv.go @@ -166,10 +166,10 @@ func (fs *FS) initDev(sb *util.Ref[btrfsvol.PhysicalAddr, Superblock]) error { }, TreeWalkHandler{ Item: func(_ TreePath, item Item) error { - if item.Head.Key.ItemType != btrfsitem.CHUNK_ITEM_KEY { + if item.Key.ItemType != btrfsitem.CHUNK_ITEM_KEY { return nil } - for _, mapping := range item.Body.(btrfsitem.Chunk).Mappings(item.Head.Key) { + for _, mapping := range item.Body.(btrfsitem.Chunk).Mappings(item.Key) { if err := fs.LV.AddMapping(mapping); err != nil { return err } diff --git a/lib/btrfs/io3_btree.go b/lib/btrfs/io3_btree.go index 14419fe..759e378 100644 --- a/lib/btrfs/io3_btree.go +++ b/lib/btrfs/io3_btree.go @@ -367,7 +367,7 @@ func (fs *FS) treeSearch(treeRoot treeRoot, fn func(Key) int) (TreePath, *util.R end := len(node.Data.BodyLeaf) for beg < end { midpoint := (beg + end) / 2 - direction := fn(node.Data.BodyLeaf[midpoint].Head.Key) + direction := fn(node.Data.BodyLeaf[midpoint].Key) switch { case direction < 0: end = midpoint @@ -551,7 +551,7 @@ func (fs *FS) TreeSearchAll(treeID ObjID, fn func(Key) int) ([]Item, error) { break } prevItem := prevNode.Data.BodyLeaf[prevPath.Nodes[len(prevPath.Nodes)-1].ItemIdx] - if fn(prevItem.Head.Key) != 0 { + if fn(prevItem.Key) != 0 { break } ret = append(ret, prevItem) @@ -567,7 +567,7 @@ func (fs *FS) TreeSearchAll(treeID ObjID, fn func(Key) int) ([]Item, error) { break } nextItem := nextNode.Data.BodyLeaf[nextPath.Nodes[len(nextPath.Nodes)-1].ItemIdx] - if fn(nextItem.Head.Key) != 0 { + if fn(nextItem.Key) != 0 { break } ret = append(ret, nextItem) diff --git a/lib/btrfs/io4_fs.go b/lib/btrfs/io4_fs.go index 3099aca..02f1969 100644 --- a/lib/btrfs/io4_fs.go +++ b/lib/btrfs/io4_fs.go @@ -142,7 +142,7 @@ func (sv *Subvolume) LoadFullInode(inode ObjID) (*FullInode, error) { } } for _, item := range items { - switch item.Head.Key.ItemType { + switch item.Key.ItemType { case btrfsitem.INODE_ITEM_KEY: itemBody := item.Body.(btrfsitem.Inode) if val.InodeItem != nil { @@ -187,10 +187,10 @@ func (ret *Dir) populate() { ret.ChildrenByName = make(map[string]btrfsitem.DirEntry) ret.ChildrenByIndex = make(map[uint64]btrfsitem.DirEntry) for _, item := range ret.OtherItems { - switch item.Head.Key.ItemType { + switch item.Key.ItemType { case btrfsitem.INODE_REF_KEY: ref := InodeRef{ - Inode: ObjID(item.Head.Key.Offset), + Inode: ObjID(item.Key.Offset), InodeRef: item.Body.(btrfsitem.InodeRef), } if ret.DotDot != nil { @@ -203,9 +203,9 @@ func (ret *Dir) populate() { case btrfsitem.DIR_ITEM_KEY: entry := item.Body.(btrfsitem.DirEntry) namehash := btrfsitem.NameHash(entry.Name) - if namehash != item.Head.Key.Offset { + if namehash != item.Key.Offset { ret.Errs = append(ret.Errs, fmt.Errorf("direntry crc32c mismatch: key=%#x crc32c(%q)=%#x", - item.Head.Key.Offset, entry.Name, namehash)) + item.Key.Offset, entry.Name, namehash)) continue } if other, exists := ret.ChildrenByName[string(entry.Name)]; exists { @@ -216,7 +216,7 @@ func (ret *Dir) populate() { } ret.ChildrenByName[string(entry.Name)] = entry case btrfsitem.DIR_INDEX_KEY: - index := item.Head.Key.Offset + index := item.Key.Offset entry := item.Body.(btrfsitem.DirEntry) if other, exists := ret.ChildrenByIndex[index]; exists { if !reflect.DeepEqual(entry, other) { @@ -227,7 +227,7 @@ func (ret *Dir) populate() { ret.ChildrenByIndex[index] = entry //case btrfsitem.XATTR_ITEM_KEY: default: - panic(fmt.Errorf("TODO: handle item type %v", item.Head.Key.ItemType)) + panic(fmt.Errorf("TODO: handle item type %v", item.Key.ItemType)) } } entriesWithIndexes := make(map[string]struct{}) @@ -297,16 +297,16 @@ func (sv *Subvolume) LoadFile(inode ObjID) (*File, error) { func (ret *File) populate() { for _, item := range ret.OtherItems { - switch item.Head.Key.ItemType { + switch item.Key.ItemType { case btrfsitem.INODE_REF_KEY: // TODO case btrfsitem.EXTENT_DATA_KEY: ret.Extents = append(ret.Extents, FileExtent{ - OffsetWithinFile: int64(item.Head.Key.Offset), + OffsetWithinFile: int64(item.Key.Offset), FileExtent: item.Body.(btrfsitem.FileExtent), }) default: - panic(fmt.Errorf("TODO: handle item type %v", item.Head.Key.ItemType)) + panic(fmt.Errorf("TODO: handle item type %v", item.Key.ItemType)) } } diff --git a/lib/btrfs/types_node.go b/lib/btrfs/types_node.go index f425460..34151c9 100644 --- a/lib/btrfs/types_node.go +++ b/lib/btrfs/types_node.go @@ -246,7 +246,7 @@ func (node *Node) marshalInternalTo(bodyBuf []byte) error { // Node: "leaf" //////////////////////////////////////////////////////////////////////////////////// type Item struct { - Head ItemHeader + Key Key Body btrfsitem.Item } @@ -261,9 +261,8 @@ func (node *Node) unmarshalLeaf(bodyBuf []byte) (int, error) { head := 0 tail := len(bodyBuf) for i := uint32(0); i < node.Head.NumItems; i++ { - var item Item - - n, err := binstruct.Unmarshal(bodyBuf[head:], &item.Head) + var itemHead ItemHeader + n, err := binstruct.Unmarshal(bodyBuf[head:], &itemHead) head += n if err != nil { return 0, fmt.Errorf("item %v: head: %w", i, err) @@ -273,21 +272,23 @@ func (node *Node) unmarshalLeaf(bodyBuf []byte) (int, error) { i, head, tail) } - dataOff := int(item.Head.DataOffset) + dataOff := int(itemHead.DataOffset) if dataOff < head { return 0, fmt.Errorf("item %v: body: beg_offset=%#x is in the head section (offset<%#x)", i, dataOff, head) } - dataSize := int(item.Head.DataSize) + dataSize := int(itemHead.DataSize) if dataOff+dataSize != tail { return 0, fmt.Errorf("item %v: body: end_offset=%#x is not cur_tail=%#x)", i, dataOff+dataSize, tail) } tail = dataOff dataBuf := bodyBuf[dataOff : dataOff+dataSize] - item.Body = btrfsitem.UnmarshalItem(item.Head.Key, node.ChecksumType, dataBuf) - node.BodyLeaf = append(node.BodyLeaf, item) + node.BodyLeaf = append(node.BodyLeaf, Item{ + Key: itemHead.Key, + Body: btrfsitem.UnmarshalItem(itemHead.Key, node.ChecksumType, dataBuf), + }) } node.Padding = bodyBuf[head:tail] @@ -302,9 +303,11 @@ func (node *Node) marshalLeafTo(bodyBuf []byte) error { if err != nil { return fmt.Errorf("item %v: body: %w", i, err) } - item.Head.DataSize = uint32(len(itemBodyBuf)) - item.Head.DataOffset = uint32(tail - len(itemBodyBuf)) - itemHeadBuf, err := binstruct.Marshal(item.Head) + itemHeadBuf, err := binstruct.Marshal(ItemHeader{ + Key: item.Key, + DataSize: uint32(len(itemBodyBuf)), + DataOffset: uint32(tail - len(itemBodyBuf)), + }) if err != nil { return fmt.Errorf("item %v: head: %w", i, err) } @@ -334,7 +337,8 @@ func (node *Node) LeafFreeSpace() uint32 { freeSpace -= uint32(binstruct.StaticSize(NodeHeader{})) for _, item := range node.BodyLeaf { freeSpace -= uint32(binstruct.StaticSize(ItemHeader{})) - freeSpace -= item.Head.DataSize + bs, _ := binstruct.Marshal(item.Body) + freeSpace -= uint32(len(bs)) } return freeSpace } |