diff mbox

[4/4] fat-files: Add dir support

Message ID 1467857393-3728-4-git-send-email-benh@kernel.crashing.org
State Accepted
Headers show

Commit Message

Benjamin Herrenschmidt July 7, 2016, 2:09 a.m. UTC
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
---
 slof/fs/packages/fat-files.fs | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
diff mbox

Patch

diff --git a/slof/fs/packages/fat-files.fs b/slof/fs/packages/fat-files.fs
index e5b08bd..b5b6bdd 100644
--- a/slof/fs/packages/fat-files.fs
+++ b/slof/fs/packages/fat-files.fs
@@ -208,6 +208,7 @@  INSTANCE VARIABLE current-pos
 INSTANCE VARIABLE pos-in-data
 
 : seek ( lo hi -- status )
+  dir? @ IF ABORT" fat-files: trying to seek a dir" THEN
   lxjoin dup current-pos ! file-cluster @ read-cluster
   \ Read and skip blocks until we are where we want to be.
   BEGIN dup #data @ >= WHILE #data @ - next-cluster @ dup 0= IF
@@ -219,25 +220,26 @@  INSTANCE VARIABLE pos-in-data
   r@ pos-in-data +!  r@ current-pos +!  pos-in-data @ #data @ = IF
   next-cluster @ ?dup IF read-cluster 0 pos-in-data ! THEN THEN r> ;
 : read ( adr len -- actual )
+  dir? @ IF ABORT" fat-files: trying to read a dir" THEN
   file-len @ min                \ len cannot be greater than file size
   dup >r BEGIN dup WHILE 2dup read dup 0= ABORT" fat-files: read failed"
   /string ( tuck - >r + r> ) REPEAT 2drop r> ;
 : load ( adr -- len )
+  dir? @ IF ABORT" fat-files: trying to load a dir" THEN
   file-len @ read dup file-len @ <> ABORT" fat-files: failed loading file" ;
 
 : close  free-data ;
 
 : dir
-  dir? @ IF file-cluster @ .dir ELSE ." not a directory!" cr THEN
+  dir? @ IF file-cluster @ .dir ELSE cr ." not a directory!" THEN
   ;
 
 : open
   do-super
   0 my-args find-path
-  0= IF free-data false EXIT
-  THEN
-  dir? ! file-len !  file-cluster !
-  dir? @ IF
+  0= IF close false EXIT THEN
+  dir? ! file-len ! file-cluster !
+  dir? @ 0= IF
     0 0 seek 0=
   ELSE true THEN
 ;