commit e3bb483c1fc930600d7a2acd7e03c6189bcff48b
parent 3b9204ebe9a2dd94a28ade6ef27f43cca42770ae
Author: Virgil Dupras <hsoft@hardcoded.net>
Date: Fri, 12 Aug 2022 14:01:33 -0400
fs/fat: move nextsector? to FAT struct
Diffstat:
2 files changed, 19 insertions(+), 18 deletions(-)
diff --git a/fs/fs/fat.fs b/fs/fs/fat.fs
@@ -63,11 +63,11 @@ $ffff const EOC
: findfreedirentry ( -- direntry )
begin
_findinsec ?dup not while ( )
- nextsector? while
+ FATFS :nextsector? while
repeat \ nothing found, we have to extend the chain
findfreecluster dup zerocluster ( newcl )
- dup bufcluster FAT! ( newcl ) EOC swap FAT!
- nextsector? ( has to work ) fatbuf(
+ dup FATFS bufcluster FAT! ( newcl ) EOC swap FAT!
+ FATFS :nextsector? ( has to work ) fatbuf(
else \ found, a if good
then ;
diff --git a/fs/fs/fatlo.fs b/fs/fs/fatlo.fs
@@ -18,6 +18,7 @@
extends Filesystem struct[ FAT
sfield bufsec \ sector number of current buf
sfield bufseccnt \ number of sectors ahead for sequential read
+sfield bufcluster \ cluster number of current buf
' FAT structsz const SZ
SZ &+ :hdr(
@@ -74,6 +75,18 @@ r@ :buf( r> Filesystem drv Drive :sec@ ;
: :EOC? ( cluster self -- f )
:FAT12? if $ff8 else $fff8 then tuck and = ;
+\ Read next sector if a sequential read is available, else return false.
+: :nextsector? ( self -- f ) >r
+ r@ bufseccnt if \ still on a sector streak
+ r@ bufseccnt 1+ r@ bufseccnt 1- r> :readsector 1
+ else \ out of sector, try next cluster
+ r@ bufcluster r@ :FAT@ dup r@ :EOC? if
+ rdrop drop 0
+ else \ we have another cluster
+ dup to r@ bufcluster r@ :FirstSectorOfCluster
+ r@ secpercluster r> :readsector 1 then
+ then ;
+
]struct
$1000 const FATMAXSECSZ
@@ -81,7 +94,7 @@ $1000 const FATMAXSECSZ
\ TODO: support more than one FAT FS at once
align4
create _FATFS
- fatdrv , 0 , 0 , ' abort , 0 , 0 ,
+ fatdrv , 0 , 0 , ' abort , 0 , 0 , 0 ,
FAT HDRSZ allot
\ Allocate buffer
FATMAXSECSZ 1+ allot
@@ -91,8 +104,6 @@ _FATFS structbind FAT FATFS
: fatbuf( FATFS :buf( ;
: )fatbuf FATFS :)buf ;
-0 value bufcluster \ cluster number of current buf
-
: readFATvolume ( -- )
0 fatbuf( fatdrv Drive :sec@
fatbuf( FATFS :hdr( FAT HDRSZ move
@@ -100,16 +111,6 @@ _FATFS structbind FAT FATFS
abort" Drive sector size not matching drive!" then ;
readFATvolume
-\ Read next sector if a sequential read is available, else return false.
-: nextsector? ( -- f )
- FATFS bufseccnt if \ still on a sector streak
- FATFS bufseccnt 1+ FATFS bufseccnt 1- FATFS :readsector 1
- else \ out of sector, try next cluster
- bufcluster FATFS :FAT@ dup FATFS :EOC? if drop 0 else \ we have another cluster
- dup to bufcluster FATFS :FirstSectorOfCluster
- FATFS secpercluster FATFS :readsector 1
- then then ;
-
32 const DIRENTRYSZ
11 const FNAMESZ
: DIR_Name ( direntry -- sa sl ) FNAMESZ ;
@@ -146,7 +147,7 @@ here const )fnbuf
\ Find current fnbuf( in current dir buffer and return a dir entry.
: findindir ( -- direntry )
begin
- _ ?dup not while nextsector? while
+ _ ?dup not while FATFS :nextsector? while
repeat ( not found ) 0 then ;
\ Read specified "direntry" in fatbuf(
@@ -154,7 +155,7 @@ here const )fnbuf
DIR_Cluster ?dup if \ not root entry
dup FATFS :FirstSectorOfCluster FATFS secpercluster else \ root entry
1 FATFS :FirstRootDirSecNum FATFS :RootDirSectors then ( cluster sec cnt )
- FATFS :readsector ( cluster ) to bufcluster ;
+ FATFS :readsector ( cluster ) to FATFS bufcluster ;
\ Get DirEntry address from FS ID "id"
: getdirentry ( id -- direntry )