sys: import types from handle or sched, not wasi. drop types:: prefix.
This commit is contained in:
@@ -1,18 +1,18 @@
|
||||
use super::oshandle::RawOsHandle;
|
||||
use crate::handle::{Advice, Dircookie, Dirent, Fdflags, Filesize, Filestat, DIRCOOKIE_START};
|
||||
use crate::sys::osdir::OsDir;
|
||||
use crate::sys::osfile::OsFile;
|
||||
use crate::wasi::{self, types};
|
||||
use crate::Result;
|
||||
use std::convert::TryInto;
|
||||
use std::fs::File;
|
||||
use std::os::unix::prelude::AsRawFd;
|
||||
|
||||
pub(crate) fn fdstat_get(fd: &File) -> Result<types::Fdflags> {
|
||||
pub(crate) fn fdstat_get(fd: &File) -> Result<Fdflags> {
|
||||
let fdflags = unsafe { yanix::fcntl::get_status_flags(fd.as_raw_fd())? };
|
||||
Ok(fdflags.into())
|
||||
}
|
||||
|
||||
pub(crate) fn fdstat_set_flags(fd: &File, fdflags: types::Fdflags) -> Result<Option<RawOsHandle>> {
|
||||
pub(crate) fn fdstat_set_flags(fd: &File, fdflags: Fdflags) -> Result<Option<RawOsHandle>> {
|
||||
unsafe { yanix::fcntl::set_status_flags(fd.as_raw_fd(), fdflags.into())? };
|
||||
// We return None here to signal that the operation succeeded on the original
|
||||
// file descriptor and mutating the original WASI Descriptor is thus unnecessary.
|
||||
@@ -20,28 +20,23 @@ pub(crate) fn fdstat_set_flags(fd: &File, fdflags: types::Fdflags) -> Result<Opt
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
pub(crate) fn advise(
|
||||
file: &OsFile,
|
||||
advice: types::Advice,
|
||||
offset: types::Filesize,
|
||||
len: types::Filesize,
|
||||
) -> Result<()> {
|
||||
pub(crate) fn advise(file: &OsFile, advice: Advice, offset: Filesize, len: Filesize) -> Result<()> {
|
||||
use yanix::fadvise::{posix_fadvise, PosixFadviseAdvice};
|
||||
let offset = offset.try_into()?;
|
||||
let len = len.try_into()?;
|
||||
let host_advice = match advice {
|
||||
types::Advice::Dontneed => PosixFadviseAdvice::DontNeed,
|
||||
types::Advice::Sequential => PosixFadviseAdvice::Sequential,
|
||||
types::Advice::Willneed => PosixFadviseAdvice::WillNeed,
|
||||
types::Advice::Noreuse => PosixFadviseAdvice::NoReuse,
|
||||
types::Advice::Random => PosixFadviseAdvice::Random,
|
||||
types::Advice::Normal => PosixFadviseAdvice::Normal,
|
||||
Advice::Dontneed => PosixFadviseAdvice::DontNeed,
|
||||
Advice::Sequential => PosixFadviseAdvice::Sequential,
|
||||
Advice::Willneed => PosixFadviseAdvice::WillNeed,
|
||||
Advice::Noreuse => PosixFadviseAdvice::NoReuse,
|
||||
Advice::Random => PosixFadviseAdvice::Random,
|
||||
Advice::Normal => PosixFadviseAdvice::Normal,
|
||||
};
|
||||
unsafe { posix_fadvise(file.as_raw_fd(), offset, len, host_advice)? };
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn filestat_get(file: &File) -> Result<types::Filestat> {
|
||||
pub(crate) fn filestat_get(file: &File) -> Result<Filestat> {
|
||||
use yanix::file::fstat;
|
||||
let stat = unsafe { fstat(file.as_raw_fd())? };
|
||||
Ok(stat.try_into()?)
|
||||
@@ -49,8 +44,8 @@ pub(crate) fn filestat_get(file: &File) -> Result<types::Filestat> {
|
||||
|
||||
pub(crate) fn readdir<'a>(
|
||||
dirfd: &'a OsDir,
|
||||
cookie: types::Dircookie,
|
||||
) -> Result<Box<dyn Iterator<Item = Result<(types::Dirent, String)>> + 'a>> {
|
||||
cookie: Dircookie,
|
||||
) -> Result<Box<dyn Iterator<Item = Result<(Dirent, String)>> + 'a>> {
|
||||
use yanix::dir::{DirIter, Entry, EntryExt, SeekLoc};
|
||||
|
||||
// Get an instance of `Dir`; this is host-specific due to intricasies
|
||||
@@ -59,7 +54,7 @@ pub(crate) fn readdir<'a>(
|
||||
|
||||
// Seek if needed. Unless cookie is wasi::__WASI_DIRCOOKIE_START,
|
||||
// new items may not be returned to the caller.
|
||||
if cookie == wasi::DIRCOOKIE_START {
|
||||
if cookie == DIRCOOKIE_START {
|
||||
tracing::trace!("fd_readdir: doing rewinddir");
|
||||
dir.rewind();
|
||||
} else {
|
||||
@@ -71,7 +66,7 @@ pub(crate) fn readdir<'a>(
|
||||
Ok(Box::new(DirIter::new(dir).map(|entry| {
|
||||
let entry: Entry = entry?;
|
||||
let name = entry.file_name().to_str()?.to_owned();
|
||||
let dirent = types::Dirent {
|
||||
let dirent = Dirent {
|
||||
d_next: entry.seek_loc()?.to_raw().try_into()?,
|
||||
d_ino: entry.ino(),
|
||||
d_namlen: name.len().try_into()?,
|
||||
|
||||
Reference in New Issue
Block a user