Skip to content

Commit

Permalink
Merge branch 'fs-node-refactor'
Browse files Browse the repository at this point in the history
  • Loading branch information
ddevault committed Jul 19, 2015
2 parents 46cd2ba + 0bda45f commit af804e2
Show file tree
Hide file tree
Showing 4 changed files with 183 additions and 264 deletions.
2 changes: 2 additions & 0 deletions include/defines.inc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ errNoEntryPoint .equ 15
errKernelMismatch .equ 15
errMutexNotLocked .equ 16
errReadOnly .equ 17
errNotAFile .equ 18
errNotADirectory .equ 18

threadRangeMask .equ 0b11111

Expand Down
74 changes: 69 additions & 5 deletions src/00/filestreams.asm
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,45 @@ initFilesystem:
ldir
ret

; If findNode turned up a symlink, this will follow it and
; give the findNode return value for the final destination.
followSymLink:
#define newName kernelGarbage + 2 ; findNode uses kernelGarbage
push de
dec hl ; ID
dec hl \ dec hl ; Entry len
dec hl \ dec hl ; Parent ID
ld b, 0
ld c, (hl) \ dec hl ; Name length
scf \ ccf
sbc hl, bc

.recurse:
ld de, newName
.load_target_loop:
ld a, (hl)
ld (de), a
inc de \ dec hl
; NOTE: KFS spec doesn't mention the trailing zero, this should be standardized
or a
jr nz, .load_target_loop
ld de, newName
call findNode
jr nz, .not_found

setBankA
ld a, (hl)

cp fsSymLink
jr z, .recurse

cp a
.not_found:
pop de
ret
#undefine newName

;; openFileRead [Filestreams]
;; Opens a file stream in read-only mode.
;; Inputs:
Expand All @@ -19,15 +58,30 @@ initFilesystem:
openFileRead:
push hl
push bc
call findFileEntry
jp nz, .fileNotFound
ld b, a
push af
ld a, i
push af
di
push iy
push bc
push de
.linkLoop:
call findNode
jp nz, .fileNotFound

; Check if node is file or symlink or other
setBankA
ld a, (hl)
cp fsFile
jr z, .validNode

cp fsSymLink
jp nz, .fileNotFound ; TODO: use something like errNotAFile?

call followSymLink
jp nz, .fileNotFound
.validNode:
pop de
ld iy, fileHandleTable
ld bc, FILE_HANDLE_SIZE
ld d, 0
Expand Down Expand Up @@ -130,10 +184,20 @@ _: pop af
_: pop af
pop bc
pop hl
cp a
ret
.fileNotFound:
pop de
pop bc
pop iy
pop af
jp po, _
ei
_: pop af
pop bc
pop hl
ld a, errFileNotFound
cp 0
ret
.outOfMemory:
pop ix
Expand Down Expand Up @@ -198,7 +262,7 @@ _: pop af
ret
.entryFound:
push hl
call findFileEntry
call findNode ; TODO: Check if this is a file, follow symlinks, etc
jp nz, .fileNotFound
pop de
ld d, e
Expand Down Expand Up @@ -540,7 +604,7 @@ _: pop af
ld (hl), a
push hl
ld de, kernelGarbage + 0x100
call findDirectoryEntry
call findNode ; TODO: Check that this is a directory node
jp nz, .wtf
setBankA
pop de
Expand Down
Loading

0 comments on commit af804e2

Please sign in to comment.