From patchwork Thu Jul 7 02:09:50 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Herrenschmidt X-Patchwork-Id: 645733 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 3rlLgV4qypz9sxR for ; Thu, 7 Jul 2016 12:10:30 +1000 (AEST) Received: from ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3rlLgV4HKTzDr70 for ; Thu, 7 Jul 2016 12:10:30 +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 3rlLg04WpqzDr7Z for ; Thu, 7 Jul 2016 12:10:04 +1000 (AEST) Received: from pasglop.ozlabs.ibm.com (localhost.localdomain [127.0.0.1]) by gate.crashing.org (8.14.1/8.13.8) with ESMTP id u6729wmt027274; Wed, 6 Jul 2016 21:09:59 -0500 From: Benjamin Herrenschmidt To: slof@lists.ozlabs.org Date: Thu, 7 Jul 2016 12:09:50 +1000 Message-Id: <1467857393-3728-1-git-send-email-benh@kernel.crashing.org> X-Mailer: git-send-email 2.7.4 Subject: [SLOF] [PATCH 1/4] fat-files: Fix access to FAT32 dir/files when cluster > 16-bits 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: , MIME-Version: 1.0 Errors-To: slof-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "SLOF" On FAT32, the directory entry contains a new field providing the top 16-bits of the cluster number. We didn't use it, thus reading the wrong sectors when trying to access files or directories beyond block 0x10000. Signed-off-by: Benjamin Herrenschmidt --- slof/fs/packages/fat-files.fs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/slof/fs/packages/fat-files.fs b/slof/fs/packages/fat-files.fs index d919452..9e389eb 100644 --- a/slof/fs/packages/fat-files.fs +++ b/slof/fs/packages/fat-files.fs @@ -73,6 +73,14 @@ INSTANCE VARIABLE next-cluster THEN ; +\ Read cluster# from directory entry (handle FAT32 extension) +: get-cluster ( direntry -- cluster# ) + fat-type @ 20 = IF + dup 14 + 2c@ bwjoin 10 lshift + ELSE 0 THEN + swap 1a + 2c@ bwjoin + +; + : .time ( x -- ) base @ >r decimal b #split 2 0.r [char] : emit 5 #split 2 0.r [char] : emit 2* 2 0.r @@ -87,7 +95,7 @@ INSTANCE VARIABLE next-cluster dup 0b + c@ 8 and IF drop EXIT THEN \ volume label, not a file dup c@ e5 = IF drop EXIT THEN \ deleted file cr - dup 1a + 2c@ bwjoin [char] # emit 4 0.r space \ starting cluster + dup get-cluster [char] # emit 8 0.r space \ starting cluster dup 18 + 2c@ bwjoin .date space dup 16 + 2c@ bwjoin .time space dup 1c + 4c@ bljoin base @ decimal swap a .r base ! space \ size in bytes @@ -114,8 +122,10 @@ CREATE dos-name b allot : (find-file) ( -- cluster file-len is-dir? true | false ) data @ BEGIN dup data @ #data @ + < WHILE dup dos-name b comp WHILE 20 + REPEAT - dup 1a + 2c@ bwjoin swap dup 1c + 4c@ bljoin swap 0b + c@ 10 and 0<> true + dup get-cluster + swap dup 1c + 4c@ bljoin swap 0b + c@ 10 and 0<> true ELSE drop false THEN ; + : find-file ( dir-cluster name len -- cluster file-len is-dir? true | false ) make-dos-name read-dir BEGIN (find-file) 0= WHILE next-cluster @ WHILE next-cluster @ read-cluster REPEAT false ELSE true THEN ;