Show HN: Understanding FAT16 – an interactive filesystem explainer

(fat16.asciitweezers.com)

105 points | by giant_fern 3 days ago

13 comments

  • 3dbrows 6 hours ago
    The article, game and visual aids are delightfully well-crafted. I enjoyed reading this. Thank you!

    Like many others, this brought back memories, but it also leaves me with a certain feeling of wistfulness: personal computing technology is now _harder_ to learn than it was. My kids are approaching the age that I was when I started learning about topics like this, and I think it's harder for them than it was for me to access the first principles of a machine. The common retort to this is "oh, higher level abstractions are more useful". Yes, but something of value is lost when the technical (and informational) barriers to tinkering have been raised so high.

  • compiler-guy 15 hours ago
    Terrific, reminded me of many nights watching norton do its thing.

    A bonus for the game might be to defrag in such a way that the free space is all contiguous. I seem to recall that all files were moved to the lowest cluster numbers, which maximizes contiguous free space at the end.

    Anyway brought back some good memories.

    • Firehawke 13 hours ago
      Correct. You'd prefer a full defragment putting free space at the end so that new files written to the drive have a much higher chance of not being fragmented from the start. It often takes a fair bit longer to do a full defrag, though, so most people went with quick defrags and only used full when the free space was getting too fragmented.
  • rkagerer 7 hours ago
    I kind of wonder what the Internet would look like now if IPv4 had evolved similarly to FAT16 --> FAT32.
  • lock1 10 hours ago
    Man, reminds me of my TA days. Staring at Microsoft FAT specification docs, designing FAT-like toy FS, writing manim code manually.

    Looking at this project, I'm tempted to revisit & rewrite my TA guidebook using LLM assistance for interactive visualization.

    Cool work

  • mradex77 7 hours ago
    This is a cool way to learn how filesystems work.

    Are you thinking about covering FAT32 or other filesystems next?

    • giant_fern 3 hours ago
      I might jump around to different topics, but NTFS still looms large in my mind so maybe some day :)
  • nticompass 4 hours ago
    I like the little defrag game, it's fun.
  • reactor3d 13 hours ago
    The two reading exercises make a nice pair. Starting with a file that fits in one cluster makes it clear what the allocation table adds when a file is scattered across the disk.
  • abeauvois 2 days ago
    such an emotion! Amiga, FAT16 & 32 ...colored DOS screen, I remember the boot viruses that used to change the first pointer to the boot code. The FAT backup saved my day several times.
  • fuzzfactor 9 hours ago
    >Would love to hear corrections

    You presented good info quite well and I am impressed :)

    More understanding please ;)

    This is not meant to be harsh but I would bring the terminology up to the next level at least.

    That's a little correction but mostly "color" from me :)

    A "disk" is actually most correctly a single piece of hardware, basically otherwise known equally correctly as a "drive". Probably why they call them HDDs and SSDs ;)

    Unfortunately both terms were spread conventionally by Microsoft as interchangeably poor substitutes for the more accurate terms "partition" and "volume". At one time those who were fortunate enough to even have a HDD were taught to refer to it as their "C:" drive. "A:" and "B:" were certainly always floppy hardware drives by definition, regardless of which drive you inserted a floppy disk into, and that basic terminology logic was simply extended when you got the long-coveted HDD, so that worked somewhat as a learning shortcut. You have addressed this pretty well by skipping over the partitioning stuff, I don't blame you a bit ;)

    But at the time it's also as if it was not possible to end up having up to 4 bootable primary partitions per HDD, each independently containing your choice of folders & files somewhat like a 4-drawer filing cabinet. Whether you chose to put a bootable fileset having a different OS on each partition, or merely use one or more partitions for plain ordinary storage was supposed to be your choice. On powerup I kinda liked having the choice of DOS, WindowsNT, Windows 3.1, and Linux from the "standard" Microsoft bootmenu myself :) Instead most users never dreamed they would ever see any "drive" other than "C:". DOS & Windows PCs intentionally sold with the entire HDD already "divided" into a single FAT partition taking up the whole disk, with the OS pre-"installed" to it, and plenty of space left over for your valuable data storage to be intimately intermixed with the OS files & folders. IOW if you wanted to take advantage of multibooting, or merely confine your data more safely away from your OS by using different volumes, you would most likely be expected to buy an additional HDD to use as a mainstream "D: drive". Otherwise you were on your own with no documentation nor tools from Microsoft which would be as helpful as they could be for multi-partitioning a single HDD, especially when it comes to booting a secondary OS. Remember, until CDROMs and later USB sticks started showing up all over the place, any existence of a "D:" volume or any other letter of the alphabet beyond C: was considered voodoo of some kind and discouraged as being not for the faint of heart.

    But the wrong false move on your only volume (C:, where the OS is more likely to become self-corrupt than your own more-valuable data it is sharing space with), and you were expected to lose your OS and data at the same time. Even now to some extent this concept lingers :\

    So if some geek came along with two HDDs in one PC, a "C:" and a "D:" "drive", it was looked at by regular office workers as about the most confusing undocumented thing at the time. Even worse if there was only one HDD and it was partitioned into more than one partition so you had like a D: E: & F: to go along with your C:. However for most users CDROMs usually were the first time they had ever seen a D:, then if they were advanced, "risked it all" and added 3 more primary partitions to their HDD they could end up with C:, E:, F: & G: on the same HDD, some users' head could explode with that ;) Plus whichever volume you boot to at the time is designated as C:, and the remaining alphabetic letters assigned in relation to that according to a fairly interesting hierarchy.

    Of course multi-partitioning was usually only done using third-party tools, Microsoft was not your friend here. Actually not usual at all, more like "seldom if ever" in most offices.

    Anyway, namely a volume is a formatted partition, so partition and volume are not even supposed to have the same meaning. Neither one is best referred to as a "disk" nor a "drive" when you start really focusing on filesystems, leaving you responsible for making the distinction more correctly than most people have been taught to do.

    Now under conventional (legacy) BIOS, sector 0 of the HDD contains the Master Boot Record (MBR) within the first 440 bytes followed by the NT serial number if present, then the next bytes consist of the partition table followed by the final "signature bytes". All within 512 bytes. The MBR is the code that interprets the partition table, and then jumps to the particular partition that is marked "Active" at the time.

    Any one of these partitions is where your designated "sector 0" comes in, not exactly "start of disk" proper at all. Note that the first sector of each partition is always a bit "downstream" from the actual sector 0 of the HDD (as defined by the particular partition table), even when you only have a single partition encompassing the whole HDD. Simply enough, your "start of disk" is actually a start of a single volume contained within the disk. At the first sector of the volume like this is where you correctly follow the Boot Sector code proper which interprets the particular filesystem on the volume. And from which point the booted partition acts about as closely to a floppy as it's going to.

    A volume's boot sector is more descriptively known as a Volume Boot Record (VBR), or even a Partition Boot Record (PBR) sometimes. Also it's not the VBR, it's the MBR where the code must be restricted to the first 440 bytes of HDD sector 0. Bytes 441 thru 444 are reserved or occupied by the NT serial number, 445 & 446 were always zeros and unused (although these days some non-zero data finds its way there somehow sometimes, I don't know from where yet). 447 & 448 are the first two bytes of the partition table itself which extends to 510, so off-limits to MBR code as well. 511 & 512 are the final signature bytes.

    For a VBR sector, much more variation can be seen between different filesystems, the code can be more or less than 440 bytes plus usually followed by error messages that can extend almost to the end of the sector since the later bytes do not contain a partition table so are available for other use, because a VBR is not an MBR. Even though there is some cross-functionality tracing back to floppies, the MBR is supposed to be OS-agnostic and simply jump to the active partition according to the partition table. Any VBR code found then interprets the specific filesystem on that particular volume and runs the expected boot files contained and found in that filesystem.

    So that's more or less a numerical correction there :)

    I say keep doing what you're doing because it is coming out good so far :) Excellent really.

    Prepare the terminology to be consistent enough now to better address the partitioning process in detail later.

    If you haven't looked over the Starman this is old info (newer than FAT16 though) but contemporary with FAT32 and early NTFS, extensive but not as complete as it could be and not always perfect, but very useful. For instance hidden sectors are now usually 2048, instead of 63 which was the most common first-partition starting point decades ago, but there were also sometimes 32 or 64 hidden among others like 128. BIOS is supposed to read the sectors well enough to handle this but lots of motherboards would only boot to a volume having 63:

    https://thestarman.narod.ru/asm/mbr/index.html

    Keep posting as you make progress, when you get to FAT32 I'll have more to add since that's mainly what UEFI is expected to boot with.

    I confirm these kind of things using extensive experimentation.

    Oh yeah, keep in mind that FAT32 boot sectors can come in a variety of forms appropriate for the different generations of boot files which are intended to be found and executed.

    Originally they were a FAT DOS bootsector, written to the volume by formatting or "SYSing" the volume while booted to DOS or W9x, a DOS bootsector seeks the IO.SYS file. Then FAT NT3 and NT4 were not as well-developed before reaching FAT NT5 for W2K & XP, seeking NTLDR as a boot file not much differently than an NTFS NT5 bootsector does. Next we find ourselves at NT6 FAT bootsectors since Vista, now seeking a BOOTMGR file in the filesystem as well as the expected well-crafted BOOT folder to launch the OS, as far as BIOS goes. OTOH under UEFI mode instead of BIOS, the firmware is OK without any BOOT folder to start Windows[0] and seeks the EFI folder regardless of what OS the FAT boot volume was formatted with.

    [0] Some Linux distros in UEFI mode can depend on having a BOOT folder containing their specific extra files though, in addition to the nominal EFI folder in the FAT ESP bootvolume.

    • giant_fern 3 hours ago
      Thanks for the feedback! That starman link is very extensive.

      The bootloader process is also fascinating to me, and is exactly where all these boot sector variations become extra pertinent.

  • visionwei 10 hours ago
    What made the cluster chain click for me was §4: following a file's chain by hopping between the FAT and the data area, watching 3 → 7 → 5 resolve step by step, beat any static diagram of a linked list. Same in §5: deleting ALICE.TXT showed 'delete' just means stamping 0xE5 on the name and freeing one FAT entry, which made the whole undelete story obvious. One question: the toy disk uses a single FAT, so the backup copy never comes into play — in real life, when the two FAT copies disagreed, did DOS just trust the first one? §8 flags long filenames and subdirectories as out of scope, but I'd love a VFAT follow-up — that's the part that still bites when mounting old drives today.
    • giant_fern 3 hours ago
      > in real life, when the two FAT copies disagreed, did DOS just trust the first one?

      I believe so, and it's up to you to run CHKDSK manually if you suspect they might differ, like after a crash. It doesn't seem like a very well thought out system!

      Thanks for the feedback!

  • ukdstore 9 hours ago
    Opening on a working defrag screen as the title card is a lovely touch, and the page still reads fine with JavaScript off, which most explorable explanations skip.

    Is the cluster map on the title screen driven by the same FAT model the later demos use, or is it a separate animation?

    • giant_fern 3 hours ago
      Thank you! The animation uses a separate model - because of the responsive layout the numbers of clusters jump around a bit at different page sizes.
  • precious_reads 3 days ago
    [flagged]