diff options
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/binstruct/binint/builtins.go | 2 | ||||
-rw-r--r-- | pkg/binstruct/structs.go | 20 | ||||
-rw-r--r-- | pkg/btrfs/btrfsitem/items.go | 2 | ||||
-rw-r--r-- | pkg/btrfs/internal/objid.go | 2 | ||||
-rw-r--r-- | pkg/btrfs/io1_device.go | 6 | ||||
-rw-r--r-- | pkg/btrfs/io2_fs.go | 30 | ||||
-rw-r--r-- | pkg/btrfs/types_btree.go | 44 | ||||
-rw-r--r-- | pkg/btrfs/types_superblock.go | 2 | ||||
-rw-r--r-- | pkg/btrfsmisc/fsck.go | 4 | ||||
-rw-r--r-- | pkg/btrfsmisc/print_tree.go | 138 | ||||
-rw-r--r-- | pkg/util/bitfield.go | 2 | ||||
-rw-r--r-- | pkg/util/fmt.go | 4 | ||||
-rw-r--r-- | pkg/util/ref.go | 2 |
13 files changed, 129 insertions, 129 deletions
diff --git a/pkg/binstruct/binint/builtins.go b/pkg/binstruct/binint/builtins.go index 9af3c35..04fc477 100644 --- a/pkg/binstruct/binint/builtins.go +++ b/pkg/binstruct/binint/builtins.go @@ -7,7 +7,7 @@ import ( func needNBytes(t interface{}, dat []byte, n int) error { if len(dat) < n { - return fmt.Errorf("%T.UnmarshalBinary: need at least %d bytes, only have %d", t, n, len(dat)) + return fmt.Errorf("%T.UnmarshalBinary: need at least %v bytes, only have %v", t, n, len(dat)) } return nil } diff --git a/pkg/binstruct/structs.go b/pkg/binstruct/structs.go index 8ecea6a..ec2bb7d 100644 --- a/pkg/binstruct/structs.go +++ b/pkg/binstruct/structs.go @@ -76,11 +76,11 @@ func (sh structHandler) Unmarshal(dat []byte, dst reflect.Value) (int, error) { if _n >= 0 { n += _n } - return n, fmt.Errorf("struct %q field %d %q: %w", + return n, fmt.Errorf("struct %q field %v %q: %w", sh.name, i, field.name, err) } if _n != field.siz { - return n, fmt.Errorf("struct %q field %d %q: consumed %d bytes but should have consumed %d bytes", + return n, fmt.Errorf("struct %q field %v %q: consumed %v bytes but should have consumed %v bytes", sh.name, i, field.name, _n, field.siz) } n += _n @@ -97,7 +97,7 @@ func (sh structHandler) Marshal(val reflect.Value) ([]byte, error) { bs, err := Marshal(val.Field(i).Interface()) ret = append(ret, bs...) if err != nil { - return ret, fmt.Errorf("struct %q field %d %q: %w", + return ret, fmt.Errorf("struct %q field %v %q: %w", sh.name, i, field.name, err) } } @@ -115,13 +115,13 @@ func genStructHandler(structInfo reflect.Type) (structHandler, error) { if fieldInfo.Anonymous && fieldInfo.Type != endType { err := fmt.Errorf("binstruct does not support embedded fields") - return ret, fmt.Errorf("struct %q field %d %q: %w", + return ret, fmt.Errorf("struct %q field %v %q: %w", ret.name, i, fieldInfo.Name, err) } fieldTag, err := parseStructTag(fieldInfo.Tag.Get("bin")) if err != nil { - return ret, fmt.Errorf("struct %q field %d %q: %w", + return ret, fmt.Errorf("struct %q field %v %q: %w", ret.name, i, fieldInfo.Name, err) } if fieldTag.skip { @@ -133,8 +133,8 @@ func genStructHandler(structInfo reflect.Type) (structHandler, error) { } if fieldTag.off != curOffset { - err := fmt.Errorf("tag says off=0x%x but curOffset=0x%x", fieldTag.off, curOffset) - return ret, fmt.Errorf("struct %q field %d %q: %w", + err := fmt.Errorf("tag says off=%#x but curOffset=%#x", fieldTag.off, curOffset) + return ret, fmt.Errorf("struct %q field %v %q: %w", ret.name, i, fieldInfo.Name, err) } if fieldInfo.Type == endType { @@ -143,13 +143,13 @@ func genStructHandler(structInfo reflect.Type) (structHandler, error) { fieldSize, err := staticSize(fieldInfo.Type) if err != nil { - return ret, fmt.Errorf("struct %q field %d %q: %w", + return ret, fmt.Errorf("struct %q field %v %q: %w", ret.name, i, fieldInfo.Name, err) } if fieldTag.siz != fieldSize { - err := fmt.Errorf("tag says siz=0x%x but StaticSize(typ)=0x%x", fieldTag.siz, fieldSize) - return ret, fmt.Errorf("struct %q field %d %q: %w", + err := fmt.Errorf("tag says siz=%#x but StaticSize(typ)=%#x", fieldTag.siz, fieldSize) + return ret, fmt.Errorf("struct %q field %v %q: %w", ret.name, i, fieldInfo.Name, err) } curOffset += fieldTag.siz diff --git a/pkg/btrfs/btrfsitem/items.go b/pkg/btrfs/btrfsitem/items.go index c4ad7e9..1a3b883 100644 --- a/pkg/btrfs/btrfsitem/items.go +++ b/pkg/btrfs/btrfsitem/items.go @@ -65,7 +65,7 @@ func UnmarshalItem(key internal.Key, dat []byte) Item { if n < len(dat) { return Error{ Dat: dat, - Err: fmt.Errorf("btrfsitem.UnmarshalItem({ItemType:%v}, dat): left over data: got %d bytes but only consumed %d", + Err: fmt.Errorf("btrfsitem.UnmarshalItem({ItemType:%v}, dat): left over data: got %v bytes but only consumed %v", key.ItemType, len(dat), n), } } diff --git a/pkg/btrfs/internal/objid.go b/pkg/btrfs/internal/objid.go index a53d61f..b3f09f6 100644 --- a/pkg/btrfs/internal/objid.go +++ b/pkg/btrfs/internal/objid.go @@ -68,7 +68,7 @@ func (id ObjID) Format(typ ItemType) string { uint64(id)>>48, uint64(id)&((1<<48)-1)) case UUID_SUBVOL_KEY, UUID_RECEIVED_SUBVOL_KEY: - return fmt.Sprintf("0x%016x", uint64(id)) + return fmt.Sprintf("%#016x", uint64(id)) case DEV_ITEM_KEY: names := map[ObjID]string{ BALANCE_OBJECTID: "BALANCE", diff --git a/pkg/btrfs/io1_device.go b/pkg/btrfs/io1_device.go index 978d388..32070cd 100644 --- a/pkg/btrfs/io1_device.go +++ b/pkg/btrfs/io1_device.go @@ -56,7 +56,7 @@ func (dev *Device) Superblocks() ([]*util.Ref[PhysicalAddr, Superblock], error) Addr: addr, } if err := superblock.Read(); err != nil { - return nil, fmt.Errorf("superblock %d: %w", i, err) + return nil, fmt.Errorf("superblock %v: %w", i, err) } ret = append(ret, superblock) } @@ -79,11 +79,11 @@ func (dev *Device) Superblock() (*util.Ref[PhysicalAddr, Superblock], error) { for i, sb := range sbs { if err := sb.Data.ValidateChecksum(); err != nil { - return nil, fmt.Errorf("superblock %d: %w", i, err) + return nil, fmt.Errorf("superblock %v: %w", i, err) } if i > 0 { if !sb.Data.Equal(sbs[0].Data) { - return nil, fmt.Errorf("superblock %d and superblock %d disagree", 0, i) + return nil, fmt.Errorf("superblock %v and superblock %v disagree", 0, i) } } } diff --git a/pkg/btrfs/io2_fs.go b/pkg/btrfs/io2_fs.go index a59fec4..cb99d14 100644 --- a/pkg/btrfs/io2_fs.go +++ b/pkg/btrfs/io2_fs.go @@ -23,9 +23,9 @@ type FS struct { func (fs *FS) Name() string { sb, err := fs.Superblock() if err != nil { - return fmt.Sprintf("fs_uuid=%s", "(unreadable)") + return fmt.Sprintf("fs_uuid=%v", "(unreadable)") } - return fmt.Sprintf("fs_uuid=%s", sb.Data.FSUUID) + return fmt.Sprintf("fs_uuid=%v", sb.Data.FSUUID) } func (fs *FS) Size() (LogicalAddr, error) { @@ -76,13 +76,13 @@ func (fs *FS) Superblock() (*util.Ref[PhysicalAddr, Superblock], error) { } if err := sb.Data.ValidateChecksum(); err != nil { - return nil, fmt.Errorf("file %q superblock %d: %w", sb.File.Name(), sbi, err) + return nil, fmt.Errorf("file %q superblock %v: %w", sb.File.Name(), sbi, err) } if i > 0 { // This is probably wrong, but lots of my // multi-device code is probably wrong. if !sb.Data.Equal(sbs[0].Data) { - return nil, fmt.Errorf("file %q superblock %d and file %q superblock %d disagree", + return nil, fmt.Errorf("file %q superblock %v and file %q superblock %v disagree", sbs[0].File.Name(), 0, sb.File.Name(), sbi) } @@ -110,7 +110,7 @@ func (fs *FS) Init() error { b.Checksum = CSum{} b.Self = 0 if !reflect.DeepEqual(a, b) { - return fmt.Errorf("file %q: superblock %d disagrees with superblock 0", + return fmt.Errorf("file %q: superblock %v disagrees with superblock 0", dev.Name(), i+1) } } @@ -158,12 +158,12 @@ func (fs *FS) Resolve(laddr LogicalAddr) (paddrs map[QualifiedPhysicalAddr]struc maxlen = math.MaxUint64 for _, chunk := range fs.chunks { - low := chunk.Key.Offset - high := chunk.Key.Offset + uint64(chunk.Chunk.Head.Size) - match := low <= uint64(laddr) && uint64(laddr) < high + low := LogicalAddr(chunk.Key.Offset) + high := low + LogicalAddr(chunk.Chunk.Head.Size) + match := low <= laddr && laddr < high if dbg2 { - fmt.Printf("DBG: 0x%0x <= 0x%0x < 0x%0x : %v\n", - low, uint64(laddr), high, match) + fmt.Printf("DBG: %v <= %v < %v : %v\n", + low, laddr, high, match) } if match { offsetWithinChunk := uint64(laddr) - chunk.Key.Offset @@ -213,16 +213,16 @@ func (fs *FS) maybeShortReadAt(dat []byte, laddr LogicalAddr) (int, error) { for paddr := range paddrs { dev, ok := fs.uuid2dev[paddr.Dev] if !ok { - return 0, fmt.Errorf("device=%s does not exist", paddr.Dev) + return 0, fmt.Errorf("device=%v does not exist", paddr.Dev) } if _, err := dev.ReadAt(buf, paddr.Addr); err != nil { - return 0, fmt.Errorf("read device=%s paddr=%v: %w", paddr.Dev, paddr.Addr, err) + return 0, fmt.Errorf("read device=%v paddr=%v: %w", paddr.Dev, paddr.Addr, err) } if first { copy(dat, buf) } else { if !bytes.Equal(dat, buf) { - return 0, fmt.Errorf("inconsistent stripes at laddr=%v len=%d", laddr, len(dat)) + return 0, fmt.Errorf("inconsistent stripes at laddr=%v len=%v", laddr, len(dat)) } } } @@ -253,10 +253,10 @@ func (fs *FS) maybeShortWriteAt(dat []byte, laddr LogicalAddr) (int, error) { for paddr := range paddrs { dev, ok := fs.uuid2dev[paddr.Dev] if !ok { - return 0, fmt.Errorf("device=%s does not exist", paddr.Dev) + return 0, fmt.Errorf("device=%v does not exist", paddr.Dev) } if _, err := dev.WriteAt(dat, paddr.Addr); err != nil { - return 0, fmt.Errorf("write device=%s paddr=%v: %w", paddr.Dev, paddr.Addr, err) + return 0, fmt.Errorf("write device=%v paddr=%v: %w", paddr.Dev, paddr.Addr, err) } } return len(dat), nil diff --git a/pkg/btrfs/types_btree.go b/pkg/btrfs/types_btree.go index e58e33b..8a32d9d 100644 --- a/pkg/btrfs/types_btree.go +++ b/pkg/btrfs/types_btree.go @@ -104,7 +104,7 @@ func (node Node) ValidateChecksum() error { return err } if calced != stored { - return fmt.Errorf("node checksum mismatch: stored=%s calculated=%s", + return fmt.Errorf("node checksum mismatch: stored=%v calculated=%v", stored, calced) } return nil @@ -132,7 +132,7 @@ func (node *Node) UnmarshalBinary(nodeBuf []byte) (int, error) { } } if n != len(nodeBuf) { - return n, fmt.Errorf("btrfs.Node.UnmarshalBinary: left over data: got %d bytes but only consumed %d", + return n, fmt.Errorf("btrfs.Node.UnmarshalBinary: left over data: got %v bytes but only consumed %v", len(nodeBuf), n) } return n, nil @@ -143,7 +143,7 @@ func (node Node) MarshalBinary() ([]byte, error) { return nil, fmt.Errorf("btrfs.Node.MarshalBinary: .Size must be set") } if node.Size <= uint32(binstruct.StaticSize(NodeHeader{})) { - return nil, fmt.Errorf("btrfs.Node.MarshalBinary: .Size must be greater than %d", + return nil, fmt.Errorf("btrfs.Node.MarshalBinary: .Size must be greater than %v", binstruct.StaticSize(NodeHeader{})) } if node.Head.Level > 0 { @@ -157,7 +157,7 @@ func (node Node) MarshalBinary() ([]byte, error) { if bs, err := binstruct.Marshal(node.Head); err != nil { return buf, err } else if len(bs) != binstruct.StaticSize(NodeHeader{}) { - return nil, fmt.Errorf("btrfs.Node.MarshalBinary: header is %d bytes but expected %d", + return nil, fmt.Errorf("btrfs.Node.MarshalBinary: header is %v bytes but expected %v", len(bs), binstruct.StaticSize(NodeHeader{})) } else { copy(buf, bs) @@ -192,7 +192,7 @@ func (node *Node) unmarshalInternal(bodyBuf []byte) (int, error) { _n, err := binstruct.Unmarshal(bodyBuf[n:], &item) n += _n if err != nil { - return n, fmt.Errorf("item %d: %w", i, err) + return n, fmt.Errorf("item %v: %w", i, err) } node.BodyInternal = append(node.BodyInternal, item) } @@ -205,16 +205,16 @@ func (node *Node) marshalInternalTo(bodyBuf []byte) error { for i, item := range node.BodyInternal { bs, err := binstruct.Marshal(item) if err != nil { - return fmt.Errorf("item %d: %w", i, err) + return fmt.Errorf("item %v: %w", i, err) } if copy(bodyBuf[n:], bs) < len(bs) { - return fmt.Errorf("item %d: not enough space: need at least %d+%d=%d bytes, but only have %d", + return fmt.Errorf("item %v: not enough space: need at least %v+%v=%v bytes, but only have %v", i, n, len(bs), n+len(bs), len(bodyBuf)) } n += len(bs) } if copy(bodyBuf[n:], node.Padding) < len(node.Padding) { - return fmt.Errorf("padding: not enough space: need at least %d+%d=%d bytes, but only have %d", + return fmt.Errorf("padding: not enough space: need at least %v+%v=%v bytes, but only have %v", n, len(node.Padding), n+len(node.Padding), len(bodyBuf)) } return nil @@ -243,21 +243,21 @@ func (node *Node) unmarshalLeaf(bodyBuf []byte) (int, error) { n, err := binstruct.Unmarshal(bodyBuf[head:], &item.Head) head += n if err != nil { - return 0, fmt.Errorf("item %d: head: %w", i, err) + return 0, fmt.Errorf("item %v: head: %w", i, err) } if head > tail { - return 0, fmt.Errorf("item %d: head: end_offset=0x%0x is in the body section (offset>0x%0x)", + return 0, fmt.Errorf("item %v: head: end_offset=%#x is in the body section (offset>%#x)", i, head, tail) } dataOff := int(item.Head.DataOffset) if dataOff < head { - return 0, fmt.Errorf("item %d: body: beg_offset=0x%0x is in the head section (offset<0x%0x)", + 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) if dataOff+dataSize != tail { - return 0, fmt.Errorf("item %d: body: end_offset=0x%0x is not cur_tail=0x%0x)", + return 0, fmt.Errorf("item %v: body: end_offset=%#x is not cur_tail=%#x)", i, dataOff+dataSize, tail) } tail = dataOff @@ -277,17 +277,17 @@ func (node *Node) marshalLeafTo(bodyBuf []byte) error { for i, item := range node.BodyLeaf { itemBodyBuf, err := binstruct.Marshal(item.Body) if err != nil { - return fmt.Errorf("item %d: body: %w", i, err) + 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) if err != nil { - return fmt.Errorf("item %d: head: %w", i, err) + return fmt.Errorf("item %v: head: %w", i, err) } if tail-head < len(itemHeadBuf)+len(itemBodyBuf) { - return fmt.Errorf("item %d: not enough space: need at least (head_len:%d)+(body_len:%d)=%d free bytes, but only have %d", + return fmt.Errorf("item %v: not enough space: need at least (head_len:%v)+(body_len:%v)=%v free bytes, but only have %v", i, len(itemHeadBuf), len(itemBodyBuf), len(itemHeadBuf)+len(itemBodyBuf), tail-head) } @@ -297,7 +297,7 @@ func (node *Node) marshalLeafTo(bodyBuf []byte) error { copy(bodyBuf[tail:], itemBodyBuf) } if copy(bodyBuf[head:tail], node.Padding) < len(node.Padding) { - return fmt.Errorf("padding: not enough space: need at least %d free bytes, but only have %d", + return fmt.Errorf("padding: not enough space: need at least %v free bytes, but only have %v", len(node.Padding), tail-head) } return nil @@ -333,32 +333,32 @@ func ReadNode[Addr ~int64](fs util.File[Addr], sb Superblock, addr Addr, laddrCB Addr: addr, } if _, err := binstruct.Unmarshal(nodeBuf, &nodeRef.Data.Head); err != nil { - return nodeRef, fmt.Errorf("btrfs.ReadNode: node@%d: %w", addr, err) + return nodeRef, fmt.Errorf("btrfs.ReadNode: node@%v: %w", addr, err) } // sanity checking if nodeRef.Data.Head.MetadataUUID != sb.EffectiveMetadataUUID() { - return nil, fmt.Errorf("btrfs.ReadNode: node@%d: %w", addr, ErrNotANode) + return nil, fmt.Errorf("btrfs.ReadNode: node@%v: %w", addr, ErrNotANode) } stored := nodeRef.Data.Head.Checksum calced := CRC32c(nodeBuf[binstruct.StaticSize(CSum{}):]) if stored != calced { - return nodeRef, fmt.Errorf("btrfs.ReadNode: node@%d: looks like a node but is corrupt: checksum mismatch: stored=%s calculated=%s", + return nodeRef, fmt.Errorf("btrfs.ReadNode: node@%v: looks like a node but is corrupt: checksum mismatch: stored=%v calculated=%v", addr, stored, calced) } if laddrCB != nil { if err := laddrCB(nodeRef.Data.Head.Addr); err != nil { - return nodeRef, fmt.Errorf("btrfs.ReadNode: node@%d: %w", addr, err) + return nodeRef, fmt.Errorf("btrfs.ReadNode: node@%v: %w", addr, err) } } // parse (main) if _, err := nodeRef.Data.UnmarshalBinary(nodeBuf); err != nil { - return nodeRef, fmt.Errorf("btrfs.ReadNode: node@%d: %w", addr, err) + return nodeRef, fmt.Errorf("btrfs.ReadNode: node@%v: %w", addr, err) } // return @@ -374,7 +374,7 @@ func (fs *FS) ReadNode(addr LogicalAddr) (*util.Ref[LogicalAddr, Node], error) { return ReadNode[LogicalAddr](fs, sb.Data, addr, func(claimAddr LogicalAddr) error { if claimAddr != addr { - return fmt.Errorf("read from laddr=%d but claims to be at laddr=%d", + return fmt.Errorf("read from laddr=%v but claims to be at laddr=%v", addr, claimAddr) } return nil diff --git a/pkg/btrfs/types_superblock.go b/pkg/btrfs/types_superblock.go index 7291869..0f63389 100644 --- a/pkg/btrfs/types_superblock.go +++ b/pkg/btrfs/types_superblock.go @@ -84,7 +84,7 @@ func (sb Superblock) ValidateChecksum() error { return err } if calced != stored { - return fmt.Errorf("superblock checksum mismatch: stored=%s calculated=%s", + return fmt.Errorf("superblock checksum mismatch: stored=%v calculated=%v", stored, calced) } return nil diff --git a/pkg/btrfsmisc/fsck.go b/pkg/btrfsmisc/fsck.go index 1334900..2c7085e 100644 --- a/pkg/btrfsmisc/fsck.go +++ b/pkg/btrfsmisc/fsck.go @@ -18,13 +18,13 @@ func ScanForNodes(dev *btrfs.Device, sb btrfs.Superblock, fn func(*util.Ref[btrf } if sb.NodeSize < sb.SectorSize { - return fmt.Errorf("node_size(%d) < sector_size(%d)", + return fmt.Errorf("node_size(%v) < sector_size(%v)", sb.NodeSize, sb.SectorSize) } for pos := btrfs.PhysicalAddr(0); pos+btrfs.PhysicalAddr(sb.NodeSize) < devSize; pos += btrfs.PhysicalAddr(sb.SectorSize) { if util.InSlice(pos, btrfs.SuperblockAddrs) { - //fmt.Printf("sector@%d is a superblock\n", pos) + //fmt.Printf("sector@%v is a superblock\n", pos) continue } diff --git a/pkg/btrfsmisc/print_tree.go b/pkg/btrfsmisc/print_tree.go index de216c2..41e86a0 100644 --- a/pkg/btrfsmisc/print_tree.go +++ b/pkg/btrfsmisc/print_tree.go @@ -25,7 +25,7 @@ func PrintTree(fs *btrfs.FS, root btrfs.LogicalAddr) error { printHeaderInfo(node) if node.Head.Level > 0 { // internal for _, item := range node.BodyInternal { - fmt.Printf("\t%s block %d gen %d\n", + fmt.Printf("\t%v block %v gen %v\n", FmtKey(item.Key), item.BlockPtr, item.Generation) @@ -37,84 +37,84 @@ func PrintTree(fs *btrfs.FS, root btrfs.LogicalAddr) error { } } else { // leaf for i, item := range node.BodyLeaf { - fmt.Printf("\titem %d %s itemoff %d itemsize %d\n", + fmt.Printf("\titem %v %v itemoff %v itemsize %v\n", i, FmtKey(item.Head.Key), item.Head.DataOffset, item.Head.DataSize) switch body := item.Body.(type) { case btrfsitem.FreeSpaceHeader: - fmt.Printf("\t\tlocation %s\n", FmtKey(body.Location)) - fmt.Printf("\t\tcache generation %d entries %d bitmaps %d\n", + fmt.Printf("\t\tlocation %v\n", FmtKey(body.Location)) + fmt.Printf("\t\tcache generation %v entries %v bitmaps %v\n", body.Generation, body.NumEntries, body.NumBitmaps) case btrfsitem.Inode: fmt.Printf(""+ - "\t\tgeneration %d transid %d size %d nbytes %d\n"+ - "\t\tblock group %d mode %o links %d uid %d gid %d rdev %d\n"+ - "\t\tsequence %d flags %v\n", + "\t\tgeneration %v transid %v size %v nbytes %v\n"+ + "\t\tblock group %v mode %o links %v uid %v gid %v rdev %v\n"+ + "\t\tsequence %v flags %v\n", body.Generation, body.TransID, body.Size, body.NumBytes, body.BlockGroup, body.Mode, body.NLink, body.UID, body.GID, body.RDev, body.Sequence, body.Flags) - fmt.Printf("\t\tatime %s\n", fmtTime(body.ATime)) - fmt.Printf("\t\tctime %s\n", fmtTime(body.CTime)) - fmt.Printf("\t\tmtime %s\n", fmtTime(body.MTime)) - fmt.Printf("\t\totime %s\n", fmtTime(body.OTime)) + fmt.Printf("\t\tatime %v\n", fmtTime(body.ATime)) + fmt.Printf("\t\tctime %v\n", fmtTime(body.CTime)) + fmt.Printf("\t\tmtime %v\n", fmtTime(body.MTime)) + fmt.Printf("\t\totime %v\n", fmtTime(body.OTime)) case btrfsitem.InodeRefList: for _, ref := range body { - fmt.Printf("\t\tindex %d namelen %d name: %s\n", + fmt.Printf("\t\tindex %v namelen %v name: %s\n", ref.Index, ref.NameLen, ref.Name) } //case btrfsitem.INODE_EXTREF_KEY: // // TODO case btrfsitem.DirList: for _, dir := range body { - fmt.Printf("\t\tlocation %s type %v\n", + fmt.Printf("\t\tlocation %v type %v\n", FmtKey(dir.Location), dir.Type) - fmt.Printf("\t\ttransid %d data_len %d name_len %d\n", + fmt.Printf("\t\ttransid %v data_len %v name_len %v\n", dir.TransID, dir.DataLen, dir.NameLen) fmt.Printf("\t\tname: %s\n", dir.Name) if len(dir.Data) > 0 { - fmt.Printf("\t\tdata %s\n", dir.Data) + fmt.Printf("\t\tdata %v\n", dir.Data) } } //case btrfsitem.DIR_LOG_INDEX_KEY, btrfsitem.DIR_LOG_ITEM_KEY: // // TODO case btrfsitem.Root: - fmt.Printf("\t\tgeneration %d root_dirid %d bytenr %d byte_limit %d bytes_used %d\n", + fmt.Printf("\t\tgeneration %v root_dirid %v bytenr %d byte_limit %v bytes_used %v\n", body.Generation, body.RootDirID, body.ByteNr, body.ByteLimit, body.BytesUsed) - fmt.Printf("\t\tlast_snapshot %d flags %s refs %d\n", + fmt.Printf("\t\tlast_snapshot %v flags %v refs %v\n", body.LastSnapshot, body.Flags, body.Refs) - fmt.Printf("\t\tdrop_progress %s drop_level %d\n", + fmt.Printf("\t\tdrop_progress %v drop_level %v\n", FmtKey(body.DropProgress), body.DropLevel) - fmt.Printf("\t\tlevel %d generation_v2 %d\n", + fmt.Printf("\t\tlevel %v generation_v2 %v\n", body.Level, body.GenerationV2) if body.Generation == body.GenerationV2 { - fmt.Printf("\t\tuuid %s\n", body.UUID) - fmt.Printf("\t\tparent_uuid %s\n", body.ParentUUID) - fmt.Printf("\t\treceived_uuid %s\n", body.ReceivedUUID) - fmt.Printf("\t\tctransid %d otransid %d stransid %d rtransid %d\n", + fmt.Printf("\t\tuuid %v\n", body.UUID) + fmt.Printf("\t\tparent_uuid %v\n", body.ParentUUID) + fmt.Printf("\t\treceived_uuid %v\n", body.ReceivedUUID) + fmt.Printf("\t\tctransid %v otransid %v stransid %v rtransid %v\n", body.CTransID, body.OTransID, body.STransID, body.RTransID) - fmt.Printf("\t\tctime %s\n", fmtTime(body.CTime)) - fmt.Printf("\t\totime %s\n", fmtTime(body.OTime)) - fmt.Printf("\t\tstime %s\n", fmtTime(body.STime)) - fmt.Printf("\t\trtime %s\n", fmtTime(body.RTime)) + fmt.Printf("\t\tctime %v\n", fmtTime(body.CTime)) + fmt.Printf("\t\totime %v\n", fmtTime(body.OTime)) + fmt.Printf("\t\tstime %v\n", fmtTime(body.STime)) + fmt.Printf("\t\trtime %v\n", fmtTime(body.RTime)) } //case btrfsitem.ROOT_REF_KEY: // // TODO //case btrfsitem.ROOT_BACKREF_KEY: // // TODO case btrfsitem.Extent: - fmt.Printf("\t\trefs %d gen %d flags %v\n", + fmt.Printf("\t\trefs %v gen %v flags %v\n", body.Head.Refs, body.Head.Generation, body.Head.Flags) if body.Head.Flags.Has(btrfsitem.EXTENT_FLAG_TREE_BLOCK) { - fmt.Printf("\t\ttree block %s level %d\n", + fmt.Printf("\t\ttree block %v level %v\n", FmtKey(body.Info.Key), body.Info.Level) } printExtentInlineRefs(body.Refs) case btrfsitem.Metadata: - fmt.Printf("\t\trefs %d gen %d flags %v\n", + fmt.Printf("\t\trefs %v gen %v flags %v\n", body.Head.Refs, body.Head.Generation, body.Head.Flags) - fmt.Printf("\t\ttree block skinny level %d\n", item.Head.Key.Offset) + fmt.Printf("\t\ttree block skinny level %v\n", item.Head.Key.Offset) printExtentInlineRefs(body.Refs) //case btrfsitem.EXTENT_DATA_REF_KEY: // // TODO @@ -123,24 +123,24 @@ func PrintTree(fs *btrfs.FS, root btrfs.LogicalAddr) error { //case btrfsitem.EXTENT_CSUM_KEY: // // TODO case btrfsitem.FileExtent: - fmt.Printf("\t\tgeneration %d type %v\n", + fmt.Printf("\t\tgeneration %v type %v\n", body.Generation, body.Type) switch body.Type { case btrfsitem.FILE_EXTENT_INLINE: - fmt.Printf("\t\tinline extent data size %d ram_bytes %d compression %v\n", + fmt.Printf("\t\tinline extent data size %v ram_bytes %v compression %v\n", len(body.BodyInline), body.RAMBytes, body.Compression) case btrfsitem.FILE_EXTENT_PREALLOC: - fmt.Printf("\t\tprealloc data disk byte %d nr %d\n", + fmt.Printf("\t\tprealloc data disk byte %v nr %v\n", body.BodyPrealloc.DiskByteNr, body.BodyPrealloc.DiskNumBytes) - fmt.Printf("\t\tprealloc data offset %d nr %d\n", + fmt.Printf("\t\tprealloc data offset %v nr %v\n", body.BodyPrealloc.Offset, body.BodyPrealloc.NumBytes) case btrfsitem.FILE_EXTENT_REG: - fmt.Printf("\t\textent data disk byte %d nr %d\n", + fmt.Printf("\t\textent data disk byte %v nr %v\n", body.BodyReg.DiskByteNr, body.BodyReg.DiskNumBytes) - fmt.Printf("\t\textenti data offset %d nr %d ram %d\n", + fmt.Printf("\t\textenti data offset %v nr %v ram %v\n", body.BodyReg.Offset, body.BodyReg.NumBytes, body.RAMBytes) @@ -150,34 +150,34 @@ func PrintTree(fs *btrfs.FS, root btrfs.LogicalAddr) error { fmt.Printf("\t\t(error) unknown file extent type %v", body.Type) } case btrfsitem.BlockGroup: - fmt.Printf("\t\tblock group used %d chunk_objectid %d flags %v\n", + fmt.Printf("\t\tblock group used %v chunk_objectid %v flags %v\n", body.Used, body.ChunkObjectID, body.Flags) case btrfsitem.FreeSpaceInfo: - fmt.Printf("\t\tfree space info extent count %d flags %d\n", + fmt.Printf("\t\tfree space info extent count %v flags %v\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", + fmt.Printf("\t\tlength %v owner %d stripe_len %v type %v\n", body.Head.Size, body.Head.Owner, body.Head.StripeLen, body.Head.Type) - fmt.Printf("\t\tio_align %d io_width %d sector_size %d\n", + fmt.Printf("\t\tio_align %v io_width %v sector_size %v\n", body.Head.IOOptimalAlign, body.Head.IOOptimalWidth, body.Head.IOMinSize) - fmt.Printf("\t\tnum_stripes %d sub_stripes %d\n", + fmt.Printf("\t\tnum_stripes %v sub_stripes %v\n", body.Head.NumStripes, body.Head.SubStripes) for i, stripe := range body.Stripes { - fmt.Printf("\t\t\tstripe %d devid %d offset %d\n", + fmt.Printf("\t\t\tstripe %v devid %d offset %d\n", i, stripe.DeviceID, stripe.Offset) - fmt.Printf("\t\t\tdev_uuid %s\n", + fmt.Printf("\t\t\tdev_uuid %v\n", stripe.DeviceUUID) } case btrfsitem.Dev: fmt.Printf(""+ - "\t\tdevid %d total_bytes %d bytes_used %d\n"+ - "\t\tio_align %d io_width %d sector_size %d type %d\n"+ - "\t\tgeneration %d start_offset %d dev_group %d\n"+ - "\t\tseek_speed %d bandwidth %d\n"+ - "\t\tuuid %s\n"+ - "\t\tfsid %s\n", + "\t\tdevid %d total_bytes %v bytes_used %v\n"+ + "\t\tio_align %v io_width %v sector_size %v type %v\n"+ + "\t\tgeneration %v start_offset %v dev_group %v\n"+ + "\t\tseek_speed %v bandwidth %v\n"+ + "\t\tuuid %v\n"+ + "\t\tfsid %v\n", body.DeviceID, body.NumBytes, body.NumBytesUsed, body.IOOptimalAlign, body.IOOptimalWidth, body.IOMinSize, body.Type, body.Generation, body.StartOffset, body.DevGroup, @@ -186,9 +186,9 @@ func PrintTree(fs *btrfs.FS, root btrfs.LogicalAddr) error { body.FSUUID) case btrfsitem.DevExtent: fmt.Printf(""+ - "\t\tdev extent chunk_tree %d\n"+ - "\t\tchunk_objectid %d chunk_offset %d length %d\n"+ - "\t\tchunk_tree_uuid %s\n", + "\t\tdev extent chunk_tree %v\n"+ + "\t\tchunk_objectid %v chunk_offset %v length %v\n"+ + "\t\tchunk_tree_uuid %v\n", body.ChunkTree, body.ChunkObjectID, body.ChunkOffset, body.Length, body.ChunkTreeUUID) //case btrfsitem.QGROUP_STATUS_KEY: @@ -205,19 +205,19 @@ func PrintTree(fs *btrfs.FS, root btrfs.LogicalAddr) error { //case btrfsitem.STRING_ITEM_KEY: // // TODO case btrfsitem.DevStats: - fmt.Printf("\t\tpersistent item objectid %s offset %d\n", + fmt.Printf("\t\tpersistent item objectid %v offset %v\n", item.Head.Key.ObjectID.Format(item.Head.Key.ItemType), item.Head.Key.Offset) switch item.Head.Key.ObjectID { case btrfs.DEV_STATS_OBJECTID: fmt.Printf("\t\tdevice stats\n") - fmt.Printf("\t\twrite_errs %d read_errs %d flush_errs %d corruption_errs %d generation %d\n", + fmt.Printf("\t\twrite_errs %v read_errs %v flush_errs %v corruption_errs %v generation %v\n", body.Values[btrfsitem.DEV_STAT_WRITE_ERRS], body.Values[btrfsitem.DEV_STAT_READ_ERRS], body.Values[btrfsitem.DEV_STAT_FLUSH_ERRS], body.Values[btrfsitem.DEV_STAT_CORRUPTION_ERRS], body.Values[btrfsitem.DEV_STAT_GENERATION_ERRS]) default: - fmt.Printf("\t\tunknown persistent item objectid %d\n", item.Head.Key.ObjectID) + fmt.Printf("\t\tunknown persistent item objectid %v\n", item.Head.Key.ObjectID) } //case btrfsitem.TEMPORARY_ITEM_KEY: // // TODO @@ -255,23 +255,23 @@ func printHeaderInfo(node btrfs.Node) { var typename string if node.Head.Level > 0 { // internal node typename = "node" - fmt.Printf("node %d level %d items %d free space %d", + fmt.Printf("node %v level %v items %v free space %v", node.Head.Addr, node.Head.Level, node.Head.NumItems, node.MaxItems()-node.Head.NumItems) } else { // leaf node typename = "leaf" - fmt.Printf("leaf %d items %d free space %d", + fmt.Printf("leaf %d items %v free space %v", node.Head.Addr, node.Head.NumItems, node.LeafFreeSpace()) } - fmt.Printf(" generation %d owner %v\n", + fmt.Printf(" generation %v owner %v\n", node.Head.Generation, node.Head.Owner) - fmt.Printf("%s %d flags %s backref revision %d\n", + fmt.Printf("%v %d flags %v backref revision %v\n", typename, node.Head.Addr, node.Head.Flags, @@ -284,8 +284,8 @@ func printHeaderInfo(node btrfs.Node) { fmt.Printf("checksum calced %v\n", calcSum) } - fmt.Printf("fs uuid %s\n", node.Head.MetadataUUID) - fmt.Printf("chunk uuid %s\n", node.Head.ChunkTreeUUID) + fmt.Printf("fs uuid %v\n", node.Head.MetadataUUID) + fmt.Printf("chunk uuid %v\n", node.Head.ChunkTreeUUID) } // printExtentInlineRefs mimics part of btrfs-progs kernel-shared/print-tree.c:print_extent_item() @@ -298,16 +298,16 @@ func printExtentInlineRefs(refs []btrfsitem.ExtentInlineRef) { fmt.Printf("\t\ttree block backref root %v\n", btrfs.ObjID(ref.Offset)) case btrfsitem.SHARED_BLOCK_REF_KEY: - fmt.Printf("\t\tshared block backref parent %d\n", + fmt.Printf("\t\tshared block backref parent %v\n", ref.Offset) default: fmt.Printf("\t\t(error) unexpected empty sub-item type: %v\n", ref.Type) } case btrfsitem.ExtentDataRef: - fmt.Printf("\t\textent data backref root %v objectid %d offset %d count %d\n", + fmt.Printf("\t\textent data backref root %v objectid %v offset %v count %v\n", subitem.Root, subitem.ObjectID, subitem.Offset, subitem.Count) case btrfsitem.SharedDataRef: - fmt.Printf("\t\tshared data backref parent %d count %d\n", + fmt.Printf("\t\tshared data backref parent %v count %v\n", ref.Offset, subitem.Count) default: fmt.Printf("\t\t(error) unexpected sub-item type: %T\n", subitem) @@ -318,25 +318,25 @@ func printExtentInlineRefs(refs []btrfsitem.ExtentInlineRef) { // mimics print-tree.c:btrfs_print_key() func FmtKey(key btrfs.Key) string { var out strings.Builder - fmt.Fprintf(&out, "key (%s %v", key.ObjectID.Format(key.ItemType), key.ItemType) + fmt.Fprintf(&out, "key (%v %v", key.ObjectID.Format(key.ItemType), key.ItemType) switch key.ItemType { case btrfsitem.QGROUP_RELATION_KEY: //TODO, btrfsitem.QGROUP_INFO_KEY, btrfsitem.QGROUP_LIMIT_KEY: panic("not implemented") case btrfsitem.UUID_SUBVOL_KEY, btrfsitem.UUID_RECEIVED_SUBVOL_KEY: - fmt.Fprintf(&out, " 0x%016x)", key.Offset) + fmt.Fprintf(&out, " %v)", btrfs.PhysicalAddr(key.Offset)) case btrfsitem.ROOT_ITEM_KEY: fmt.Fprintf(&out, " %v)", btrfs.ObjID(key.Offset)) default: if key.Offset == util.MaxUint64pp-1 { fmt.Fprintf(&out, " -1)") } else { - fmt.Fprintf(&out, " %d)", key.Offset) + fmt.Fprintf(&out, " %v)", key.Offset) } } return out.String() } func fmtTime(t btrfs.Time) string { - return fmt.Sprintf("%d.%d (%s)", + return fmt.Sprintf("%v.%v (%v)", t.Sec, t.NSec, t.ToStd().Format("2006-01-02 15:04:05")) } diff --git a/pkg/util/bitfield.go b/pkg/util/bitfield.go index 216837d..23da17a 100644 --- a/pkg/util/bitfield.go +++ b/pkg/util/bitfield.go @@ -36,7 +36,7 @@ func BitfieldString[T ~uint8 | ~uint16 | ~uint32 | ~uint64](bitfield T, bitnames if i < len(bitnames) { out.WriteString(bitnames[i]) } else { - fmt.Fprintf(&out, "(1<<%d)", i) + fmt.Fprintf(&out, "(1<<%v)", i) } first = false } diff --git a/pkg/util/fmt.go b/pkg/util/fmt.go index c0ff596..af7404c 100644 --- a/pkg/util/fmt.go +++ b/pkg/util/fmt.go @@ -16,13 +16,13 @@ func FmtStateString(st fmt.State, verb rune) string { } } if width, ok := st.Width(); ok { - fmt.Fprintf(&ret, "%d", width) + fmt.Fprintf(&ret, "%v", width) } if prec, ok := st.Precision(); ok { if prec == 0 { ret.WriteByte('.') } else { - fmt.Fprintf(&ret, ".%d", prec) + fmt.Fprintf(&ret, ".%v", prec) } } ret.WriteRune(verb) diff --git a/pkg/util/ref.go b/pkg/util/ref.go index 57f2eac..aecfb9f 100644 --- a/pkg/util/ref.go +++ b/pkg/util/ref.go @@ -36,7 +36,7 @@ func (r *Ref[A, T]) Read() error { return err } if n != size { - return fmt.Errorf("util.Ref[%T].Read: left over data: read %d bytes but only consumed %d", + return fmt.Errorf("util.Ref[%T].Read: left over data: read %v bytes but only consumed %v", r.Data, size, n) } return nil |