commit 202d6b3c06a34664b2f3b671bd8f280cecb4420f
parent 9e2d5e61a728d2ecd9544448e1c4074043c60c63
Author: Virgil Dupras <hsoft@hardcoded.net>
Date: Fri, 12 Aug 2022 13:03:03 -0400
fs/fat: move fatbuf( in _FATFS structure
One step at a time...
Diffstat:
1 file changed, 23 insertions(+), 23 deletions(-)
diff --git a/fs/fs/fatlo.fs b/fs/fs/fatlo.fs
@@ -17,29 +17,9 @@
$1000 const FATMAXSECSZ
-\ FAT buffer
-\ The FAT buffer is where we read sectors from FATs and from directory entries.
-\ This data is very short lived and never persists across single calls. We
-\ therefore, for the sake of simplicity, share it among all mounted FAT FSes.
-\ Buffer for either reading FAT sectors or Directory contents. It is one sector
-\ in size and knows the number of sequential sector read it has in front of it.
-align4
-create fatbuf( FATMAXSECSZ 1+ allot
-\ 1+ is for the extra byte for FAT12 cross-sector exception
-
-0 value bufsec \ sector number of current buf
-0 value bufseccnt \ number of sectors ahead for sequential read
-0 value bufcluster \ cluster number of current buf
-: )fatbuf fatbuf( fatdrv Drive secsz + ;
-
-\ "cnt" is the number of sectors ahead of "sec" that are available for a
-\ seqential read.
-: readsector ( sec cnt -- )
- to bufseccnt dup to bufsec fatbuf( fatdrv Drive :sec@ ;
-
extends Filesystem struct[ FATFields
' FATFields structsz const SZ
- SZ &+ hdr(
+ SZ &+ :hdr(
SZ $0b + &+w@ secsz \ in bytes
SZ $0d + &+c@ secpercluster
SZ $0e + &+w@ reservedseccnt \ number of sectors reserved before FAT starts
@@ -47,21 +27,41 @@ extends Filesystem struct[ FATFields
SZ $11 + &+w@ rootentcnt \ count of 32b entries
SZ $13 + &+w@ seccnt
SZ $16 + &+w@ FATsz \ in bytes
- $1a const HDRSZ
+ $1c const HDRSZ
+ \ buffer for reading FAT tables and dir entries. one sector in length.
+ SZ HDRSZ + &+ :buf(
+ : :)buf dup :buf( swap secsz + ;
]struct
+
\ TODO: support more than one FAT FS at once
+align4
create _FATFS
' fatdrv , 0 , 0 , ' abort , 7 CELLSZ * allot FATFields HDRSZ allot
+ \ Allocate buffer
+ FATMAXSECSZ 1+ allot
+ \ 1+ is for the extra byte for FAT12 cross-sector exception
_FATFS structbind FATFields FATFS
+: fatbuf( FATFS :buf( ;
+: )fatbuf FATFS :)buf ;
+
: readFATvolume ( -- )
0 fatbuf( fatdrv Drive :sec@
- fatbuf( FATFS hdr( FATFields HDRSZ move
+ fatbuf( FATFS :hdr( FATFields HDRSZ move
FATFS secsz fatdrv Drive secsz = not if
abort" Drive sector size not matching drive!" then ;
readFATvolume
+0 value bufsec \ sector number of current buf
+0 value bufseccnt \ number of sectors ahead for sequential read
+0 value bufcluster \ cluster number of current buf
+
+\ "cnt" is the number of sectors ahead of "sec" that are available for a
+\ seqential read.
+: readsector ( sec cnt -- )
+ to bufseccnt dup to bufsec fatbuf( fatdrv Drive :sec@ ;
+
: RootDirSectors
FATFS rootentcnt 32 * FATFS secsz /mod ( r q ) swap if 1+ then ;
: FirstDataSector