The file %FileSysDir%\file-main.fth builds the native API of the file system in preparation for the ANS layer.
File identifiers (shows as FID) are the OTB address when files are open.
: open_f# \ fn -- fid|0
Given a file number, open it and return the FID address or 0
if the operation fails.
: open_f \ caddr len -- fid|0
Open the named file and return its FID
or zero if the operation fails.
: close_f \ fid -- code
Close the file, returning: 0 on error; -1 if fully closed;
or -2 if there is still an open instance.
: file-not-exist? \ caddr len -- t/f
COMPILER: Return true if the file does not exist.
: spllt-path&file { l_*name l_len | l_*tname l_tlen -- name len }
Split Dir path and filename, returning the file name part.
: (adjust-blocks) \ len -- blocks
COMPILER: Convert a length to the minimum number of blocks
required to hold that much data.
: adjust-blocks \ len -- blocks
Convert a length to the minimum number of blocks
required to hold that much data. Always returns
at least one.
: required-blocks \ len fid -- blocks
Returns the number of blocks required to write len
bytes from the current file position.
: need-dir-$buffer \ --
ALLOCATE a working directory buffer if one has not
already been allocated.
: (ch-dir) \ caddr len -- t/f
Switch to the given working directory and return true. If the
change cannot be made, set the default directory and return 0.
: ch-dir \ caddr len -- t/f
Switch to the given working directory and return true. If the
change cannot be made, set the default directory and return 0.
: add-to-dir { l_fld l_*name l_len l_block | l_success -- flag }
Add the given file number and name to the given directory
block, returning true for success.
: remove-file-dir { l_fld l_block | l_success -- flag }
Remove the given file number from the given directory block,
returning true for success.
: (create_f) { l_*name l_len l_size l_extent | l_start l_*buff -- t/f }
In the current directory create a file with the given name,
initial size and extension. Return true for success.
The file is not opened.
: create_f { l_*name l_len l_size_b l_extent_b | l_*tname l_tlen -- t/f }
Create a file with the given name, initial size and extension.
The file name may include existing directories.
The file is not opened.
Return true for success.
: (create_d) { l_*name l_len | l_start l_fld l_prev-fld l_*buff -- t/f }
In the current directory create a subdirecory with the given name.
Return true for success.
: create_d \ caddr len -- t/f
Create a directory with the given name.
The name may include existing directories.
Return true for success.
: rename_f { *old-name old-len *new-name new-len | l_fld -- t/f }
Rename a file from the old name to the new name.
Return true for success.
: (delete_f) { l_fn | l_*buff l_size -- t/f }
Delete the given file number.
Return true for success.
: delete_f \ name len -- t/f
Delete the given file by name.
Return true for success.
: delete-files { l_*name l_len -- t/f }
Delete a group of files if the first character of the name
is '*', otherwise delete a single file.
Return true for success.
: lseek_f \ ptr fid -- t/f
Seek to the given location in the file.
Return true for success.
PTR=0 |
set to start |
PTR=-1 |
set to end of written data |
PTR=+ve |
from start of file |
PTR=-ve |
from end of data |
: file-read-area { l_fid l_len | l_*c-pos -- b-start size }
Caculate how much can be read from the current position with
a single block read.
: r/w-block { l_fid | l_hd-block l_block l_fcb -- phys-blk }
Return the block number containing the current file read/write
pointer location. Return -1 on error or -2 if the pointer
is beyond the end of file.
: read_f { l_buf l_len l_fid | l_read-size l_start-buff -- len }
Read len bytes into buff from the given file, returning
the number of bytes actually written.
: update-size&time { l_fid | l_size l_fcb -- t/f }
Update the file size and modification time.
: write_f { l_buf l_len l_fid | l_size l_start l_req-blk -- len }
Write len bytes from buff from the given file, returning
the number of bytes actually written.
: zero-file \ l_fid -- t/f
Reduce the file to zero size without changing the disk
allocation. Return true for success.
: InitFileTask \ --
Before using the file system, each task must run this word.
: doDiskTask \ --
The action of the disk service task.
Task DiskTask \ -- addr
The disk service task.
: InitFileSys \ --
Before using the file system, this word must be run at
power up.