diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2022-06-01 01:27:19 -0600 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2022-06-01 01:27:19 -0600 |
commit | 3825cf60fd652f22acc438d50028701d27a7402d (patch) | |
tree | 24b86afb8513891274dfaa8b982c4c94c1a65a5d /pkg/btrfs/io_device.go | |
parent | 2348cdbe2a3417990a2088f9e4e91adf0c45617d (diff) |
wow
Diffstat (limited to 'pkg/btrfs/io_device.go')
-rw-r--r-- | pkg/btrfs/io_device.go | 73 |
1 files changed, 0 insertions, 73 deletions
diff --git a/pkg/btrfs/io_device.go b/pkg/btrfs/io_device.go deleted file mode 100644 index 042c9f2..0000000 --- a/pkg/btrfs/io_device.go +++ /dev/null @@ -1,73 +0,0 @@ -package btrfs - -import ( - "fmt" - "os" -) - -type Device struct { - *os.File -} - -func (dev Device) Size() (PhysicalAddr, error) { - fi, err := dev.Stat() - if err != nil { - return 0, err - } - return PhysicalAddr(fi.Size()), nil -} - -var superblockAddrs = []PhysicalAddr{ - 0x00_0001_0000, // 64KiB - 0x00_0400_0000, // 64MiB - 0x40_0000_0000, // 256GiB -} - -func (dev *Device) ReadAt(dat []byte, paddr PhysicalAddr) (int, error) { - return dev.File.ReadAt(dat, int64(paddr)) -} - -func (dev *Device) Superblocks() ([]Ref[PhysicalAddr, Superblock], error) { - const superblockSize = 0x1000 - - sz, err := dev.Size() - if err != nil { - return nil, err - } - - var ret []Ref[PhysicalAddr, Superblock] - for i, addr := range superblockAddrs { - if addr+superblockSize <= sz { - superblock := Ref[PhysicalAddr, Superblock]{ - File: dev, - Addr: addr, - } - if err := superblock.Read(); err != nil { - return nil, fmt.Errorf("superblock %d: %w", i, err) - } - ret = append(ret, superblock) - } - } - if len(ret) == 0 { - return nil, fmt.Errorf("no superblocks") - } - return ret, nil -} - -func (dev *Device) Superblock() (ret Ref[PhysicalAddr, Superblock], err error) { - sbs, err := dev.Superblocks() - if err != nil { - return ret, err - } - for i, sb := range sbs { - if err := sb.Data.ValidateChecksum(); err != nil { - return ret, fmt.Errorf("superblock %d: %w", i, err) - } - if i > 0 { - if !sb.Data.Equal(sbs[0].Data) { - return ret, fmt.Errorf("superblock %d and superblock %d disagree", 0, i) - } - } - } - return sbs[0], nil -} |