fs: only import wasi Fd type in one place
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
use crate::fs::{File, OpenOptions, ReadDir};
|
||||
use crate::wasi::types;
|
||||
use crate::fs::{Fd, File, OpenOptions, ReadDir};
|
||||
use crate::wasi::wasi_snapshot_preview1::WasiSnapshotPreview1;
|
||||
use crate::WasiCtx;
|
||||
#[cfg(unix)]
|
||||
@@ -18,12 +17,12 @@ use std::{io, path::Path};
|
||||
/// don't interoperate well with the capability-oriented security model.
|
||||
pub struct Dir<'ctx> {
|
||||
ctx: &'ctx WasiCtx,
|
||||
fd: types::Fd,
|
||||
fd: Fd,
|
||||
}
|
||||
|
||||
impl<'ctx> Dir<'ctx> {
|
||||
/// Constructs a new instance of `Self` from the given raw WASI file descriptor.
|
||||
pub unsafe fn from_raw_wasi_fd(ctx: &'ctx WasiCtx, fd: types::Fd) -> Self {
|
||||
pub unsafe fn from_raw_wasi_fd(ctx: &'ctx WasiCtx, fd: Fd) -> Self {
|
||||
Self { ctx, fd }
|
||||
}
|
||||
|
||||
@@ -39,7 +38,7 @@ impl<'ctx> Dir<'ctx> {
|
||||
/// [`std::fs::File::open`]: https://doc.rust-lang.org/std/fs/struct.File.html#method.open
|
||||
pub fn open_file<P: AsRef<Path>>(&mut self, path: P) -> io::Result<File> {
|
||||
let path = path.as_ref();
|
||||
let mut fd = types::Fd::from(0);
|
||||
let mut fd = Fd::from(0);
|
||||
|
||||
// TODO: Refactor the hostcalls functions to split out the encoding/decoding
|
||||
// parts from the underlying functionality, so that we can call into the
|
||||
@@ -92,7 +91,7 @@ impl<'ctx> Dir<'ctx> {
|
||||
/// TODO: Not yet implemented. See the comment in `open_file`.
|
||||
pub fn open_dir<P: AsRef<Path>>(&mut self, path: P) -> io::Result<Self> {
|
||||
let path = path.as_ref();
|
||||
let mut fd = types::Fd::from(0);
|
||||
let mut fd = Fd::from(0);
|
||||
|
||||
// TODO: See the comment in `open_file`.
|
||||
unimplemented!("Dir::open_dir");
|
||||
@@ -124,7 +123,7 @@ impl<'ctx> Dir<'ctx> {
|
||||
/// [`std::fs::File::create`]: https://doc.rust-lang.org/std/fs/struct.File.html#method.create
|
||||
pub fn create_file<P: AsRef<Path>>(&mut self, path: P) -> io::Result<File> {
|
||||
let path = path.as_ref();
|
||||
let mut fd = types::Fd::from(0);
|
||||
let mut fd = Fd::from(0);
|
||||
|
||||
// TODO: See the comments in `open_file`.
|
||||
//
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
use crate::fs::Metadata;
|
||||
use crate::wasi::types;
|
||||
use crate::fs::{Fd, Metadata};
|
||||
use crate::wasi::wasi_snapshot_preview1::WasiSnapshotPreview1;
|
||||
use crate::Result;
|
||||
use crate::WasiCtx;
|
||||
@@ -19,7 +18,7 @@ use std::io;
|
||||
/// [`Dir::create_file`]: struct.Dir.html#method.create_file
|
||||
pub struct File<'ctx> {
|
||||
ctx: &'ctx WasiCtx,
|
||||
fd: types::Fd,
|
||||
fd: Fd,
|
||||
}
|
||||
|
||||
impl<'ctx> File<'ctx> {
|
||||
@@ -28,7 +27,7 @@ impl<'ctx> File<'ctx> {
|
||||
/// This corresponds to [`std::fs::File::from_raw_fd`].
|
||||
///
|
||||
/// [`std::fs::File::from_raw_fd`]: https://doc.rust-lang.org/std/fs/struct.File.html#method.from_raw_fd
|
||||
pub unsafe fn from_raw_wasi_fd(ctx: &'ctx WasiCtx, fd: types::Fd) -> Self {
|
||||
pub unsafe fn from_raw_wasi_fd(ctx: &'ctx WasiCtx, fd: Fd) -> Self {
|
||||
Self { ctx, fd }
|
||||
}
|
||||
|
||||
@@ -89,7 +88,7 @@ impl<'ctx> io::Read for File<'ctx> {
|
||||
/// TODO: Not yet implemented. See the comment in `Dir::open_file`.
|
||||
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
|
||||
// TODO
|
||||
// let iov = [types::Iovec {
|
||||
// let iov = [Iovec {
|
||||
// buf: buf.as_mut_ptr() as *mut u8,
|
||||
// buf_len: buf.len(),
|
||||
// }];
|
||||
|
||||
@@ -39,6 +39,8 @@ mod open_options;
|
||||
mod permissions;
|
||||
mod readdir;
|
||||
|
||||
pub use crate::wasi::types::Fd;
|
||||
|
||||
pub use dir::*;
|
||||
pub use dir_builder::*;
|
||||
pub use dir_entry::*;
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
use crate::fs::DirEntry;
|
||||
use crate::wasi::types;
|
||||
use crate::fs::{DirEntry, Fd};
|
||||
|
||||
/// Iterator over the entries in a directory.
|
||||
///
|
||||
@@ -9,12 +8,12 @@ use crate::wasi::types;
|
||||
///
|
||||
/// [`std::fs::ReadDir`]: https://doc.rust-lang.org/std/fs/struct.ReadDir.html
|
||||
pub struct ReadDir {
|
||||
fd: types::Fd,
|
||||
fd: Fd,
|
||||
}
|
||||
|
||||
impl ReadDir {
|
||||
/// Constructs a new instance of `Self` from the given raw WASI file descriptor.
|
||||
pub unsafe fn from_raw_wasi_fd(fd: types::Fd) -> Self {
|
||||
pub unsafe fn from_raw_wasi_fd(fd: Fd) -> Self {
|
||||
Self { fd }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user