commit 74cdd42fdce528dee551bfd67b56d815f00542c4
parent 82fd267a3771c45e7c7814d821c1b95d454beceb
Author: Virgil Dupras <hsoft@hardcoded.net>
Date: Thu, 11 Aug 2022 07:56:25 -0400
fs/fat: melt away some words
Diffstat:
2 files changed, 27 insertions(+), 30 deletions(-)
diff --git a/fs/fs/fat.fs b/fs/fs/fat.fs
@@ -37,8 +37,8 @@ $ffff const EOC
: FAT! ( entry cluster ) FAT12? if FAT12! else FAT16! then writecursector ;
: zerocluster ( cluster -- )
- fatbuf( BPB_BytsPerSec 0 fill
- FirstSectorOfCluster ( sec ) BPB_SecPerClus >r begin ( sec )
+ fatbuf( FATFS secsz 0 fill
+ FirstSectorOfCluster ( sec ) FATFS secpercluster >r begin ( sec )
fatbuf( fatdrv :sec! 1+ next drop ;
\ find a free cluster in the FAT
@@ -82,7 +82,8 @@ $ffff const EOC
: writecluster ( cluster src -- )
over 2 - $fff6 > if abort" cluster out of range!" then
- swap FirstSectorOfCluster ( dst sec ) swap BPB_SecPerClus swap writesectors ;
+ swap FirstSectorOfCluster ( dst sec )
+ swap FATFS secpercluster swap writesectors ;
: fatflush ( fcursor -- )
dup FCUR_dirty? not if drop exit then ( fcursor )
diff --git a/fs/fs/fatlo.fs b/fs/fs/fatlo.fs
@@ -63,38 +63,33 @@ _FATFS structbind FATFields FATFS
abort" Drive sector size not matching drive!" then ;
readFATvolume
-: BPB_BytsPerSec FATFS secsz ;
-: BPB_SecPerClus FATFS secpercluster ;
-: BPB_RsvdSecCnt FATFS reservedseccnt ;
-: BPB_NumFATs FATFS FATcnt ;
-: BPB_RootEntCnt FATFS rootentcnt ;
-: BPB_TotSec16 FATFS seccnt ;
-: BPB_FATSz16 FATFS FATsz ;
: RootDirSectors
- BPB_RootEntCnt 32 * BPB_BytsPerSec /mod ( r q ) swap if 1+ then ;
-: FirstDataSector BPB_RsvdSecCnt BPB_NumFATs BPB_FATSz16 * + RootDirSectors + ;
+ FATFS rootentcnt 32 * FATFS secsz /mod ( r q ) swap if 1+ then ;
+: FirstDataSector
+ FATFS reservedseccnt FATFS FATcnt FATFS FATsz * + RootDirSectors + ;
: FirstSectorOfCluster ( n -- sec )
- dup << BPB_BytsPerSec BPB_FATSz16 * >= if abort" cluster out of range" then
- 1- 1- BPB_SecPerClus * FirstDataSector + ;
-: FirstRootDirSecNum BPB_RsvdSecCnt BPB_NumFATs BPB_FATSz16 * + ;
-: ClusterSize BPB_SecPerClus BPB_BytsPerSec * ;
+ dup << FATFS secsz FATFS FATsz * >= if abort" cluster out of range" then
+ 1- 1- FATFS secpercluster * FirstDataSector + ;
+: FirstRootDirSecNum FATFS reservedseccnt FATFS FATcnt FATFS FATsz * + ;
+: ClusterSize FATFS secpercluster FATFS secsz * ;
: DataSec
- BPB_TotSec16 BPB_FATSz16 BPB_NumFATs * BPB_RsvdSecCnt + RootDirSectors + - ;
-: CountOfClusters DataSec BPB_SecPerClus / ;
+ FATFS seccnt FATFS FATsz FATFS FATcnt *
+ FATFS reservedseccnt + RootDirSectors + - ;
+: CountOfClusters DataSec FATFS secpercluster / ;
: FAT12? CountOfClusters 4085 < ;
: FAT12' ( cluster -- 'entry )
- dup >> + ( cl offset ) BPB_BytsPerSec /mod ( cl secoff sec )
- BPB_RsvdSecCnt +
- over 1+ BPB_BytsPerSec = if \ end-of-sector cross-over!
+ dup >> + ( cl offset ) FATFS secsz /mod ( cl secoff sec )
+ FATFS reservedseccnt +
+ over 1+ FATFS secsz = if \ end-of-sector cross-over!
dup 1 + fatbuf( bufdrv :sec@ fatbuf( c@ )fatbuf c! then
0 readsector ( cl secoff )
fatbuf( + ;
: FAT12@ ( cluster -- entry )
dup FAT12' w@ swap 1 and if 4 rshift else $fff and then ;
: FAT16' ( cluster -- 'entry )
- << ( offset ) BPB_BytsPerSec /mod ( secoff sec )
- BPB_RsvdSecCnt + 0 readsector ( secoff )
+ << ( offset ) FATFS secsz /mod ( secoff sec )
+ FATFS reservedseccnt + 0 readsector ( secoff )
fatbuf( + ;
: FAT16@ ( cluster -- entry ) FAT16' w@ ;
: FAT@ ( cluster -- entry ) FAT12? if FAT12@ else FAT16@ then ;
@@ -108,7 +103,7 @@ readFATvolume
bufseccnt 1+ bufseccnt 1- readsector 1
else \ out of sector, try next cluster
bufcluster FAT@ dup EOC? if drop 0 else \ we have another cluster
- dup to bufcluster FirstSectorOfCluster BPB_SecPerClus readsector 1
+ dup to bufcluster FirstSectorOfCluster FATFS secpercluster readsector 1
then then ;
32 const DIRENTRYSZ
@@ -153,18 +148,18 @@ here const )fnbuf
\ Read specified "direntry" in fatbuf(
: readdir ( direntry -- )
DIR_Cluster ?dup if \ not root entry
- dup FirstSectorOfCluster BPB_SecPerClus else \ root entry
+ dup FirstSectorOfCluster FATFS secpercluster else \ root entry
1 FirstRootDirSecNum RootDirSectors then ( cluster sec cnt )
readsector ( cluster ) to bufcluster ;
\ Get DirEntry address from FS ID "id"
: getdirentry ( id -- direntry )
?dup if
- BPB_BytsPerSec /mod ( offset sec ) 1 readsector ( off ) fatbuf( +
+ FATFS secsz /mod ( offset sec ) 1 readsector ( off ) fatbuf( +
else rootdirentry( then ;
\ Get ID for direntry
-: getid ( direntry -- id ) fatbuf( - bufsec BPB_BytsPerSec * + ;
+: getid ( direntry -- id ) fatbuf( - bufsec FATFS secsz * + ;
: FATFS:child ( dirid name self -- id-or-0 )
drop fnbuf! getdirentry readdir findindir dup if getid then ;
@@ -211,11 +206,12 @@ create fcursors( FCursorSize FCURSORCNT * allot0
\ read multiple sectors in buf
: readsectors ( sec u buf -- )
A>r swap >r swap >A begin ( buf )
- A> over bufdrv :sec@ A+ BPB_BytsPerSec + next ( buf ) drop r>A ;
+ A> over bufdrv :sec@ A+ FATFS secsz + next ( buf ) drop r>A ;
: readcluster ( cluster dst -- )
over 2 - $fff6 > if abort" cluster out of range!" then
- swap FirstSectorOfCluster ( dst sec ) swap BPB_SecPerClus swap readsectors ;
+ swap FirstSectorOfCluster ( dst sec )
+ swap FATFS secpercluster swap readsectors ;
\ set fcursor to pos. If new pos crosses cluster boundaries compared to current
\ pos, flush current buffer and read a new sector from disk.
@@ -252,7 +248,7 @@ create fcursors( FCursorSize FCURSORCNT * allot0
['] fatseek r@ 12 + ! ['] fatclose r@ 16 + !
\ write the rest
0 r@ FCUR_cluster! ( dirent ) 1 r@ FCUR_flags!
- dup fatbuf( - bufsec BPB_BytsPerSec * + ( dirent doffset ) r@ 32 + !
+ dup fatbuf( - bufsec FATFS secsz * + ( dirent doffset ) r@ 32 + !
-1 r@ FCUR_clusteridx! 0 r@ FCUR_pos!
DIR_FileSize r@ FCUR_size! ( ) r> ;
current _FATFS 8 + !