From patchwork Thu Jun 9 03:47:43 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Benjamin Herrenschmidt X-Patchwork-Id: 632615 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3rQB8r5CQKz9sf9 for ; Thu, 9 Jun 2016 13:47:56 +1000 (AEST) Received: from ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3rQB8r4R0NzDqST for ; Thu, 9 Jun 2016 13:47:56 +1000 (AEST) X-Original-To: slof@lists.ozlabs.org Delivered-To: slof@lists.ozlabs.org Received: from gate.crashing.org (gate.crashing.org [63.228.1.57]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3rQB8j71WhzDqR3 for ; Thu, 9 Jun 2016 13:47:49 +1000 (AEST) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by gate.crashing.org (8.14.1/8.13.8) with ESMTP id u593liSD032269 for ; Wed, 8 Jun 2016 22:47:45 -0500 Message-ID: <1465444063.2948.25.camel@kernel.crashing.org> From: Benjamin Herrenschmidt To: slof@lists.ozlabs.org Date: Thu, 09 Jun 2016 13:47:43 +1000 X-Mailer: Evolution 3.18.5.2 (3.18.5.2-1.fc23) Mime-Version: 1.0 Subject: [SLOF] [PATCH] fat-files: Add dir support X-BeenThere: slof@lists.ozlabs.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: "Patches for https://github.com/aik/SLOF" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: slof-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "SLOF" Add a "dir" methods to FAT filesystem, example: Signed-off-by: Benjamin Herrenschmidt ---  slof/fs/packages/fat-files.fs | 12 +++++++-----  1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/slof/fs/packages/fat-files.fs b/slof/fs/packages/fat-files.fs index ac2f141..906f0ee 100644 --- a/slof/fs/packages/fat-files.fs +++ b/slof/fs/packages/fat-files.fs @@ -209,6 +209,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 @@ -220,25 +221,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  ;