Skip to content

Instantly share code, notes, and snippets.

@robey
Last active December 10, 2015 08:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robey/4410421 to your computer and use it in GitHub Desktop.
Save robey/4410421 to your computer and use it in GitHub Desktop.
I'm probably not ever going to get around to implementing this, but maybe it will help others who are looking for ideas. It's a floppy disk format i came up with back in May when we were told the DCPU would have a floppy disk drive, but we weren't told what the interface would be like yet. Some of the parameters are flexible in the spec because …

dios disk format

disk/block size

the disk block size is 1KB, or 512 words. each disk has 18 tracks of 80 sectors, or 1440 blocks. a hypothetical hard drive could have up to 64k blocks (64MB) using an addressing scheme of one word block ids.

ascii encoding

ascii is packed into a word as two bytes: the high byte first, then the low byte. the high bit of each byte is zero unless it's the last byte of the string.

file sizes

there are five file size categories, each stored in a different way.

  • tiny (up to 1KB)
  • small (up to 32KB)
  • medium (up to 512KB)
  • large (up to 16MB)
  • huge (up to 256MB)

whenever a block reference is zero, that block is unallocated, possibly due to a sparse file. (block 0 is always invalid.)

tiny

tiny files are stored entirely in one block. the directory entry points to this block.

small

small files have a slot of up to 32 block references inside a "small-span" block. each small-span block is made up of 16 "slots" of 32 references each, and the directory entry for a small file points to the small-span block, as well as indicating which of the 16 slots the file is in. when creating new small files (or converting existing files to small), the metadata block contains a list of partially-full small-span blocks that are already in use and have at least one free slot.

medium

medium files have an entire block of 512 block references. the directory entry points to this indirect block.

large

large files use a "small-span" block to indirectly reference up to 32 other reference blocks.

huge

huge files have an indirect block that contains up to 512 references to other reference blocks, in a double-layer tree. the largest file (256MB) could use 512 reference blocks, and an extra top-level block, for 513 blocks total. no file on a floppy disk can reach huge size.

special blocks

a disk must, at minumum, have:

  • one metadata block
  • one folder block

so at least 2KB of the disk must be used for metadata. on a 1.44MB floppy, this is 0.1%.

block zero

block zero is the boot block of the disk. if the disk is bootable, it needs to contain code to bootstrap the operating system. the last 2 words are reserved for key data about the disk.

1fe - location (block #) of the metadata block
1ff - dios identifier: d105

the blocks following block zero (block 1, block 2, ...) may also be used to bootstrap the OS, so the metadata block can be anywhere on the disk. if the disk is not bootable, the metadata block may be block zero.

metadata block

this block contains metadata about the whole disk.

00 - metadata identifier: 8b83
01 - zdos version number (0000)
02 - # of bytes per block
03 - # of blocks on this disk
04 - location (block #) of the root folder block
05 - location (block #) of the bitmap continuation, if it won't fit in
     this metadata block (0 = no continuation)
06-07 - reserved
08-0F - volume name in ascii (up to 16 chars)
10-?? - bitmap of free blocks
??-?? - list of partially-full small-span blocks
1fe-1ff - reserved

the bitmap uses 1 to indicate a free block, and 0 to indicate a used block. the blocks are numbered from the lowest bit (0) to the highest bit (15), so if block 20 is free, bit 5 of word 0x11 will be set. all boot blocks, the metadata block, and the root folder block should all be marked "used" when the disk is formatted.

the bitmap size is (# blocks on disk / 16). on a floppy, that's 90 words. maximum size is 4096 words, which would consume 9 blocks.

if the metadata block is in block zero, the last two words (1FE and 1FF) are used to identify the disk's filesystem, and the metadata identifier (8b83) doubles as a signal that the disk is not bootable. (8b83 executes as a halt instruction, "SUB PC, 1".)

the list of partially-full small-span blocks is used to find small-span blocks with empty slots for files of type small or large. unused entries in the list are marked as zero. small-span blocks should not be in this list if they have all 16 slots full.

the small-span list size is (# blocks on disk / 32). on a floppy, that's 45 words.

folder block

the folder block lists files in a folder.

00 - folder block identifier: d1fb
01 - parent folder block, or 0
02 - next block (continuation) of this folder, or 0
03 - previous block of this folder (if this block is a continuation) or 0
04 - # of entries in this block
05-07 - reserved
08-end - entries

each entry is a static block of metadata 12 words long, so each folder block can contain 42 entries.

00 - block reference (depends on type) (0 = unused/deleted entry)
01 - bitfield: DTSI????????NNNN
     D - entry is a directory (block reference is a folder block)
     T - tiny file: only one block large, so block reference is the
         file's actual content
     S - block reference is a block of slots (small or large file)
     I - block reference is indirect to more block references (large or
         huge file)
     N - # of slot if S is set (0 - 15)
02-03 - size of the file, in words
04-0B - filename in ascii
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment