From patchwork Tue Dec 31 03:04:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Kardashevskiy X-Patchwork-Id: 1216565 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47mzgc6LC9z9sPh for ; Tue, 31 Dec 2019 14:05:16 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.ru Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 47mzgc3zWGzDq9W for ; Tue, 31 Dec 2019 14:05:16 +1100 (AEDT) X-Original-To: slof@lists.ozlabs.org Delivered-To: slof@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=ozlabs.ru (client-ip=107.174.27.60; helo=ozlabs.ru; envelope-from=aik@ozlabs.ru; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.ru Received: from ozlabs.ru (unknown [107.174.27.60]) by lists.ozlabs.org (Postfix) with ESMTP id 47mzgQ1TW4zDq9Q for ; Tue, 31 Dec 2019 14:05:05 +1100 (AEDT) Received: from fstn1-p1.ozlabs.ibm.com (localhost [IPv6:::1]) by ozlabs.ru (Postfix) with ESMTP id 6A06DAE80571; Mon, 30 Dec 2019 22:03:51 -0500 (EST) From: Alexey Kardashevskiy To: slof@lists.ozlabs.org Date: Tue, 31 Dec 2019 14:04:51 +1100 Message-Id: <20191231030457.5873-5-aik@ozlabs.ru> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191231030457.5873-1-aik@ozlabs.ru> References: <20191231030457.5873-1-aik@ozlabs.ru> Subject: [SLOF] [PATCH slof 04/10] ext2: Prepare for extending X-BeenThere: slof@lists.ozlabs.org X-Mailman-Version: 2.1.29 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" Signed-off-by: Alexey Kardashevskiy --- slof/fs/packages/ext2-files.fs | 43 +++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/slof/fs/packages/ext2-files.fs b/slof/fs/packages/ext2-files.fs index 262c64a34915..392615d17d57 100644 --- a/slof/fs/packages/ext2-files.fs +++ b/slof/fs/packages/ext2-files.fs @@ -39,9 +39,9 @@ INSTANCE VARIABLE dindirect-block INSTANCE VARIABLE inode INSTANCE VARIABLE file-len -INSTANCE VARIABLE blocks +INSTANCE VARIABLE blocks \ data from disk blocks INSTANCE VARIABLE #blocks -INSTANCE VARIABLE ^blocks +INSTANCE VARIABLE ^blocks \ current pointer in blocks INSTANCE VARIABLE #blocks-left : blocks-read ( n -- ) dup negate #blocks-left +! 4 * ^blocks +! ; : read-indirect-blocks ( indirect-block# -- ) @@ -73,20 +73,27 @@ INSTANCE VARIABLE #blocks-left drop \ drop 0, the invalid block number ; +: inode-i-block ( inode -- block ) 28 + ; + +\ Reads block numbers into blocks : read-block#s ( -- ) - blocks @ ?dup IF #blocks @ 4 * free-mem THEN - inode @ 4 + l@-le file-len ! - file-len @ block-size @ // #blocks ! - #blocks @ 4 * alloc-mem blocks ! + blocks @ ?dup IF #blocks @ 4 * free-mem THEN \ free blocks if allocated + inode @ 4 + l@-le file-len ! \ *file-len = i_size_lo + file-len @ block-size @ // #blocks ! \ *#blocks = roundup(file-len/block-size) + #blocks @ 4 * alloc-mem blocks ! \ *blocks = allocmem(*#blocks) blocks @ ^blocks ! #blocks @ #blocks-left ! #blocks-left @ c min \ # direct blocks - inode @ 28 + over 4 * ^blocks @ swap move blocks-read + inode @ inode-i-block over 4 * ^blocks @ swap move blocks-read #blocks-left @ IF inode @ 58 + l@-le read-indirect-blocks THEN #blocks-left @ IF inode @ 5c + l@-le read-double-indirect-blocks THEN - #blocks-left @ IF inode @ 60 + l@-le read-triple-indirect-blocks THEN ; + #blocks-left @ IF inode @ 60 + l@-le read-triple-indirect-blocks THEN +; + : read-inode ( inode# -- ) - 1- inodes/group @ u/mod \ # in group, group # - 20 * group-descriptors @ + 8 + l@-le block-size @ * \ # in group, inode table + 1- inodes/group @ u/mod + 20 * group-descriptors @ + + 8 + l@-le \ reads bg_inode_table_lo + block-size @ * \ # in group, inode table swap inode-size @ * + xlsplit seek drop inode @ inode-size @ read drop ; @@ -153,17 +160,25 @@ INSTANCE VARIABLE current-pos : read-dir ( inode# -- adr ) read-inode read-block#s file-len @ alloc-mem 0 0 seek ABORT" ext2-files read-dir: seek failed" - dup file-len @ read file-len @ <> ABORT" ext2-files read-dir: read failed" ; + dup file-len @ read file-len @ <> ABORT" ext2-files read-dir: read failed" +; + : .dir ( inode# -- ) read-dir dup BEGIN 2dup file-len @ - > over l@-le tuck and WHILE cr dup 8 0.r space read-inode .inode space space dup .name - dup 4 + w@-le + REPEAT 2drop file-len @ free-mem ; + dup 4 + w@-le + REPEAT 2drop file-len @ free-mem +; + : (find-file) ( adr name len -- inode#|0 ) 2>r dup BEGIN 2dup file-len @ - > over l@-le and WHILE dup 8 + over 6 + c@ 2r@ str= IF 2r> 2drop nip l@-le EXIT THEN - dup 4 + w@-le + REPEAT 2drop 2r> 2drop 0 ; + dup 4 + w@-le + REPEAT 2drop 2r> 2drop 0 +; + : find-file ( inode# name len -- inode#|0 ) - 2>r read-dir dup 2r> (find-file) swap file-len @ free-mem ; + 2>r read-dir dup 2r> (find-file) swap file-len @ free-mem +; + : find-path ( inode# name len -- inode#|0 ) dup 0= IF 3drop 0 ." empty name " EXIT THEN over c@ [char] \ = IF 1 /string ." slash " RECURSE EXIT THEN