From b392ad64a8fd04d20b35ad21d2d4ea3ff2778e3f Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Tue, 5 Jul 2022 12:26:45 -0600 Subject: wip file io --- pkg/btrfs/btrfsitem/item_fileextent.go | 29 +++++++++++++++++------------ pkg/btrfsmisc/print_tree.go | 4 ++-- 2 files changed, 19 insertions(+), 14 deletions(-) (limited to 'pkg') diff --git a/pkg/btrfs/btrfsitem/item_fileextent.go b/pkg/btrfs/btrfsitem/item_fileextent.go index 5e87021..f3cbffe 100644 --- a/pkg/btrfs/btrfsitem/item_fileextent.go +++ b/pkg/btrfs/btrfsitem/item_fileextent.go @@ -4,9 +4,12 @@ import ( "fmt" "lukeshu.com/btrfs-tools/pkg/binstruct" + "lukeshu.com/btrfs-tools/pkg/btrfs/btrfsvol" "lukeshu.com/btrfs-tools/pkg/btrfs/internal" ) +// key.objectid = inode +// key.offset = offset within file type FileExtent struct { // EXTENT_DATA=108 Generation internal.Generation `bin:"off=0x0, siz=0x8"` // transaction ID that created this extent RAMBytes int64 `bin:"off=0x8, siz=0x8"` // upper bound of what compressed data will decompress to @@ -23,23 +26,25 @@ type FileExtent struct { // EXTENT_DATA=108 // only one of these, depending on .Type BodyInline []byte `bin:"-"` BodyReg struct { - // Position within the device - DiskByteNr int64 `bin:"off=0x0, siz=0x8"` - DiskNumBytes int64 `bin:"off=0x8, siz=0x8"` + // Position of extent within the device + DiskByteNr btrfsvol.LogicalAddr `bin:"off=0x0, siz=0x8"` + DiskNumBytes btrfsvol.AddrDelta `bin:"off=0x8, siz=0x8"` + + // Position of data within the extent + Offset btrfsvol.AddrDelta `bin:"off=0x10, siz=0x8"` + NumBytes btrfsvol.AddrDelta `bin:"off=0x18, siz=0x8"` - // Position within the file - Offset int64 `bin:"off=0x10, siz=0x8"` - NumBytes int64 `bin:"off=0x18, siz=0x8"` binstruct.End `bin:"off=0x20"` } `bin:"-"` BodyPrealloc struct { - // Position within the device - DiskByteNr int64 `bin:"off=0x0, siz=0x8"` - DiskNumBytes int64 `bin:"off=0x8, siz=0x8"` + // Position of extent within the device + DiskByteNr btrfsvol.LogicalAddr `bin:"off=0x0, siz=0x8"` + DiskNumBytes btrfsvol.AddrDelta `bin:"off=0x8, siz=0x8"` + + // Position of data within the extent + Offset btrfsvol.AddrDelta `bin:"off=0x10, siz=0x8"` + NumBytes btrfsvol.AddrDelta `bin:"off=0x18, siz=0x8"` - // Position within the file - Offset int64 `bin:"off=0x10, siz=0x8"` - NumBytes int64 `bin:"off=0x18, siz=0x8"` binstruct.End `bin:"off=0x20"` } `bin:"-"` } diff --git a/pkg/btrfsmisc/print_tree.go b/pkg/btrfsmisc/print_tree.go index f78f653..6b4ff96 100644 --- a/pkg/btrfsmisc/print_tree.go +++ b/pkg/btrfsmisc/print_tree.go @@ -162,10 +162,10 @@ func PrintTree(fs *btrfs.FS, root btrfsvol.LogicalAddr) error { body.BodyPrealloc.Offset, body.BodyPrealloc.NumBytes) case btrfsitem.FILE_EXTENT_REG: - fmt.Printf("\t\textent data disk byte %v nr %v\n", + fmt.Printf("\t\textent data disk byte %d nr %d\n", body.BodyReg.DiskByteNr, body.BodyReg.DiskNumBytes) - fmt.Printf("\t\textent data offset %v nr %v ram %v\n", + fmt.Printf("\t\textent data offset %d nr %d ram %v\n", body.BodyReg.Offset, body.BodyReg.NumBytes, body.RAMBytes) -- cgit v1.2.3-2-g168b