# What size does the kernel think nbd0 is?
blockdev --getsize64 /dev/nbd0
blockdev --getsz /dev/nbd0

# What does the superblock say?
python3 -c "
import struct
with open('/dev/nbd0','rb') as f:
    f.seek(1024)
    sb = f.read(256)
blocks_lo = struct.unpack_from('<I',sb,4)[0]
blocks_hi = struct.unpack_from('<I',sb,336)[0]
total = (blocks_hi<<32)|blocks_lo
bsize = 4096
print(f'SB block count: {total}')
print(f'SB filesystem size: {total*bsize} bytes')
print(f'NBD device size: ', end='')
import subprocess
r = subprocess.run(['blockdev','--getsize64','/dev/nbd0'],
                   capture_output=True,text=True)
nbd_size = int(r.stdout.strip())
print(nbd_size)
print(f'Match: {total*bsize == nbd_size}')
print(f'Difference: {abs(total*bsize - nbd_size)} bytes')
"
