-
Notifications
You must be signed in to change notification settings - Fork 814
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
About file descriptors in lib/wasi & their POSIX compliance #3315
Comments
Hey @corwin-of-amber , we added vfs as an after-thought to wasi.
I believe most of the complexity came from the reasons I described before. I'm sure a lot of this logic could be refactored and improved. |
This might be a bug that we need to address |
Hi @syrusakbary! Thanks for the incredibly swift reply. I am happy to learn that you are going to take that into consideration. I will stay tuned to see the changes that you are doing in this refactor. |
Thank you for reporting, we are likely to do this after the WASIX merge, the filesystem code is currently frozen. Yes, the Fd should either have a proper reference count and we need to make sure that the closing one Fd doesn't affect others, this is a serious bug. The reason for the indirection is probably so that the Fd can be expanded later, which would not be possible with a simple integer. |
This requires a bit of refactor on wasi and the filesystem. Will post here the updates |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Feel free to reopen the issue if it has been closed by mistake. |
Summary
Generally, I am trying to understand the relationship between
Inode
,InodeVal
, andFd
. Perhaps this mechanism can be improved.Additional details
First, some background: I am running
ocamlc
on top of Wasmer (in wasm32). One thing that I noticed is that it opens the same file multiple times. This is weird perhaps, but is acceptable POSIX behavior. In Wasmer, I find anfd_map
which maps int ->Fd
, which contains anInode
, which in turn is mapped throughinodes.arena
to anInodeVal
. The latter has aKind
which in turn holds ahandle: Option<Box<dyn VirtualFile>>
. As much as I look at it, it seems that theInode
is determined from the path atpath_open
, and the arena is indexed by theinode.index
, such that if I open the same file multiple times, I am bound to get the sameInode
and therefore the sameInodeVal
. This is in line with my observation, which is (finally): if I open the same file twice, and then close one of the file handles, then the other file handle is also closed as a side effect.What I am asking is then two things: (i) what is the motivation for so many levels of indirection from an int fd to a handle? (ii) would it make sense to have handles keyed by fd instead?
It also strikes as a bit strange that files in the vfs have a
FileDescriptor
(usize) and that e.g. mem_fs maintains a positioncursor
for aFile
in file nodes. Because the position is associated with the fd, and the entire model kind of breaks if a file has multiple active fd's.The text was updated successfully, but these errors were encountered: