monogon-dev / monogon

The Monogon Monorepo. May contain traces of peanuts and a ✨pure Go Linux userland✨. Work in progress!
https://monogon.tech
Apache License 2.0
378 stars 9 forks source link

blockdev: open API design questions #240

Open lorenz opened 1 year ago

lorenz commented 1 year ago

There are a number of warts/open questions related to the blockdev design:

See also code at https://review.monogon.dev/c/monogon/+/1873

  1. Blocks vs bytes and alignment

    • Most arguments are bytes, which must be aligned to blocks
    • WriteAt/ReadAt might only take block-aligned IO depending on platform and O_DIRECT
    • BlockCount returns the number of blocks, not bytes (maybe we should have Size())?
  2. ReadWriteSeeker

    • BlockDev does not require Read/Write/Seek to be present, but these are commonly required to for example copy data onto block devices
    • Underlying block device can require block alignment, which would require buffering
  3. GPT/partitions

    • I migrated GPT onto blockdev as it makes extensive use of the block device geometry.
    • Problem is that now GPT has a weird API surface where magic happens when AddPartition magically creates a section of the block device it's added to (and not updated when you change first/last block manually)
    • Reading/writing partitions requires creating a RWS manually.
    • Support for dynamically-sized block devices when backed by files.

/cc @q3k