diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2022-05-11 18:54:40 -0600 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2022-05-11 18:54:40 -0600 |
commit | f39ce9ac2e5364a4966b3b88c00ecaee5cfd2111 (patch) | |
tree | 57983ed7c2b9aa96df1a4c6e4f434060d7ece6d6 /pkg | |
parent | c519ae6b97b63024dae8ee349fe1e4e47c3ad54f (diff) |
remove desc from binstruct
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/binstruct/binstruct_test.go | 28 | ||||
-rw-r--r-- | pkg/binstruct/l2.go | 9 | ||||
-rw-r--r-- | pkg/btrfs/types.go | 150 |
3 files changed, 93 insertions, 94 deletions
diff --git a/pkg/binstruct/binstruct_test.go b/pkg/binstruct/binstruct_test.go index fc7eab4..382a200 100644 --- a/pkg/binstruct/binstruct_test.go +++ b/pkg/binstruct/binstruct_test.go @@ -12,24 +12,24 @@ func TestSmoke(t *testing.T) { type UUID [16]byte type PhysicalAddr int64 type DevItem struct { - DeviceID uint64 `bin:"off=0, siz=8, desc=device id"` + DeviceID uint64 `bin:"off=0, siz=8"` // device id - NumBytes uint64 `bin:"off=8, siz=8, desc=number of bytes"` - NumBytesUsed uint64 `bin:"off=10, siz=8, desc=number of bytes used"` + NumBytes uint64 `bin:"off=8, siz=8"` // number of bytes + NumBytesUsed uint64 `bin:"off=10, siz=8"` // number of bytes used - IOOptimalAlign uint32 `bin:"off=18, siz=4, desc=optimal I/O align"` - IOOptimalWidth uint32 `bin:"off=1c, siz=4, desc=optimal I/O width"` - IOMinSize uint32 `bin:"off=20, siz=4, desc=minimal I/O size (sector size)"` + IOOptimalAlign uint32 `bin:"off=18, siz=4"` // optimal I/O align + IOOptimalWidth uint32 `bin:"off=1c, siz=4"` // optimal I/O width + IOMinSize uint32 `bin:"off=20, siz=4"` // minimal I/O size (sector size) - Type uint64 `bin:"off=24, siz=8, desc=type"` - Generation uint64 `bin:"off=2c, siz=8, desc=generation"` - StartOffset uint64 `bin:"off=34, siz=8, desc=start offset"` - DevGroup uint32 `bin:"off=3c, siz=4, desc=dev group"` - SeekSpeed uint8 `bin:"off=40, siz=1, desc=seek speed"` - Bandwidth uint8 `bin:"off=41, siz=1, desc=bandwidth"` + Type uint64 `bin:"off=24, siz=8"` // type + Generation uint64 `bin:"off=2c, siz=8"` // generation + StartOffset uint64 `bin:"off=34, siz=8"` // start offset + DevGroup uint32 `bin:"off=3c, siz=4"` // dev group + SeekSpeed uint8 `bin:"off=40, siz=1"` // seek speed + Bandwidth uint8 `bin:"off=41, siz=1"` // bandwidth - DevUUID UUID `bin:"off=42, siz=10, desc=device UUID"` - FSUUID UUID `bin:"off=52, siz=10, desc=FS UUID"` + DevUUID UUID `bin:"off=42, siz=10"` // device UUID + FSUUID UUID `bin:"off=52, siz=10"` // FS UUID binstruct.End `bin:"off=62"` } diff --git a/pkg/binstruct/l2.go b/pkg/binstruct/l2.go index 32aa313..c9b9a9c 100644 --- a/pkg/binstruct/l2.go +++ b/pkg/binstruct/l2.go @@ -117,9 +117,8 @@ func genStructHandler(structInfo reflect.Type) (handler, error) { type tag struct { skip bool - off int64 - siz int64 - desc string + off int64 + siz int64 } func parseStructTag(str string) (tag, error) { @@ -151,8 +150,8 @@ func parseStructTag(str string) (tag, error) { return tag{}, err } ret.siz = vint - case "desc": - ret.desc = val + default: + return tag{}, fmt.Errorf("unrecognized option %q", key) } } return ret, nil diff --git a/pkg/btrfs/types.go b/pkg/btrfs/types.go index 3e7bfaf..a91708e 100644 --- a/pkg/btrfs/types.go +++ b/pkg/btrfs/types.go @@ -13,15 +13,15 @@ type ( ) type Key struct { - ObjectID ObjID `bin:"off=0, siz=8, desc=Object ID. Each tree has its own set of Object IDs."` - ItemType uint8 `bin:"off=8, siz=1, desc=Item type."` - Offset uint64 `bin:"off=9, siz=8, desc=Offset. The meaning depends on the item type."` + ObjectID ObjID `bin:"off=0, siz=8"` // Object ID. Each tree has its own set of Object IDs. + ItemType uint8 `bin:"off=8, siz=1"` // Item type. + Offset uint64 `bin:"off=9, siz=8"` // Offset. The meaning depends on the item type. binstruct.End `bin:"off=11"` } type Time struct { - Sec int64 `bin:"off=0, siz=8, desc=Number of seconds since 1970-01-01T00:00:00Z."` - NSec uint64 `bin:"off=8, siz=4, desc=Number of nanoseconds since the beginning of the second."` + Sec int64 `bin:"off=0, siz=8"` // Number of seconds since 1970-01-01T00:00:00Z. + NSec uint64 `bin:"off=8, siz=4"` // Number of nanoseconds since the beginning of the second. binstruct.End `bin:"off=c"` } @@ -30,50 +30,50 @@ func (t Time) ToStd() time.Time { } type Superblock struct { - Checksum CSum `bin:"off=0, siz=20, desc=Checksum of everything past this field (from 20 to 1000)"` - FSUUID UUID `bin:"off=20, siz=10, desc=FS UUID"` - Self PhysicalAddr `bin:"off=30, siz=8, desc=physical address of this block (different for mirrors)"` - Flags uint64 `bin:"off=38, siz=8, desc=flags"` - Magic [8]byte `bin:"off=40, siz=8, desc=magic ('_BHRfS_M')"` - Generation uint64 `bin:"off=48, siz=8, desc=generation"` - - RootTree LogicalAddr `bin:"off=50, siz=8, desc=logical address of the root tree root"` - ChunkTree LogicalAddr `bin:"off=58, siz=8, desc=logical address of the chunk tree root"` - LogTree LogicalAddr `bin:"off=60, siz=8, desc=logical address of the log tree root"` - - LogRootTransID uint64 `bin:"off=68, siz=8, desc=log_root_transid"` - TotalBytes uint64 `bin:"off=70, siz=8, desc=total_bytes"` - BytesUsed uint64 `bin:"off=78, siz=8, desc=bytes_used"` - RootDirObjectID uint64 `bin:"off=80, siz=8, desc=root_dir_objectid (usually 6)"` - NumDevices uint64 `bin:"off=88, siz=8, desc=num_devices"` - - SectorSize uint32 `bin:"off=90, siz=4, desc=sectorsize"` - NodeSize uint32 `bin:"off=94, siz=4, desc=nodesize"` - LeafSize uint32 `bin:"off=98, siz=4, desc=leafsize"` - StripeSize uint32 `bin:"off=9c, siz=4, desc=stripesize"` - SysChunkArraySize uint32 `bin:"off=a0, siz=4, desc=sys_chunk_array_size"` - - ChunkRootGeneration uint64 `bin:"off=a4, siz=8, desc=chunk_root_generation"` - CompatFlags uint64 `bin:"off=ac, siz=8, desc=compat_flags"` - CompatROFlags uint64 `bin:"off=b4, siz=8, desc=compat_ro_flags - only implementations that support the flags can write to the filesystem"` - IncompatFlags uint64 `bin:"off=bc, siz=8, desc=incompat_flags - only implementations that support the flags can use the filesystem"` - ChecksumType uint16 `bin:"off=c4, siz=2, desc=csum_type - Btrfs currently uses the CRC32c little-endian hash function with seed -1."` - - RootLevel uint8 `bin:"off=c6, siz=1, desc=root_level"` - ChunkLevel uint8 `bin:"off=c7, siz=1, desc=chunk_root_level"` - LogLevel uint8 `bin:"off=c8, siz=1, desc=log_root_level"` - - DevItem DevItem `bin:"off=c9, siz=62, desc=DEV_ITEM data for this device"` - Label [0x100]byte `bin:"off=12b, siz=100, desc=label (may not contain '/' or '\\')"` - CacheGeneration uint64 `bin:"off=22b, siz=8, desc=cache_generation"` - UUIDTreeGeneration uint64 `bin:"off=233, siz=8, desc=uuid_tree_generation"` - - Reserved [0xf0]byte `bin:"off=23b, siz=f0, desc=reserved /* future expansion */"` - - SysChunkArray [0x800]byte `bin:"off=32b, siz=800, desc=sys_chunk_array:(n bytes valid) Contains (KEY . CHUNK_ITEM) pairs for all SYSTEM chunks. This is needed to bootstrap the mapping from logical addresses to physical. "` - TODOSuperRoots [0x2a0]byte `bin:"off=b2b, siz=2a0, desc=Contain super_roots (4 btrfs_root_backup)"` - - Unused [0x235]byte `bin:"off=dcb, siz=235, desc=current unused"` + Checksum CSum `bin:"off=0, siz=20"` // Checksum of everything past this field (from 20 to 1000) + FSUUID UUID `bin:"off=20, siz=10"` // FS UUID + Self PhysicalAddr `bin:"off=30, siz=8"` // physical address of this block (different for mirrors) + Flags uint64 `bin:"off=38, siz=8"` // flags + Magic [8]byte `bin:"off=40, siz=8"` // magic ('_BHRfS_M') + Generation uint64 `bin:"off=48, siz=8"` // generation + + RootTree LogicalAddr `bin:"off=50, siz=8"` // logical address of the root tree root + ChunkTree LogicalAddr `bin:"off=58, siz=8"` // logical address of the chunk tree root + LogTree LogicalAddr `bin:"off=60, siz=8"` // logical address of the log tree root + + LogRootTransID uint64 `bin:"off=68, siz=8"` // log_root_transid + TotalBytes uint64 `bin:"off=70, siz=8"` // total_bytes + BytesUsed uint64 `bin:"off=78, siz=8"` // bytes_used + RootDirObjectID uint64 `bin:"off=80, siz=8"` // root_dir_objectid (usually 6) + NumDevices uint64 `bin:"off=88, siz=8"` // num_devices + + SectorSize uint32 `bin:"off=90, siz=4"` // sectorsize + NodeSize uint32 `bin:"off=94, siz=4"` // nodesize + LeafSize uint32 `bin:"off=98, siz=4"` // leafsize + StripeSize uint32 `bin:"off=9c, siz=4"` // stripesize + SysChunkArraySize uint32 `bin:"off=a0, siz=4"` // sys_chunk_array_size + + ChunkRootGeneration uint64 `bin:"off=a4, siz=8"` // chunk_root_generation + CompatFlags uint64 `bin:"off=ac, siz=8"` // compat_flags + CompatROFlags uint64 `bin:"off=b4, siz=8"` // compat_ro_flags - only implementations that support the flags can write to the filesystem + IncompatFlags uint64 `bin:"off=bc, siz=8"` // incompat_flags - only implementations that support the flags can use the filesystem + ChecksumType uint16 `bin:"off=c4, siz=2"` // csum_type - Btrfs currently uses the CRC32c little-endian hash function with seed -1. + + RootLevel uint8 `bin:"off=c6, siz=1"` // root_level + ChunkLevel uint8 `bin:"off=c7, siz=1"` // chunk_root_level + LogLevel uint8 `bin:"off=c8, siz=1"` // log_root_level + + DevItem DevItem `bin:"off=c9, siz=62"` // DEV_ITEM data for this device + Label [0x100]byte `bin:"off=12b, siz=100"` // label (may not contain '/' or '\\') + CacheGeneration uint64 `bin:"off=22b, siz=8"` // cache_generation + UUIDTreeGeneration uint64 `bin:"off=233, siz=8"` // uuid_tree_generation + + Reserved [0xf0]byte `bin:"off=23b, siz=f0"` // reserved /* future expansion */ + + SysChunkArray [0x800]byte `bin:"off=32b, siz=800"` // sys_chunk_array:(n bytes valid) Contains (KEY . CHUNK_ITEM) pairs for all SYSTEM chunks. This is needed to bootstrap the mapping from logical addresses to physical. + TODOSuperRoots [0x2a0]byte `bin:"off=b2b, siz=2a0"` // Contain super_roots (4 btrfs_root_backup) + + Unused [0x235]byte `bin:"off=dcb, siz=235"` // current unused binstruct.End `bin:"off=1000"` } @@ -117,47 +117,47 @@ func (sb Superblock) ParseSysChunkArray() ([]SysChunk, error) { } type DevItem struct { - DeviceID uint64 `bin:"off=0, siz=8, desc=device id"` + DeviceID uint64 `bin:"off=0, siz=8"` // device id - NumBytes uint64 `bin:"off=8, siz=8, desc=number of bytes"` - NumBytesUsed uint64 `bin:"off=10, siz=8, desc=number of bytes used"` + NumBytes uint64 `bin:"off=8, siz=8"` // number of bytes + NumBytesUsed uint64 `bin:"off=10, siz=8"` // number of bytes used - IOOptimalAlign uint32 `bin:"off=18, siz=4, desc=optimal I/O align"` - IOOptimalWidth uint32 `bin:"off=1c, siz=4, desc=optimal I/O width"` - IOMinSize uint32 `bin:"off=20, siz=4, desc=minimal I/O size (sector size)"` + IOOptimalAlign uint32 `bin:"off=18, siz=4"` // optimal I/O align + IOOptimalWidth uint32 `bin:"off=1c, siz=4"` // optimal I/O width + IOMinSize uint32 `bin:"off=20, siz=4"` // minimal I/O size (sector size) - Type uint64 `bin:"off=24, siz=8, desc=type"` - Generation uint64 `bin:"off=2c, siz=8, desc=generation"` - StartOffset uint64 `bin:"off=34, siz=8, desc=start offset"` - DevGroup uint32 `bin:"off=3c, siz=4, desc=dev group"` - SeekSpeed uint8 `bin:"off=40, siz=1, desc=seek speed"` - Bandwidth uint8 `bin:"off=41, siz=1, desc=bandwidth"` + Type uint64 `bin:"off=24, siz=8"` // type + Generation uint64 `bin:"off=2c, siz=8"` // generation + StartOffset uint64 `bin:"off=34, siz=8"` // start offset + DevGroup uint32 `bin:"off=3c, siz=4"` // dev group + SeekSpeed uint8 `bin:"off=40, siz=1"` // seek speed + Bandwidth uint8 `bin:"off=41, siz=1"` // bandwidth - DevUUID UUID `bin:"off=42, siz=10, desc=device UUID"` - FSUUID UUID `bin:"off=52, siz=10, desc=FS UUID"` + DevUUID UUID `bin:"off=42, siz=10"` // device UUID + FSUUID UUID `bin:"off=52, siz=10"` // FS UUID binstruct.End `bin:"off=62"` } type ChunkItem struct { // Maps logical address to physical. - Size uint64 `bin:"off=0, siz=8, desc=size of chunk (bytes)"` - Root ObjID `bin:"off=8, siz=8, desc=root referencing this chunk (2)"` - StripeLen uint64 `bin:"off=10, siz=8, desc=stripe length"` - Type uint64 `bin:"off=18, siz=8, desc=type (same as flags for block group?)"` - IOOptimalAlign uint32 `bin:"off=20, siz=4, desc=optimal io alignment"` - IOOptimalWidth uint32 `bin:"off=24, siz=4, desc=optimal io width"` - IoMinSize uint32 `bin:"off=28, siz=4, desc=minimal io size (sector size)"` - NumStripes uint16 `bin:"off=2c, siz=2, desc=number of stripes"` - SubStripes uint16 `bin:"off=2e, siz=2, desc=sub stripes"` + Size uint64 `bin:"off=0, siz=8"` // size of chunk (bytes) + Root ObjID `bin:"off=8, siz=8"` // root referencing this chunk (2) + StripeLen uint64 `bin:"off=10, siz=8"` // stripe length + Type uint64 `bin:"off=18, siz=8"` // type (same as flags for block group?) + IOOptimalAlign uint32 `bin:"off=20, siz=4"` // optimal io alignment + IOOptimalWidth uint32 `bin:"off=24, siz=4"` // optimal io width + IoMinSize uint32 `bin:"off=28, siz=4"` // minimal io size (sector size) + NumStripes uint16 `bin:"off=2c, siz=2"` // number of stripes + SubStripes uint16 `bin:"off=2e, siz=2"` // sub stripes binstruct.End `bin:"off=30"` Stripes []ChunkItemStripe `bin:"-"` } type ChunkItemStripe struct { // Stripes follow (for each number of stripes): - DeviceID ObjID `bin:"off=0, siz=8, desc=device id"` - Offset uint64 `bin:"off=8, siz=8, desc=offset"` - DeviceUUID UUID `bin:"off=10, siz=10, desc=device UUID"` + DeviceID ObjID `bin:"off=0, siz=8"` // device id + Offset uint64 `bin:"off=8, siz=8"` // offset + DeviceUUID UUID `bin:"off=10, siz=10"` // device UUID binstruct.End `bin:"off=20"` } |