From fc6f690727aac2b5c9bd368f9b13188fb0ba36a7 Mon Sep 17 00:00:00 2001 From: user Date: Thu, 16 Jul 2026 13:07:28 +0200 Subject: fs: reject open()/read() on a directory (EISDIR) open() now checks the target's inode type: opening a directory as a file returns $FE (EISDIR) instead of a valid fd, so 'cat docs' no longer streams the raw directory block as bytes. cat reports 'is a directory'; wc/head/save treat any invalid fd (>3) as an open failure. (ls is unaffected - it uses the structural opendir/list path, not open/getb.) --- src/fs.asm | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/fs.asm') diff --git a/src/fs.asm b/src/fs.asm index d543b0f..a4ad77e 100644 --- a/src/fs.asm +++ b/src/fs.asm @@ -678,6 +678,13 @@ sys_open:: ld [wFsDir], a call dir_find ; A = target inode or 0 ld [wFsInode], a + or a + jr z, .notdir ; doesn't exist yet: no type to check + call inode_ptr + ld a, [hl] ; I_TYPE + cp IT_DIR + jr z, .isdir ; can't open a directory as a file +.notdir ld a, [wFsMode] or a jr nz, .write @@ -730,6 +737,9 @@ sys_open:: ld a, c cp OF_MAX jr c, .ofl +.isdir + ld a, $FE ; EISDIR: is a directory + ret .fail ld a, $FF ret -- cgit v1.3.1-sl0p