After this change, file_init will correctly wrap around in memory
like the other operations.
This commit also fixes a few issues I observed:
- Hexadecimal numbers were garbled
- Directories lacked a trailing slash
- The size calculation was too pessimistic
Previously we had a lot of places where &uxn.ram[addr] was being used without
checking that addr+length < 65536. In cases where that value is exceeded, the
reads/writes should wrap back around to the beginning of memory.
After this change, most of the accesses have been made safe.
Two places that are not (yet) converted:
1. file_init: We already truncate reads past the end of ram.
While this does is technically incorrect it will avoid memory
corruption or crashing.
2. file_read_dir: The code here still uses snprintf formatting.
Previously, writing to the stat port would produce a line of text
similar to the listing used when reading a directory. This did not
match the documentation around the stat port.
After the change, writing an address to the stat port will fill that
address with bytes equal to the length parameter. These will either be
a hexadecimal file size, or else the same character repeated N times
according to the following logic:
- path is a directory
? file size of path does not fit in N hexadecimal characters
! path is not readable
Note that unlike when reading a directory, the string will not include
the requested path, a newline, or a null terminator.
Previously Varvara did not have a way to create new directories.
This change adds that capability without adding or modifying any
device ports.
The changes are:
(1) When a filename ends in the directory separator, writing
any value to File/write will create a directory. Unlike
with regular files, the value is ignored.
(2) When writing any path (regular files or directories) if
there are missing parent directories Varvara will attempt
to create them first. This behavior is similar to mkdir -p.
The directory separator is / on most platforms, and \ on Windows.
On POSIX platforms the directories will be created with permission
0755 (modified by the user's umask value).
This change has been tested and works in both uxnemu and uxncli.