commit 4881e058a9055b48c039522d8b2a8885e8637643
parent 25de1c936efea1f84ad7fdaf97197503c9de047a
Author: Virgil Dupras <hsoft@hardcoded.net>
Date: Wed, 29 Jun 2022 15:34:27 -0400
Add sys/drive
Diffstat:
7 files changed, 45 insertions(+), 12 deletions(-)
diff --git a/fs/init.fs b/fs/init.fs
@@ -5,6 +5,11 @@ f<< lib/annotate.fs
f<< sys/doc.fs
f<< lib/io.fs
f<< sys/scratch.fs
+f<< sys/drive.fs
+f<< drv/ramdrive.fs
+fatfs( to ramdrv(
+' ramdrv@ to (drv@)
+' ramdrv! to (drv!)
f<< lib/file.fs
f<< lib/nfmt.fs
f<< lib/diag.fs
diff --git a/fs/sys/drive.fs b/fs/sys/drive.fs
@@ -0,0 +1,31 @@
+\ Drive subsystem
+
+\ Allow access to mass storage in a standardized manner. This subsystem
+\ defines the (drv@) and (drv!) aliases and a storage driver is expected to plug
+\ into it.
+
+\ Blocks: this subsystem deals with the concept of "blocks", which is a bunch
+\ of bytes of a definite size, always the same for a given device. It's the
+\ driver that defines the size of those blocks and sets the "drvblksz" value to
+\ this proper value.
+
+\ (drv@) and (drv!) expect block number arguments, which means that we consider
+\ the data held by the storage device to be an array of contiguous blocks of
+\ "drvblksz" bytes in size.
+
+\ The Drive subsystem holds a temporary buffer and manages it. This buffer can
+\ be larger than "drvblksz" to accommodate the possibility of hot-switching
+\ storage drivers, but it *has* to be at least "drvblksz" in bytes.
+
+$400 const DRVBUFSZ
+create drvbuf( DRVBUFSZ allot
+DRVBUFSZ value drvblksz
+
+( blkno buf -- )
+alias abort (drv@)
+
+( blkno buf -- )
+alias abort (drv!)
+
+: drv@ ( blkno -- ) drvbuf( (drv@) ;
+: drv! ( blkno -- ) drvbuf( (drv!) ;
diff --git a/fs/tests/all.fs b/fs/tests/all.fs
@@ -1,6 +1,6 @@
\ Run all test suites
f<< tests/kernel.fs
f<< tests/lib/all.fs
-f<< tests/drv/all.fs
+f<< tests/sys/all.fs
f<< tests/asm.fs
f<< tests/cc/all.fs
diff --git a/fs/tests/drv/all.fs b/fs/tests/drv/all.fs
@@ -1,2 +0,0 @@
-\ Run all drv test suites
-f<< tests/drv/ramdrive.fs
diff --git a/fs/tests/drv/ramdrive.fs b/fs/tests/drv/ramdrive.fs
@@ -1,9 +0,0 @@
-?f<< tests/harness.fs
-?f<< drv/ramdrive.fs
-require sys/scratch.fs
-testbegin
-\ Tests for drv/ramdrive
-fatfs( to ramdrv(
-0 here ramdrv@
-here $36 + 8 []>str S" FAT16 " #s=
-testend
diff --git a/fs/tests/sys/all.fs b/fs/tests/sys/all.fs
@@ -0,0 +1,2 @@
+\ Run all sys test suites
+f<< tests/sys/drive.fs
diff --git a/fs/tests/sys/drive.fs b/fs/tests/sys/drive.fs
@@ -0,0 +1,6 @@
+?f<< tests/harness.fs
+testbegin
+\ Tests for sys/ramdrive (already loaded in init.fs)
+0 drv@
+drvbuf( $36 + 8 []>str S" FAT16 " #s=
+testend