commit e078faf0039f9fdcb54093bab93ea797e1160fb0
parent a69056e53690671991c4774bd06cef6e6222a99f
Author: Virgil Dupras <hsoft@hardcoded.net>
Date: Mon, 8 Aug 2022 12:13:59 -0400
fs/fat: assert that FAT and drive sector sizes match
Diffstat:
4 files changed, 7 insertions(+), 6 deletions(-)
diff --git a/fs/doc/drive.txt b/fs/doc/drive.txt
@@ -10,16 +10,16 @@ The drive API exposes the features of the underlying driver through a specific
data structure, called a Drive, which is 12 bytes in length in the form of 3
fields of 4 bytes:
-sectorsize
+drvsecsz
drv@
drv!
-sectorsize is an integer describing, in bytes, the size of sectors read and
+drvsecsz is an integer describing, in bytes, the size of sectors read and
written by the driver. It's often 512 bytes.
drv@ ( sec dst drv -- )
Read sector "sec" in memory address "dst", which needs to be a buffer at least
- "sectorsize" in size. "drv" is a pointer to a Drive structure.
+ "drvsecsz" in size. "drv" is a pointer to a Drive structure.
drv! ( sec src drv -- )
Write sector "sec" from memory address "src".
diff --git a/fs/fs/fat.fs b/fs/fs/fat.fs
@@ -77,7 +77,7 @@ $ffff const EOC
\ write multiple sectors from buf
: writesectors ( sec u buf -- )
A>r swap >r swap >A begin ( buf )
- A> over fatdrv drv! A+ fatdrv sectorsize + next ( buf ) drop r>A ;
+ A> over fatdrv drv! A+ fatdrv drvsecsz + next ( buf ) drop r>A ;
: writecluster ( cluster src -- )
over 2 - $fff6 > if abort" cluster out of range!" then
diff --git a/fs/fs/fatlo.fs b/fs/fs/fatlo.fs
@@ -15,10 +15,11 @@
\ See fs/fat.fs for complete implementation details.
-\ TODO: assert that fatdrv's sector size is the same as in the FAT's BPB
create bpb 0 here fatdrv drv@ $18 allot
: BPB_BytsPerSec bpb $0b + w@ ;
+BPB_BytsPerSec fatdrv drvsecsz = not [if]
+ ." Drive sector size not matching drive!" abort [then]
: BPB_SecPerClus bpb $0d + c@ ;
: BPB_RsvdSecCnt bpb $0e + w@ ;
: BPB_NumFATs bpb $10 + c@ ;
diff --git a/fs/xcomp/bootlo.fs b/fs/xcomp/bootlo.fs
@@ -161,7 +161,7 @@ alias noop [then]
\ Drive API
\ Anticipating lib/drive
-: sectorsize ( drv -- ) @ ;
+: drvsecsz ( drv -- ) @ ;
: drv@ ( sec dst drv -- ) dup 4 + @ execute ;
: drv! ( sec src drv -- ) dup 8 + @ execute ;