duskos

dusk os fork
git clone git://git.alexwennerberg.com/duskos
Log | Files | Refs | README | LICENSE

commit 2a0b4df730a6991fc76475c6e016f7677b3fd981
parent 0c9a2b553c59f74be6b0e158b41249edb0e7276c
Author: Virgil Dupras <hsoft@hardcoded.net>
Date:   Fri,  1 Jul 2022 20:54:31 -0400

fs/boot: Add FAT12 support

Diffstat:
MMakefile | 4++--
Mfs/fs/boot.fs | 22+++++++++++++++-------
Mfs/tests/sys/drive.fs | 2+-
3 files changed, 18 insertions(+), 10 deletions(-)

diff --git a/Makefile b/Makefile @@ -15,8 +15,8 @@ boot.fs: $(BOOTFS_SRC) cat $(BOOTFS_SRC) > $@ fatfs: fs - dd if=/dev/zero of=$@ bs=4M count=1 - mformat -d 1 -i $@ :: + dd if=/dev/zero of=$@ bs=1M count=1 + mformat -M 512 -d 1 -i $@ :: mcopy -sQ -i $@ fs/* :: .PHONY: run diff --git a/fs/fs/boot.fs b/fs/fs/boot.fs @@ -9,8 +9,7 @@ \ This unit has access to a very small set of words, that it, words implemented \ by boot.fs as well as the "drive" protocol, which is implemented by a driver \ that is inserted between boot.fs and this unit. -create bpb drvblksz allot -0 bpb (drv@) +create bpb 0 here (drv@) $18 allot : BPB_BytsPerSec bpb $0b + w@ ; : BPB_SecPerClus bpb $0d + c@ ; @@ -25,15 +24,18 @@ create bpb drvblksz allot : FirstSectorOfCluster ( n -- sec ) 1- 1- BPB_SecPerClus * FirstDataSector + ; : FirstRootDirSecNum BPB_RsvdSecCnt BPB_NumFATs BPB_FATSz16 * + ; : ClusterSize BPB_SecPerClus BPB_BytsPerSec * ; +: DataSec + BPB_TotSec16 BPB_FATSz16 BPB_NumFATs * BPB_RsvdSecCnt + RootDirSectors + - ; +: CountOfClusters DataSec BPB_SecPerClus / ; +: FAT12? CountOfClusters 4085 < ; \ read multiple sectors in buf : readsectors ( sec u buf -- ) A>r swap >r swap >A begin ( buf ) A> over (drv@) A+ drvblksz + next ( buf ) drop r>A ; -create FAT16( BPB_BytsPerSec BPB_FATSz16 * allot -here value )FAT16 -: readFAT BPB_RsvdSecCnt BPB_FATSz16 FAT16( readsectors ; +create FAT( BPB_BytsPerSec BPB_FATSz16 * allot +: readFAT BPB_RsvdSecCnt BPB_FATSz16 FAT( readsectors ; 32 const DIRENTRYSZ 11 const FNAMESZ @@ -71,10 +73,16 @@ here const )fnbuf \ Make the current dir the root : readroot FirstRootDirSecNum RootDirSectors dirbuf( readsectors ; -: EOC? ( cluster -- f ) $fff8 and $fff8 = ; +: EOC? ( cluster -- f ) + FAT12? if $ff8 else $fff8 then tuck and = ; \ get cluster following this one in the FAT -: nextcluster ( cluster -- nextcluster ) << FAT16( + w@ ; +: nextcluster ( cluster -- nextcluster ) + FAT12? if + dup dup >> + ( cl off ) + FAT( + w@ ( cl ncl ) swap 1 and if 4 rshift else $fff and then + else + << FAT( + w@ then ; : readcluster ( cluster dst -- ) over << BPB_BytsPerSec BPB_FATSz16 * >= if abort" cluster out of range" then diff --git a/fs/tests/sys/drive.fs b/fs/tests/sys/drive.fs @@ -1,5 +1,5 @@ ?f<< tests/harness.fs testbegin \ Tests for sys/ramdrive (already loaded in init.fs) -$36 8 drvseek ( a ) 8 []>str S" FAT16 " #s= +$36 8 drvseek ( a ) 8 []>str S" FAT12 " #s= testend