wasi-common: break dep on system-interface by defining our own Advice enum
This commit is contained in:
@@ -23,7 +23,6 @@ anyhow = "1.0"
|
||||
thiserror = "1.0"
|
||||
wiggle = { path = "../wiggle", default-features = false, version = "0.22.0" }
|
||||
tracing = "0.1.19"
|
||||
system-interface = { version = "0.5.4", features = ["cap_std_impls"] }
|
||||
cap-std = "0.12"
|
||||
cap-rand = "0.12"
|
||||
bitflags = "1.2"
|
||||
|
||||
@@ -4,11 +4,11 @@ use std::any::Any;
|
||||
use std::convert::TryInto;
|
||||
use std::io;
|
||||
use system_interface::{
|
||||
fs::{Advice, FileIoExt, GetSetFdFlags},
|
||||
fs::{FileIoExt, GetSetFdFlags},
|
||||
io::ReadReady,
|
||||
};
|
||||
use wasi_common::{
|
||||
file::{FdFlags, FileType, Filestat, WasiFile},
|
||||
file::{Advice, FdFlags, FileType, Filestat, WasiFile},
|
||||
Error,
|
||||
};
|
||||
|
||||
@@ -61,7 +61,7 @@ impl WasiFile for File {
|
||||
Ok(())
|
||||
}
|
||||
fn advise(&self, offset: u64, len: u64, advice: Advice) -> Result<(), Error> {
|
||||
self.0.advise(offset, len, advice)?;
|
||||
self.0.advise(offset, len, convert_advice(advice))?;
|
||||
Ok(())
|
||||
}
|
||||
fn allocate(&self, offset: u64, len: u64) -> Result<(), Error> {
|
||||
@@ -193,3 +193,13 @@ pub fn from_sysif_fdflags(f: system_interface::fs::FdFlags) -> wasi_common::file
|
||||
}
|
||||
out
|
||||
}
|
||||
pub fn convert_advice(advice: Advice) -> system_interface::fs::Advice {
|
||||
match advice {
|
||||
Advice::Normal => system_interface::fs::Advice::Normal,
|
||||
Advice::Sequential => system_interface::fs::Advice::Sequential,
|
||||
Advice::Random => system_interface::fs::Advice::Random,
|
||||
Advice::WillNeed => system_interface::fs::Advice::WillNeed,
|
||||
Advice::DontNeed => system_interface::fs::Advice::DontNeed,
|
||||
Advice::NoReuse => system_interface::fs::Advice::NoReuse,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ use std::any::Any;
|
||||
use std::convert::TryInto;
|
||||
use std::io;
|
||||
use std::io::{Read, Write};
|
||||
use system_interface::{fs::Advice, io::ReadReady};
|
||||
use system_interface::io::ReadReady;
|
||||
|
||||
#[cfg(unix)]
|
||||
use std::os::unix::io::{AsRawFd, RawFd};
|
||||
@@ -12,7 +12,7 @@ use std::os::unix::io::{AsRawFd, RawFd};
|
||||
use std::os::windows::io::{AsRawHandle, RawHandle};
|
||||
use unsafe_io::AsUnsafeFile;
|
||||
use wasi_common::{
|
||||
file::{FdFlags, FileType, Filestat, WasiFile},
|
||||
file::{Advice, FdFlags, FileType, Filestat, WasiFile},
|
||||
Error, ErrorExt,
|
||||
};
|
||||
|
||||
|
||||
@@ -13,12 +13,7 @@ pub trait WasiFile {
|
||||
fn set_fdflags(&mut self, flags: FdFlags) -> Result<(), Error>; // file op
|
||||
fn get_filestat(&self) -> Result<Filestat, Error>; // split out get_length as a read & write op, rest is a file op
|
||||
fn set_filestat_size(&self, _size: u64) -> Result<(), Error>; // write op
|
||||
fn advise(
|
||||
&self,
|
||||
offset: u64,
|
||||
len: u64,
|
||||
advice: system_interface::fs::Advice,
|
||||
) -> Result<(), Error>; // file op
|
||||
fn advise(&self, offset: u64, len: u64, advice: Advice) -> Result<(), Error>; // file op
|
||||
fn allocate(&self, offset: u64, len: u64) -> Result<(), Error>; // write op
|
||||
fn set_times(
|
||||
&self,
|
||||
@@ -170,3 +165,13 @@ pub struct FdStat {
|
||||
pub caps: FileCaps,
|
||||
pub flags: FdFlags,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum Advice {
|
||||
Normal,
|
||||
Sequential,
|
||||
Random,
|
||||
WillNeed,
|
||||
DontNeed,
|
||||
NoReuse,
|
||||
}
|
||||
|
||||
@@ -10,14 +10,13 @@
|
||||
//! but the virtual pipes can be instantiated with any `Read` or `Write` type.
|
||||
//!
|
||||
use crate::{
|
||||
file::{FdFlags, FileType, Filestat, WasiFile},
|
||||
file::{Advice, FdFlags, FileType, Filestat, WasiFile},
|
||||
Error, ErrorExt, SystemTimeSpec,
|
||||
};
|
||||
use std::any::Any;
|
||||
use std::convert::TryInto;
|
||||
use std::io::{self, Read, Write};
|
||||
use std::sync::{Arc, RwLock};
|
||||
use system_interface::fs::Advice;
|
||||
|
||||
/// A virtual pipe read end.
|
||||
///
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
use crate::{
|
||||
dir::{DirCaps, DirEntry, DirEntryExt, DirFdStat, ReaddirCursor, ReaddirEntity, TableDirExt},
|
||||
file::{
|
||||
FdFlags, FdStat, FileCaps, FileEntry, FileEntryExt, FileEntryMutExt, FileType, Filestat,
|
||||
OFlags, TableFileExt,
|
||||
Advice, FdFlags, FdStat, FileCaps, FileEntry, FileEntryExt, FileEntryMutExt, FileType,
|
||||
Filestat, OFlags, TableFileExt,
|
||||
},
|
||||
sched::{
|
||||
subscription::{RwEventFlags, SubscriptionResult},
|
||||
@@ -1081,15 +1081,15 @@ impl<'a> wasi_snapshot_preview1::WasiSnapshotPreview1 for WasiCtx {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<types::Advice> for system_interface::fs::Advice {
|
||||
fn from(advice: types::Advice) -> system_interface::fs::Advice {
|
||||
impl From<types::Advice> for Advice {
|
||||
fn from(advice: types::Advice) -> Advice {
|
||||
match advice {
|
||||
types::Advice::Normal => system_interface::fs::Advice::Normal,
|
||||
types::Advice::Sequential => system_interface::fs::Advice::Sequential,
|
||||
types::Advice::Random => system_interface::fs::Advice::Random,
|
||||
types::Advice::Willneed => system_interface::fs::Advice::WillNeed,
|
||||
types::Advice::Dontneed => system_interface::fs::Advice::DontNeed,
|
||||
types::Advice::Noreuse => system_interface::fs::Advice::NoReuse,
|
||||
types::Advice::Normal => Advice::Normal,
|
||||
types::Advice::Sequential => Advice::Sequential,
|
||||
types::Advice::Random => Advice::Random,
|
||||
types::Advice::Willneed => Advice::WillNeed,
|
||||
types::Advice::Dontneed => Advice::DontNeed,
|
||||
types::Advice::Noreuse => Advice::NoReuse,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user