{
  "$type": "site.standard.document",
  "bskyPostRef": {
    "cid": "bafyreiabo3lahnzk4s45xdej5iuizcoxogrssai66hywgzjxv3sh2gclpa",
    "uri": "at://did:plc:ndtvnkebzmsduapq2rqlsru4/app.bsky.feed.post/3mbquveqsrpq2"
  },
  "path": "/syndications/kl-os-2026-01-04/",
  "publishedAt": "2026-01-04T00:00:00.000Z",
  "site": "https://scientiac.space",
  "tags": [
    "https://scientiac.space/syndications/kl-os-2026-01-04/POSSE",
    "Day 14",
    "spec"
  ],
  "textContent": "Day 14 was about Disk `I/O`.\n\nA device driver for the `virtio-blk`, a virtual disk device was implemented.\n\n`Virtio` is one of the APIs for device drivers to control devices. It is widely used in virtualization environments such as QEMU. The `virtio` devices have a structure called `virtqueue` and it is a queue shared between the driver and the device. It consists of `Discriptor Table`, `Available Ring` and `Used Ring`.\n\nFirst we enable `virtio` drivers in our `buildscript` which is `run.sh`. We use the following flags for `qemu`:\n\n\n        -drive id=drive0,file=lorem.txt,format=raw,if=none\n        -device virtio-blk-device,drive=drive0,bus=virtio-mmio-bus.0\n\nHere, `lorem.txt` is a file made for testing purposes beforehand.\n\nThen, the definition of `c` structs and macros is done in `kernel.h`. To access the `MMIO` registers we add that functionality in `kernel.c`.\n\nThe `create_process` function is modified to map the `virtio-blk` `MMIO` region to the page table so the kernel can access the `MMIO` registers. `MMIO` region to the page table so the kernel can access the `MMIO` registers.\n\nThen the `Virtio Device Initialization` and `Virtqueue Initialization` is done with the process described in the spec.\n\n`I/O` requests to the disk is implemented by \"adding processing requests to the `virtqueue`\".\n\nA request is sent in the following steps:\n\n  1. Construct a request in `blk_req`. Specify the sector number you want to access and the type of read/write.\n  2. Construct a descriptor chain pointing to each area of `blk_req` (see below).\n  3. Add the index of the head descriptor of the descriptor chain to the Available Ring.\n  4. Notify the device that there is a new pending request.\n  5. Wait until the device finishes processing (aka busy-waiting or polling).\n  6. Check the response from the device.\n\n\n\nTo test, we initialize the `virtio` device in the kernel main and try reading and writing to the disk with the implemented functions.\n\n> Device drivers are just \"glue\" between the OS and devices. Drivers don't control the hardware directly; drivers communicate with other software running on the device (e.g., firmware). Devices and their software, not the OS driver, will do the rest of the heavy lifting, like moving disk read/write heads.",
  "title": "KL-OS: Disk I/O",
  "updatedAt": "2026-04-22T08:40:37.014Z"
}