-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Basic filesystems support for Wasm: support WASI-based filesystem for wasmWasi #257
Conversation
* @return a resolved path. | ||
* @throws FileNotFoundException if there is no file or directory corresponding to the specified path. | ||
*/ | ||
override fun resolve(path: Path): Path { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dkhalanskyjb (you asked, I tagged).
Here's a hand-written canonization implementation. It's used only for Wasm-WASI.
rootPaths | ||
} | ||
|
||
internal fun getRootOrNull(path: Path): PreOpen? { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I understand it, this function is not looking for the root directory, but an preopen one, maybe it should be called findPreopen(...)
?
return null | ||
} | ||
|
||
internal fun getRoot(path: Path): PreOpen { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same about name, mentioning the root is a bit confusing
|
||
SystemFileSystem.createDirectories(Path("/tmp/a/b/c/d/e")) | ||
try { | ||
WasiFileSystem.symlink(Path("/tmp/a/b/c/d/e"), Path("/tmp/l")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we also check for recursive symlinks?
) | ||
if (res != Errno.success) { | ||
if (res == Errno.noent) throw FileNotFoundException("File does not exist: $path") | ||
throw IOException("Can't open $path for write: ${res.description}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for write?
val root = PreOpens.getRoot(path) | ||
|
||
val fd = withScopedMemoryAllocator { allocator -> | ||
val fdPtr = allocator.allocate(4) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Magic number.
Can we create some constants and util functions for sizes and null-terminated string length?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For allocate(4)
- definitely. I am not sure about Null-terminated strings. I think it should be enough to explicitly comment on why there's an extra 1
in the code for now.
|
||
while (remaining > 0) { | ||
val toRead = minOf(remaining, TEMP_CIOVEC_BUFFER_LEN).toInt() | ||
source.readToLinearMemory(buffer, toRead) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not immediately clear which buffer was meant. Perhaps we should call it something else?
* code clean-up and renaming * improved exception messages * improved build scripts
… wasmWasi (#257) Implemented basic filesystem support on top of Wasm WASI.
Supported filesystem for wasmWasi target by implementing all the functionality on top of WASI preview 1.
The implementation is inspired by fs-implementations from kowasm and Okio.
Unlike other platforms, in Wasm-WASI, there are no such things as the current working directory (but there's an initial-cwd in wasi-cli:0.2.0) and a system temporary directory.
The lack of CWD affects relative paths resolution (which are usually resolved against CWD).
There are several approaches adopted by the community:
/
as a CWD;.
and all relative paths will be resolved against it;There's also an option to rely on environment variables, but that approach is not very favorable, according to WebAssembly/wasi-filesystem#24.
I decided to stick to the approach employed by kowasm and Okio as that approach could be more familiar to Kotlin developers.
For the temporary directory, for now, I decided to use
/tmp
as a temp dir, or fail if the directory is not available. The behavior could be changed once it becomes an issue for users.