Skip to content

Commit af804e2

Browse files
committed
Merge branch 'fs-node-refactor'
2 parents 46cd2ba + 0bda45f commit af804e2

File tree

4 files changed

+183
-264
lines changed

4 files changed

+183
-264
lines changed

include/defines.inc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ errNoEntryPoint .equ 15
1818
errKernelMismatch .equ 15
1919
errMutexNotLocked .equ 16
2020
errReadOnly .equ 17
21+
errNotAFile .equ 18
22+
errNotADirectory .equ 18
2123

2224
threadRangeMask .equ 0b11111
2325

src/00/filestreams.asm

Lines changed: 69 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,45 @@ initFilesystem:
77
ldir
88
ret
99

10+
; If findNode turned up a symlink, this will follow it and
11+
; give the findNode return value for the final destination.
12+
followSymLink:
13+
#define newName kernelGarbage + 2 ; findNode uses kernelGarbage
14+
push de
15+
dec hl ; ID
16+
dec hl \ dec hl ; Entry len
17+
dec hl \ dec hl ; Parent ID
18+
ld b, 0
19+
ld c, (hl) \ dec hl ; Name length
20+
scf \ ccf
21+
sbc hl, bc
22+
23+
.recurse:
24+
ld de, newName
25+
.load_target_loop:
26+
ld a, (hl)
27+
ld (de), a
28+
inc de \ dec hl
29+
; NOTE: KFS spec doesn't mention the trailing zero, this should be standardized
30+
or a
31+
jr nz, .load_target_loop
32+
33+
ld de, newName
34+
call findNode
35+
jr nz, .not_found
36+
37+
setBankA
38+
ld a, (hl)
39+
40+
cp fsSymLink
41+
jr z, .recurse
42+
43+
cp a
44+
.not_found:
45+
pop de
46+
ret
47+
#undefine newName
48+
1049
;; openFileRead [Filestreams]
1150
;; Opens a file stream in read-only mode.
1251
;; Inputs:
@@ -19,15 +58,30 @@ initFilesystem:
1958
openFileRead:
2059
push hl
2160
push bc
22-
call findFileEntry
23-
jp nz, .fileNotFound
24-
ld b, a
2561
push af
2662
ld a, i
2763
push af
2864
di
2965
push iy
3066
push bc
67+
push de
68+
.linkLoop:
69+
call findNode
70+
jp nz, .fileNotFound
71+
72+
; Check if node is file or symlink or other
73+
setBankA
74+
ld a, (hl)
75+
cp fsFile
76+
jr z, .validNode
77+
78+
cp fsSymLink
79+
jp nz, .fileNotFound ; TODO: use something like errNotAFile?
80+
81+
call followSymLink
82+
jp nz, .fileNotFound
83+
.validNode:
84+
pop de
3185
ld iy, fileHandleTable
3286
ld bc, FILE_HANDLE_SIZE
3387
ld d, 0
@@ -130,10 +184,20 @@ _: pop af
130184
_: pop af
131185
pop bc
132186
pop hl
187+
cp a
133188
ret
134189
.fileNotFound:
190+
pop de
191+
pop bc
192+
pop iy
193+
pop af
194+
jp po, _
195+
ei
196+
_: pop af
135197
pop bc
136198
pop hl
199+
ld a, errFileNotFound
200+
cp 0
137201
ret
138202
.outOfMemory:
139203
pop ix
@@ -198,7 +262,7 @@ _: pop af
198262
ret
199263
.entryFound:
200264
push hl
201-
call findFileEntry
265+
call findNode ; TODO: Check if this is a file, follow symlinks, etc
202266
jp nz, .fileNotFound
203267
pop de
204268
ld d, e
@@ -540,7 +604,7 @@ _: pop af
540604
ld (hl), a
541605
push hl
542606
ld de, kernelGarbage + 0x100
543-
call findDirectoryEntry
607+
call findNode ; TODO: Check that this is a directory node
544608
jp nz, .wtf
545609
setBankA
546610
pop de

0 commit comments

Comments
 (0)