In another thread:
Ben,
There are dozens and dozens of books, papers, articles, and what not on this. Pick a disk size and go for it.
From the Forth idea where all you have is the bare-raw disk block (or typically enough chained together to make up 1KB). Create a manual index in block 0 that you can use to type in a filename and the number of the block and off you go…
Right up to something more modern that can support open/read/write/close/seek and directories…
Some more ideas: Read (it’s online) Beneath Apple DOS. Also Beneath Apple ProDOS. One of my retro filing systems was inspired by ProDOS - and it can handle up to 32MB directly, 64MB with some tweaking. That ought to be more than enough for a retro system.
Here is something much more simple: Go and look up the “Best Fit Algorithm” for writing a memory allocator. Now treat your disk drive as a linear array of bytes and implement that. This is not a million miles from several old filing systems - the ‘trick’ is to create a file with enough space in the first instance so you don’t overwrite the end of it. (but impose those checks in the driver code anyway) It’s very effective and not hard to do - just keep a separate few blocks at the start for the index/catalog. The rest is just a big linked list of files and files themselves are always consecutive sectors on the media. After some time you’ll need to write a “compact” utility that merges free space and optionally moves files, but that’s not a big deal.
Just do it.
-Gordon