Virtual file support (#701)

* Add support for virtual files (eg, not backed by an OS file).

Virtual files are implemented through trait objects, with a default
implementation that tries to behave like on-disk files, but entirely
backed by in-memory structures.

Co-authored-by: Dan Gohman <sunfish@mozilla.com>
This commit is contained in:
iximeow
2020-03-06 11:08:13 -08:00
committed by GitHub
parent 7f7196a655
commit 7e0d9decbf
19 changed files with 1568 additions and 188 deletions

View File

@@ -1,3 +1,4 @@
use crate::fdentry::Descriptor;
use crate::hostcalls_impl::PathGet;
use crate::Result;
use std::os::unix::prelude::AsRawFd;
@@ -26,15 +27,22 @@ pub(crate) fn path_symlink(old_path: &str, resolved: PathGet) -> Result<()> {
pub(crate) fn path_rename(resolved_old: PathGet, resolved_new: PathGet) -> Result<()> {
use yanix::file::renameat;
unsafe {
renameat(
resolved_old.dirfd().as_raw_fd(),
resolved_old.path(),
resolved_new.dirfd().as_raw_fd(),
resolved_new.path(),
)
match (resolved_old.dirfd(), resolved_new.dirfd()) {
(Descriptor::OsHandle(resolved_old_file), Descriptor::OsHandle(resolved_new_file)) => {
unsafe {
renameat(
resolved_old_file.as_raw_fd(),
resolved_old.path(),
resolved_new_file.as_raw_fd(),
resolved_new.path(),
)
}
.map_err(Into::into)
}
_ => {
unimplemented!("path_link with one or more virtual files");
}
}
.map_err(Into::into)
}
pub(crate) mod fd_readdir_impl {