The virtual 1.44MB FAT32 hard drive partition

Seeing as I got no "bytes" on the 1.44MB hook, I've decided on a much better configuration:   * 16 pre-allocated root directory sectors. * 16 "protected" fat table sectors.   Both at "contiguous fixed size / locations" the same as FAT12.   * 256 root directory files of 4KB average size,   (minus one for a root folder to contain other files). * 1MB (2048 sector) virtual FAT32 partition.   Not as large as a floppy disk format, but plenty large enough for a small hobby system. Here are 72 lines of simple assembly language code which will produce a working minimal 32MB FAT32 image:

SECTORS_PER_CLUSTER equ 1
RESERVED_SECTORS equ 64
NUMBER_OF_FATS equ 1
SECTORS equ 66602 ; minimum 32MB FAT32
SECTORS_PER_FAT equ 513
HIDDEN_SECTORS equ 64

mbr:
org 0x600 ; loaded at 0x7C00 by BIOS

times 446-($-$$) db 0
  dd 0
  dd 0x0C ; partition type FAT32
partition_lba:
  dd HIDDEN_SECTORS ; LBA of first partition sector
  dd SECTORS ; number of blocks
times 16*3 db 0
  dw 0xAA55

times 512*(HIDDEN_SECTORS-1) db 0

bpb:
  jmp SHORT start
  nop
  db "        "
  dw 512 ; bytes per sector
  db SECTORS_PER_CLUSTER
  dw RESERVED_SECTORS
  db NUMBER_OF_FATS
  dw 0, 0
  db 0xF8
  dw 0
  dw 64 ; dummy sectors per track
  dw 255 ; dummy number of heads
  dd HIDDEN_SECTORS
  dd SECTORS
  dd SECTORS_PER_FAT
  dd 0
  dd 2 ; cluster number of root directory
  dw 63 ; sector number of FS Information Sector
  dw 0 ; sector number of boot sector copy (or 0 if none)
  dd 0, 0, 0
  db 0, 0, 0x29
  dd 0x78563412 ; dummy volume ID
  db "           " ; volume label
  db "FAT32   "

; 32KB boot sector loaded by mbr to 0x7C00
start:
  times 512*63-($-bpb) db 0

fsi:
  db "RRaA"
  times 480 db 0
  db "rrAa"
  dd -1 ; number of free clusters on the drive or -1 if unknown
  dd 17 ; number of the most recently allocated cluster
  times 14 db 0
  dw 0xAA55

fat:
  dd 0x0FFFFFF8, 0x0FFFFFFF
; pre-allocate 16 root directory sectors
  dd 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 15, 17
  dd 0x0FFFFFFF
  times (512*SECTORS_PER_FAT)-($-fat) db 0

root: ; this is the start of data
; 16 contiguous root sectors at "fixed location" lba 2
  times 512*16 db 0
; minimum 32MB FAT32 image
  times 512*(SECTORS-SECTORS_PER_FAT-RESERVED_SECTORS-16) db 0

Mike Gonta

look and see - many look but few see

http://mikegonta.com

/r/osdev Thread