Discussion:
The virtual 1MB FAT32 partition
(too old to reply)
Mike Gonta
2016-03-29 19:44:47 UTC
Permalink
https://groups.google.com/forum/#!topic/alt.os.development/8BJva4tA1qM

The virtual 1MB FAT32 partition

* 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:

<code>
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
</code>


Mike Gonta
look and see - many look but few see

http://mikegonta.com
Robert Wessel
2016-03-30 04:45:19 UTC
Permalink
Post by Mike Gonta
https://groups.google.com/forum/#!topic/alt.os.development/8BJva4tA1qM
The virtual 1MB FAT32 partition
* 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
<code>
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
org 0x600 ; loaded at 0x7C00 by BIOS
times 446-($-$$) db 0
dd 0
dd 0x0C ; partition type FAT32
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
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
times 512*63-($-bpb) db 0
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
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
There's a loop in your cluster chain (15->-15->15...).
Post by Mike Gonta
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
</code>
Mike Gonta
2016-03-30 07:57:40 UTC
Permalink
Post by Robert Wessel
Post by Mike Gonta
<code>
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
There's a loop in your cluster chain (15->-15->15...).
Thanks Robert.
That's a typo, when I upgraded the working code from 14
pre-allocated root directory sectors to 16.


Mike Gonta
look and see - many look but few see

http://mikegonta.com

Loading...