{
  "$type": "site.standard.document",
  "bskyPostRef": {
    "cid": "bafyreifsmczcwka7xci6jfqys52axbuadxzks5tey253qatniymbypedt4",
    "uri": "at://did:plc:ndtvnkebzmsduapq2rqlsru4/app.bsky.feed.post/3mbqwsn3rssl2"
  },
  "path": "/syndications/kl-os-2026-01-05/",
  "publishedAt": "2026-01-05T00:00:00.000Z",
  "site": "https://scientiac.space",
  "tags": [
    "https://scientiac.space/syndications/kl-os-2026-01-05/POSSE",
    "Day 15",
    "book"
  ],
  "textContent": "Day 15 was about File System.\n\nThe book that I am following has come to an end with **File System** as the final chapter where it teaches to implement `tar` file as a filesystem.\n\n`tar` is an archive format (like zip) that can contain multiple files. It contains file contents, filenames, creation dates, and other information necessary for a filesystem. Compared to common filesystem formats like FAT or ext2, tar has a much simpler data structure.\n\nFirst a simple directory with two files is made as an example which is then archived/compressed into the `tar` format using the command line `tar` tool. Which, also is added to the `buildscript` before launching the `qemu` VM.\n\n\n    (cd disk && tar cf ../disk.tar --format=ustar *.txt)\n\n    # The following flag is also added to qemu.\n    -drive id=drive0,file=disk.tar,format=raw,if=none \\\n\nTo read the filesystem, first, the data structures related to the tar filesystem is defined in `kernel.h`. This implementation has all files read from the disk at boot.\n\nTo write to the disk, the contents of the `files` variable is written back to the disk in the tar file format. The `files` variable contains the copy of the `disk` variable declared as a static variable (It is a temporary buffer and, since the stack has a limited size it is preferred to use static variable instead of local `stack` variable.) which contains the disk image.\n\nFile read/write system calls are then designed in the `user.c` and `user.h` files and then the system calls are implemented on the kernel files and then the system calls are implemented in the kernel. We also add the read and write commands to the shell.\n\nBut, we still have to address the user pointers.\n\nIn RISC-V, the behaviour of `S-Mode` (kernel) can be configured through `sstatus` `CSR`, including SUM (permit Supervisor User Memory access) bit. When SUM is not set, `S-Mode` programs (i.e. kernel) cannot access U-Mode (user) pages.\n\nAll we need to do is to set the SUM bit when entering user space and voila! Our OS with a filesystem implementation is now ready.",
  "title": "KL-OS: File System",
  "updatedAt": "2026-04-22T08:40:40.743Z"
}