summaryrefslogtreecommitdiff
path: root/lib/btrfs
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2023-01-01 22:13:14 -0700
committerLuke Shumaker <lukeshu@lukeshu.com>2023-01-01 22:42:08 -0700
commit6912dad34102be1ddea5f3b7710abd0cc8922d20 (patch)
tree95f0cff06e50203b9b36863ffc32d512603cd1a4 /lib/btrfs
parent0c706b6ad52776430ac15cf0e286dd473091d93e (diff)
lint: Turn on stylecheck
Diffstat (limited to 'lib/btrfs')
-rw-r--r--lib/btrfs/btrfsprim/misc.go6
-rw-r--r--lib/btrfs/io4_fs.go90
2 files changed, 48 insertions, 48 deletions
diff --git a/lib/btrfs/btrfsprim/misc.go b/lib/btrfs/btrfsprim/misc.go
index 9b3a6f8..22939bf 100644
--- a/lib/btrfs/btrfsprim/misc.go
+++ b/lib/btrfs/btrfsprim/misc.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
@@ -22,8 +22,8 @@ type Key struct {
binstruct.End `bin:"off=0x11"`
}
-func (k Key) String() string {
- return fmt.Sprintf("{%v %v %v}", k.ObjectID, k.ItemType, k.Offset)
+func (key Key) String() string {
+ return fmt.Sprintf("{%v %v %v}", key.ObjectID, key.ItemType, key.Offset)
}
var MaxKey = Key{
diff --git a/lib/btrfs/io4_fs.go b/lib/btrfs/io4_fs.go
index 41df3a8..799c865 100644
--- a/lib/btrfs/io4_fs.go
+++ b/lib/btrfs/io4_fs.go
@@ -218,16 +218,16 @@ func (sv *Subvolume) LoadDir(inode btrfsprim.ObjID) (*Dir, error) {
return val, nil
}
-func (ret *Dir) populate() {
- ret.ChildrenByName = make(map[string]btrfsitem.DirEntry)
- ret.ChildrenByIndex = make(map[uint64]btrfsitem.DirEntry)
- for _, item := range ret.OtherItems {
+func (dir *Dir) populate() {
+ dir.ChildrenByName = make(map[string]btrfsitem.DirEntry)
+ dir.ChildrenByIndex = make(map[uint64]btrfsitem.DirEntry)
+ for _, item := range dir.OtherItems {
switch item.Key.ItemType {
case btrfsitem.INODE_REF_KEY:
switch body := item.Body.(type) {
case btrfsitem.InodeRefs:
if len(body) != 1 {
- ret.Errs = append(ret.Errs, fmt.Errorf("INODE_REF item with %d entries on a directory",
+ dir.Errs = append(dir.Errs, fmt.Errorf("INODE_REF item with %d entries on a directory",
len(body)))
continue
}
@@ -235,15 +235,15 @@ func (ret *Dir) populate() {
Inode: btrfsprim.ObjID(item.Key.Offset),
InodeRef: body[0],
}
- if ret.DotDot != nil {
- if !reflect.DeepEqual(ref, *ret.DotDot) {
- ret.Errs = append(ret.Errs, fmt.Errorf("multiple INODE_REF items on a directory"))
+ if dir.DotDot != nil {
+ if !reflect.DeepEqual(ref, *dir.DotDot) {
+ dir.Errs = append(dir.Errs, fmt.Errorf("multiple INODE_REF items on a directory"))
}
continue
}
- ret.DotDot = &ref
+ dir.DotDot = &ref
case btrfsitem.Error:
- ret.Errs = append(ret.Errs, fmt.Errorf("malformed INODE_REF: %w", body.Err))
+ dir.Errs = append(dir.Errs, fmt.Errorf("malformed INODE_REF: %w", body.Err))
default:
panic(fmt.Errorf("should not happen: INODE_REF has unexpected item type: %T", body))
}
@@ -252,19 +252,19 @@ func (ret *Dir) populate() {
case btrfsitem.DirEntry:
namehash := btrfsitem.NameHash(entry.Name)
if namehash != item.Key.Offset {
- ret.Errs = append(ret.Errs, fmt.Errorf("direntry crc32c mismatch: key=%#x crc32c(%q)=%#x",
+ dir.Errs = append(dir.Errs, fmt.Errorf("direntry crc32c mismatch: key=%#x crc32c(%q)=%#x",
item.Key.Offset, entry.Name, namehash))
continue
}
- if other, exists := ret.ChildrenByName[string(entry.Name)]; exists {
+ if other, exists := dir.ChildrenByName[string(entry.Name)]; exists {
if !reflect.DeepEqual(entry, other) {
- ret.Errs = append(ret.Errs, fmt.Errorf("multiple instances of direntry name %q", entry.Name))
+ dir.Errs = append(dir.Errs, fmt.Errorf("multiple instances of direntry name %q", entry.Name))
}
continue
}
- ret.ChildrenByName[string(entry.Name)] = entry
+ dir.ChildrenByName[string(entry.Name)] = entry
case btrfsitem.Error:
- ret.Errs = append(ret.Errs, fmt.Errorf("malformed DIR_ITEM: %w", entry.Err))
+ dir.Errs = append(dir.Errs, fmt.Errorf("malformed DIR_ITEM: %w", entry.Err))
default:
panic(fmt.Errorf("should not happen: DIR_ITEM has unexpected item type: %T", entry))
}
@@ -272,15 +272,15 @@ func (ret *Dir) populate() {
index := item.Key.Offset
switch entry := item.Body.(type) {
case btrfsitem.DirEntry:
- if other, exists := ret.ChildrenByIndex[index]; exists {
+ if other, exists := dir.ChildrenByIndex[index]; exists {
if !reflect.DeepEqual(entry, other) {
- ret.Errs = append(ret.Errs, fmt.Errorf("multiple instances of direntry index %v", index))
+ dir.Errs = append(dir.Errs, fmt.Errorf("multiple instances of direntry index %v", index))
}
continue
}
- ret.ChildrenByIndex[index] = entry
+ dir.ChildrenByIndex[index] = entry
case btrfsitem.Error:
- ret.Errs = append(ret.Errs, fmt.Errorf("malformed DIR_INDEX: %w", entry.Err))
+ dir.Errs = append(dir.Errs, fmt.Errorf("malformed DIR_INDEX: %w", entry.Err))
default:
panic(fmt.Errorf("should not happen: DIR_INDEX has unexpected item type: %T", entry))
}
@@ -290,23 +290,23 @@ func (ret *Dir) populate() {
}
entriesWithIndexes := make(containers.Set[string])
nextIndex := uint64(2)
- for index, entry := range ret.ChildrenByIndex {
+ for index, entry := range dir.ChildrenByIndex {
if index+1 > nextIndex {
nextIndex = index + 1
}
entriesWithIndexes.Insert(string(entry.Name))
- if other, exists := ret.ChildrenByName[string(entry.Name)]; !exists {
- ret.Errs = append(ret.Errs, fmt.Errorf("missing by-name direntry for %q", entry.Name))
- ret.ChildrenByName[string(entry.Name)] = entry
+ if other, exists := dir.ChildrenByName[string(entry.Name)]; !exists {
+ dir.Errs = append(dir.Errs, fmt.Errorf("missing by-name direntry for %q", entry.Name))
+ dir.ChildrenByName[string(entry.Name)] = entry
} else if !reflect.DeepEqual(entry, other) {
- ret.Errs = append(ret.Errs, fmt.Errorf("direntry index %v and direntry name %q disagree", index, entry.Name))
- ret.ChildrenByName[string(entry.Name)] = entry
+ dir.Errs = append(dir.Errs, fmt.Errorf("direntry index %v and direntry name %q disagree", index, entry.Name))
+ dir.ChildrenByName[string(entry.Name)] = entry
}
}
- for _, name := range maps.SortedKeys(ret.ChildrenByName) {
+ for _, name := range maps.SortedKeys(dir.ChildrenByName) {
if !entriesWithIndexes.Has(name) {
- ret.Errs = append(ret.Errs, fmt.Errorf("missing by-index direntry for %q", name))
- ret.ChildrenByIndex[nextIndex] = ret.ChildrenByName[name]
+ dir.Errs = append(dir.Errs, fmt.Errorf("missing by-index direntry for %q", name))
+ dir.ChildrenByIndex[nextIndex] = dir.ChildrenByName[name]
nextIndex++
}
}
@@ -354,20 +354,20 @@ func (sv *Subvolume) LoadFile(inode btrfsprim.ObjID) (*File, error) {
return val, nil
}
-func (ret *File) populate() {
- for _, item := range ret.OtherItems {
+func (file *File) populate() {
+ for _, item := range file.OtherItems {
switch item.Key.ItemType {
case btrfsitem.INODE_REF_KEY:
// TODO
case btrfsitem.EXTENT_DATA_KEY:
switch itemBody := item.Body.(type) {
case btrfsitem.FileExtent:
- ret.Extents = append(ret.Extents, FileExtent{
+ file.Extents = append(file.Extents, FileExtent{
OffsetWithinFile: int64(item.Key.Offset),
FileExtent: itemBody,
})
case btrfsitem.Error:
- ret.Errs = append(ret.Errs, fmt.Errorf("malformed EXTENT_DATA: %w", itemBody.Err))
+ file.Errs = append(file.Errs, fmt.Errorf("malformed EXTENT_DATA: %w", itemBody.Err))
default:
panic(fmt.Errorf("should not happen: EXTENT_DATA has unexpected item type: %T", itemBody))
}
@@ -379,34 +379,34 @@ func (ret *File) populate() {
// These should already be sorted, because of the nature of
// the btree; but this is a recovery tool for corrupt
// filesystems, so go ahead and ensure that it's sorted.
- sort.Slice(ret.Extents, func(i, j int) bool {
- return ret.Extents[i].OffsetWithinFile < ret.Extents[j].OffsetWithinFile
+ sort.Slice(file.Extents, func(i, j int) bool {
+ return file.Extents[i].OffsetWithinFile < file.Extents[j].OffsetWithinFile
})
pos := int64(0)
- for _, extent := range ret.Extents {
+ for _, extent := range file.Extents {
if extent.OffsetWithinFile != pos {
if extent.OffsetWithinFile > pos {
- ret.Errs = append(ret.Errs, fmt.Errorf("extent gap from %v to %v",
+ file.Errs = append(file.Errs, fmt.Errorf("extent gap from %v to %v",
pos, extent.OffsetWithinFile))
} else {
- ret.Errs = append(ret.Errs, fmt.Errorf("extent overlap from %v to %v",
+ file.Errs = append(file.Errs, fmt.Errorf("extent overlap from %v to %v",
extent.OffsetWithinFile, pos))
}
}
size, err := extent.Size()
if err != nil {
- ret.Errs = append(ret.Errs, fmt.Errorf("extent %v: %w", extent.OffsetWithinFile, err))
+ file.Errs = append(file.Errs, fmt.Errorf("extent %v: %w", extent.OffsetWithinFile, err))
}
pos += size
}
- if ret.InodeItem != nil && pos != ret.InodeItem.NumBytes {
- if ret.InodeItem.NumBytes > pos {
- ret.Errs = append(ret.Errs, fmt.Errorf("extent gap from %v to %v",
- pos, ret.InodeItem.NumBytes))
+ if file.InodeItem != nil && pos != file.InodeItem.NumBytes {
+ if file.InodeItem.NumBytes > pos {
+ file.Errs = append(file.Errs, fmt.Errorf("extent gap from %v to %v",
+ pos, file.InodeItem.NumBytes))
} else {
- ret.Errs = append(ret.Errs, fmt.Errorf("extent mapped past end of file from %v to %v",
- ret.InodeItem.NumBytes, pos))
+ file.Errs = append(file.Errs, fmt.Errorf("extent mapped past end of file from %v to %v",
+ file.InodeItem.NumBytes, pos))
}
}
}
@@ -451,7 +451,7 @@ func (file *File) maybeShortReadAt(dat []byte, off int64) (int, error) {
if err != nil {
return 0, err
}
- var beg btrfsvol.LogicalAddr = extent.BodyExtent.DiskByteNr.
+ beg := extent.BodyExtent.DiskByteNr.
Add(extent.BodyExtent.Offset).
Add(btrfsvol.AddrDelta(offsetWithinExt))
var block [btrfssum.BlockSize]byte