From b37adbbe317787fc1c627a93e36327c154e0fa68 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Wed, 1 Jul 2020 11:53:16 -0700 Subject: [PATCH] Rename `OFlag`/`AtFlag` to `OFlags`/`AtFlags`. (#1951) * Rename `OFlag`/`AtFlag` to `OFlags`/`AtFlags`. This makes them consistent with `PollFlags` and common usage of bitflags types in Rust code in general. POSIX does tend to use names like `oflag` and `flag`, so this is in mild disagreement with POSIX style, however I find this particular aspects of POSIX confusing because these values hold multiple flags. * rustfmt --- .../old/snapshot_0/sys/unix/bsd/host_impl.rs | 2 +- .../snapshot_0/sys/unix/bsd/hostcalls_impl.rs | 14 +++--- .../sys/unix/emscripten/host_impl.rs | 2 +- .../src/old/snapshot_0/sys/unix/entry_impl.rs | 8 ++-- .../src/old/snapshot_0/sys/unix/host_impl.rs | 36 +++++++------- .../snapshot_0/sys/unix/hostcalls_impl/fs.rs | 32 ++++++------- .../sys/unix/hostcalls_impl/fs_helpers.rs | 12 ++--- .../snapshot_0/sys/unix/linux/host_impl.rs | 2 +- .../sys/unix/linux/hostcalls_impl.rs | 4 +- crates/wasi-common/src/sys/unix/bsd/mod.rs | 2 +- crates/wasi-common/src/sys/unix/bsd/path.rs | 14 +++--- .../src/sys/unix/emscripten/mod.rs | 2 +- crates/wasi-common/src/sys/unix/linux/mod.rs | 2 +- crates/wasi-common/src/sys/unix/linux/path.rs | 4 +- crates/wasi-common/src/sys/unix/mod.rs | 28 +++++------ crates/wasi-common/src/sys/unix/osdir.rs | 8 ++-- crates/wasi-common/src/sys/unix/osfile.rs | 8 ++-- crates/wasi-common/src/sys/unix/path.rs | 48 +++++++++---------- crates/wasi-common/yanix/src/fcntl.rs | 14 +++--- crates/wasi-common/yanix/src/file.rs | 18 ++++--- 20 files changed, 132 insertions(+), 128 deletions(-) diff --git a/crates/wasi-common/src/old/snapshot_0/sys/unix/bsd/host_impl.rs b/crates/wasi-common/src/old/snapshot_0/sys/unix/bsd/host_impl.rs index ea14861f10..37ed2e4e38 100644 --- a/crates/wasi-common/src/old/snapshot_0/sys/unix/bsd/host_impl.rs +++ b/crates/wasi-common/src/old/snapshot_0/sys/unix/bsd/host_impl.rs @@ -1,7 +1,7 @@ use crate::old::snapshot_0::wasi::{self, WasiResult}; use std::convert::TryFrom; -pub(crate) const O_RSYNC: yanix::file::OFlag = yanix::file::OFlag::SYNC; +pub(crate) const O_RSYNC: yanix::file::OFlags = yanix::file::OFlags::SYNC; pub(crate) fn stdev_from_nix(dev: libc::dev_t) -> WasiResult { wasi::__wasi_device_t::try_from(dev).map_err(Into::into) diff --git a/crates/wasi-common/src/old/snapshot_0/sys/unix/bsd/hostcalls_impl.rs b/crates/wasi-common/src/old/snapshot_0/sys/unix/bsd/hostcalls_impl.rs index 15ab4bc319..3182ec4dc3 100644 --- a/crates/wasi-common/src/old/snapshot_0/sys/unix/bsd/hostcalls_impl.rs +++ b/crates/wasi-common/src/old/snapshot_0/sys/unix/bsd/hostcalls_impl.rs @@ -3,12 +3,12 @@ use crate::old::snapshot_0::wasi::{WasiError, WasiResult}; use std::os::unix::prelude::AsRawFd; pub(crate) fn path_unlink_file(resolved: PathGet) -> WasiResult<()> { - use yanix::file::{unlinkat, AtFlag}; + use yanix::file::{unlinkat, AtFlags}; match unsafe { unlinkat( resolved.dirfd().as_raw_fd(), resolved.path(), - AtFlag::empty(), + AtFlags::empty(), ) } { Err(err) => { @@ -27,7 +27,7 @@ pub(crate) fn path_unlink_file(resolved: PathGet) -> WasiResult<()> { fstatat( resolved.dirfd().as_raw_fd(), resolved.path(), - AtFlag::SYMLINK_NOFOLLOW, + AtFlags::SYMLINK_NOFOLLOW, ) } { Ok(stat) => { @@ -48,7 +48,7 @@ pub(crate) fn path_unlink_file(resolved: PathGet) -> WasiResult<()> { } pub(crate) fn path_symlink(old_path: &str, resolved: PathGet) -> WasiResult<()> { - use yanix::file::{fstatat, symlinkat, AtFlag}; + use yanix::file::{fstatat, symlinkat, AtFlags}; log::debug!("path_symlink old_path = {:?}", old_path); log::debug!("path_symlink resolved = {:?}", resolved); @@ -66,7 +66,7 @@ pub(crate) fn path_symlink(old_path: &str, resolved: PathGet) -> WasiResult<()> fstatat( resolved.dirfd().as_raw_fd(), new_path, - AtFlag::SYMLINK_NOFOLLOW, + AtFlags::SYMLINK_NOFOLLOW, ) } { Ok(_) => return Err(WasiError::EEXIST), @@ -82,7 +82,7 @@ pub(crate) fn path_symlink(old_path: &str, resolved: PathGet) -> WasiResult<()> } pub(crate) fn path_rename(resolved_old: PathGet, resolved_new: PathGet) -> WasiResult<()> { - use yanix::file::{fstatat, renameat, AtFlag}; + use yanix::file::{fstatat, renameat, AtFlags}; match unsafe { renameat( resolved_old.dirfd().as_raw_fd(), @@ -107,7 +107,7 @@ pub(crate) fn path_rename(resolved_old: PathGet, resolved_new: PathGet) -> WasiR fstatat( resolved_old.dirfd().as_raw_fd(), resolved_old.path(), - AtFlag::SYMLINK_NOFOLLOW, + AtFlags::SYMLINK_NOFOLLOW, ) } { Ok(_) => { diff --git a/crates/wasi-common/src/old/snapshot_0/sys/unix/emscripten/host_impl.rs b/crates/wasi-common/src/old/snapshot_0/sys/unix/emscripten/host_impl.rs index ac25f4a9d2..2f9092cd4d 100644 --- a/crates/wasi-common/src/old/snapshot_0/sys/unix/emscripten/host_impl.rs +++ b/crates/wasi-common/src/old/snapshot_0/sys/unix/emscripten/host_impl.rs @@ -1,6 +1,6 @@ use crate::old::snapshot_0::wasi::{self, WasiResult}; -pub(crate) const O_RSYNC: yanix::file::OFlag = yanix::file::OFlag::RSYNC; +pub(crate) const O_RSYNC: yanix::file::OFlags = yanix::file::OFlags::RSYNC; pub(crate) fn stdev_from_nix(dev: libc::dev_t) -> WasiResult { Ok(wasi::__wasi_device_t::from(dev)) diff --git a/crates/wasi-common/src/old/snapshot_0/sys/unix/entry_impl.rs b/crates/wasi-common/src/old/snapshot_0/sys/unix/entry_impl.rs index aa0135470e..8f9debabf9 100644 --- a/crates/wasi-common/src/old/snapshot_0/sys/unix/entry_impl.rs +++ b/crates/wasi-common/src/old/snapshot_0/sys/unix/entry_impl.rs @@ -36,12 +36,12 @@ pub(crate) unsafe fn determine_type_and_access_rights( )> { let (file_type, mut rights_base, rights_inheriting) = determine_type_rights(fd)?; - use yanix::{fcntl, file::OFlag}; + use yanix::{fcntl, file::OFlags}; let flags = fcntl::get_status_flags(fd.as_raw_fd())?; - let accmode = flags & OFlag::ACCMODE; - if accmode == OFlag::RDONLY { + let accmode = flags & OFlags::ACCMODE; + if accmode == OFlags::RDONLY { rights_base &= !wasi::__WASI_RIGHTS_FD_WRITE; - } else if accmode == OFlag::WRONLY { + } else if accmode == OFlags::WRONLY { rights_base &= !wasi::__WASI_RIGHTS_FD_READ; } diff --git a/crates/wasi-common/src/old/snapshot_0/sys/unix/host_impl.rs b/crates/wasi-common/src/old/snapshot_0/sys/unix/host_impl.rs index f96473da90..50e294dd2a 100644 --- a/crates/wasi-common/src/old/snapshot_0/sys/unix/host_impl.rs +++ b/crates/wasi-common/src/old/snapshot_0/sys/unix/host_impl.rs @@ -8,7 +8,7 @@ use crate::old::snapshot_0::{helpers, sys::unix::sys_impl}; use std::ffi::OsStr; use std::io; use std::os::unix::prelude::OsStrExt; -use yanix::file::OFlag; +use yanix::file::OFlags; pub(crate) use sys_impl::host_impl::*; @@ -104,59 +104,59 @@ impl From for WasiError { } } -pub(crate) fn nix_from_fdflags(fdflags: wasi::__wasi_fdflags_t) -> OFlag { - let mut nix_flags = OFlag::empty(); +pub(crate) fn nix_from_fdflags(fdflags: wasi::__wasi_fdflags_t) -> OFlags { + let mut nix_flags = OFlags::empty(); if fdflags & wasi::__WASI_FDFLAGS_APPEND != 0 { - nix_flags.insert(OFlag::APPEND); + nix_flags.insert(OFlags::APPEND); } if fdflags & wasi::__WASI_FDFLAGS_DSYNC != 0 { - nix_flags.insert(OFlag::DSYNC); + nix_flags.insert(OFlags::DSYNC); } if fdflags & wasi::__WASI_FDFLAGS_NONBLOCK != 0 { - nix_flags.insert(OFlag::NONBLOCK); + nix_flags.insert(OFlags::NONBLOCK); } if fdflags & wasi::__WASI_FDFLAGS_RSYNC != 0 { nix_flags.insert(O_RSYNC); } if fdflags & wasi::__WASI_FDFLAGS_SYNC != 0 { - nix_flags.insert(OFlag::SYNC); + nix_flags.insert(OFlags::SYNC); } nix_flags } -pub(crate) fn fdflags_from_nix(oflags: OFlag) -> wasi::__wasi_fdflags_t { +pub(crate) fn fdflags_from_nix(oflags: OFlags) -> wasi::__wasi_fdflags_t { let mut fdflags = 0; - if oflags.contains(OFlag::APPEND) { + if oflags.contains(OFlags::APPEND) { fdflags |= wasi::__WASI_FDFLAGS_APPEND; } - if oflags.contains(OFlag::DSYNC) { + if oflags.contains(OFlags::DSYNC) { fdflags |= wasi::__WASI_FDFLAGS_DSYNC; } - if oflags.contains(OFlag::NONBLOCK) { + if oflags.contains(OFlags::NONBLOCK) { fdflags |= wasi::__WASI_FDFLAGS_NONBLOCK; } if oflags.contains(O_RSYNC) { fdflags |= wasi::__WASI_FDFLAGS_RSYNC; } - if oflags.contains(OFlag::SYNC) { + if oflags.contains(OFlags::SYNC) { fdflags |= wasi::__WASI_FDFLAGS_SYNC; } fdflags } -pub(crate) fn nix_from_oflags(oflags: wasi::__wasi_oflags_t) -> OFlag { - let mut nix_flags = OFlag::empty(); +pub(crate) fn nix_from_oflags(oflags: wasi::__wasi_oflags_t) -> OFlags { + let mut nix_flags = OFlags::empty(); if oflags & wasi::__WASI_OFLAGS_CREAT != 0 { - nix_flags.insert(OFlag::CREAT); + nix_flags.insert(OFlags::CREAT); } if oflags & wasi::__WASI_OFLAGS_DIRECTORY != 0 { - nix_flags.insert(OFlag::DIRECTORY); + nix_flags.insert(OFlags::DIRECTORY); } if oflags & wasi::__WASI_OFLAGS_EXCL != 0 { - nix_flags.insert(OFlag::EXCL); + nix_flags.insert(OFlags::EXCL); } if oflags & wasi::__WASI_OFLAGS_TRUNC != 0 { - nix_flags.insert(OFlag::TRUNC); + nix_flags.insert(OFlags::TRUNC); } nix_flags } diff --git a/crates/wasi-common/src/old/snapshot_0/sys/unix/hostcalls_impl/fs.rs b/crates/wasi-common/src/old/snapshot_0/sys/unix/hostcalls_impl/fs.rs index 3d106a4397..cfbbb1ead5 100644 --- a/crates/wasi-common/src/old/snapshot_0/sys/unix/hostcalls_impl/fs.rs +++ b/crates/wasi-common/src/old/snapshot_0/sys/unix/hostcalls_impl/fs.rs @@ -72,14 +72,14 @@ pub(crate) fn path_create_directory(resolved: PathGet) -> WasiResult<()> { } pub(crate) fn path_link(resolved_old: PathGet, resolved_new: PathGet) -> WasiResult<()> { - use yanix::file::{linkat, AtFlag}; + use yanix::file::{linkat, AtFlags}; unsafe { linkat( resolved_old.dirfd().as_raw_fd(), resolved_old.path(), resolved_new.dirfd().as_raw_fd(), resolved_new.path(), - AtFlag::SYMLINK_FOLLOW, + AtFlags::SYMLINK_FOLLOW, ) } .map_err(Into::into) @@ -92,18 +92,18 @@ pub(crate) fn path_open( oflags: wasi::__wasi_oflags_t, fs_flags: wasi::__wasi_fdflags_t, ) -> WasiResult { - use yanix::file::{fstatat, openat, AtFlag, FileType, Mode, OFlag}; + use yanix::file::{fstatat, openat, AtFlags, FileType, Mode, OFlags}; let mut nix_all_oflags = if read && write { - OFlag::RDWR + OFlags::RDWR } else if write { - OFlag::WRONLY + OFlags::WRONLY } else { - OFlag::RDONLY + OFlags::RDONLY }; // on non-Capsicum systems, we always want nofollow - nix_all_oflags.insert(OFlag::NOFOLLOW); + nix_all_oflags.insert(OFlags::NOFOLLOW); // convert open flags nix_all_oflags.insert(host_impl::nix_from_oflags(oflags)); @@ -135,7 +135,7 @@ pub(crate) fn path_open( fstatat( resolved.dirfd().as_raw_fd(), resolved.path(), - AtFlag::SYMLINK_NOFOLLOW, + AtFlags::SYMLINK_NOFOLLOW, ) } { Ok(stat) => { @@ -151,13 +151,13 @@ pub(crate) fn path_open( // Linux returns ENOTDIR instead of ELOOP when using O_NOFOLLOW|O_DIRECTORY // on a symlink. libc::ENOTDIR - if !(nix_all_oflags & (OFlag::NOFOLLOW | OFlag::DIRECTORY)).is_empty() => + if !(nix_all_oflags & (OFlags::NOFOLLOW | OFlags::DIRECTORY)).is_empty() => { match unsafe { fstatat( resolved.dirfd().as_raw_fd(), resolved.path(), - AtFlag::SYMLINK_NOFOLLOW, + AtFlags::SYMLINK_NOFOLLOW, ) } { Ok(stat) => { @@ -172,7 +172,7 @@ pub(crate) fn path_open( } // FreeBSD returns EMLINK instead of ELOOP when using O_NOFOLLOW on // a symlink. - libc::EMLINK if !(nix_all_oflags & OFlag::NOFOLLOW).is_empty() => { + libc::EMLINK if !(nix_all_oflags & OFlags::NOFOLLOW).is_empty() => { return Err(WasiError::ELOOP); } _ => {} @@ -212,10 +212,10 @@ pub(crate) fn path_filestat_get( resolved: PathGet, dirflags: wasi::__wasi_lookupflags_t, ) -> WasiResult { - use yanix::file::{fstatat, AtFlag}; + use yanix::file::{fstatat, AtFlags}; let atflags = match dirflags { - 0 => AtFlag::empty(), - _ => AtFlag::SYMLINK_NOFOLLOW, + 0 => AtFlags::empty(), + _ => AtFlags::SYMLINK_NOFOLLOW, }; unsafe { fstatat(resolved.dirfd().as_raw_fd(), resolved.path(), atflags) } .map_err(Into::into) @@ -270,12 +270,12 @@ pub(crate) fn path_filestat_set_times( } pub(crate) fn path_remove_directory(resolved: PathGet) -> WasiResult<()> { - use yanix::file::{unlinkat, AtFlag}; + use yanix::file::{unlinkat, AtFlags}; unsafe { unlinkat( resolved.dirfd().as_raw_fd(), resolved.path(), - AtFlag::REMOVEDIR, + AtFlags::REMOVEDIR, ) } .map_err(Into::into) diff --git a/crates/wasi-common/src/old/snapshot_0/sys/unix/hostcalls_impl/fs_helpers.rs b/crates/wasi-common/src/old/snapshot_0/sys/unix/hostcalls_impl/fs_helpers.rs index 0be360f3d5..23ad31a578 100644 --- a/crates/wasi-common/src/old/snapshot_0/sys/unix/hostcalls_impl/fs_helpers.rs +++ b/crates/wasi-common/src/old/snapshot_0/sys/unix/hostcalls_impl/fs_helpers.rs @@ -3,7 +3,7 @@ use crate::old::snapshot_0::sys::host_impl; use crate::old::snapshot_0::wasi::{self, WasiResult}; use std::fs::File; -use yanix::file::OFlag; +use yanix::file::OFlags; pub(crate) fn path_open_rights( rights_base: wasi::__wasi_rights_t, @@ -17,19 +17,19 @@ pub(crate) fn path_open_rights( // convert open flags let oflags = host_impl::nix_from_oflags(oflags); - if oflags.contains(OFlag::CREAT) { + if oflags.contains(OFlags::CREAT) { needed_base |= wasi::__WASI_RIGHTS_PATH_CREATE_FILE; } - if oflags.contains(OFlag::TRUNC) { + if oflags.contains(OFlags::TRUNC) { needed_base |= wasi::__WASI_RIGHTS_PATH_FILESTAT_SET_SIZE; } // convert file descriptor flags let fdflags = host_impl::nix_from_fdflags(fs_flags); - if fdflags.contains(OFlag::DSYNC) { + if fdflags.contains(OFlags::DSYNC) { needed_inheriting |= wasi::__WASI_RIGHTS_FD_DATASYNC; } - if fdflags.intersects(host_impl::O_RSYNC | OFlag::SYNC) { + if fdflags.intersects(host_impl::O_RSYNC | OFlags::SYNC) { needed_inheriting |= wasi::__WASI_RIGHTS_FD_SYNC; } @@ -46,7 +46,7 @@ pub(crate) fn openat(dirfd: &File, path: &str) -> WasiResult { openat( dirfd.as_raw_fd(), path, - OFlag::RDONLY | OFlag::DIRECTORY | OFlag::NOFOLLOW, + OFlags::RDONLY | OFlags::DIRECTORY | OFlags::NOFOLLOW, Mode::empty(), ) } diff --git a/crates/wasi-common/src/old/snapshot_0/sys/unix/linux/host_impl.rs b/crates/wasi-common/src/old/snapshot_0/sys/unix/linux/host_impl.rs index 90ae925e43..0bdc802439 100644 --- a/crates/wasi-common/src/old/snapshot_0/sys/unix/linux/host_impl.rs +++ b/crates/wasi-common/src/old/snapshot_0/sys/unix/linux/host_impl.rs @@ -1,7 +1,7 @@ use crate::old::snapshot_0::wasi::{self, WasiResult}; use std::convert::TryInto; -pub(crate) const O_RSYNC: yanix::file::OFlag = yanix::file::OFlag::RSYNC; +pub(crate) const O_RSYNC: yanix::file::OFlags = yanix::file::OFlags::RSYNC; pub(crate) fn stdev_from_nix(dev: libc::dev_t) -> WasiResult { Ok(wasi::__wasi_device_t::from(dev)) diff --git a/crates/wasi-common/src/old/snapshot_0/sys/unix/linux/hostcalls_impl.rs b/crates/wasi-common/src/old/snapshot_0/sys/unix/linux/hostcalls_impl.rs index b0815e6814..8380f1742e 100644 --- a/crates/wasi-common/src/old/snapshot_0/sys/unix/linux/hostcalls_impl.rs +++ b/crates/wasi-common/src/old/snapshot_0/sys/unix/linux/hostcalls_impl.rs @@ -3,12 +3,12 @@ use crate::old::snapshot_0::wasi::WasiResult; use std::os::unix::prelude::AsRawFd; pub(crate) fn path_unlink_file(resolved: PathGet) -> WasiResult<()> { - use yanix::file::{unlinkat, AtFlag}; + use yanix::file::{unlinkat, AtFlags}; unsafe { unlinkat( resolved.dirfd().as_raw_fd(), resolved.path(), - AtFlag::empty(), + AtFlags::empty(), ) } .map_err(Into::into) diff --git a/crates/wasi-common/src/sys/unix/bsd/mod.rs b/crates/wasi-common/src/sys/unix/bsd/mod.rs index a521318cdf..e4941cce14 100644 --- a/crates/wasi-common/src/sys/unix/bsd/mod.rs +++ b/crates/wasi-common/src/sys/unix/bsd/mod.rs @@ -1,4 +1,4 @@ pub(crate) mod osdir; pub(crate) mod path; -pub(crate) const O_RSYNC: yanix::file::OFlag = yanix::file::OFlag::SYNC; +pub(crate) const O_RSYNC: yanix::file::OFlags = yanix::file::OFlags::SYNC; diff --git a/crates/wasi-common/src/sys/unix/bsd/path.rs b/crates/wasi-common/src/sys/unix/bsd/path.rs index 8dff951cb9..ab79064e8d 100644 --- a/crates/wasi-common/src/sys/unix/bsd/path.rs +++ b/crates/wasi-common/src/sys/unix/bsd/path.rs @@ -3,8 +3,8 @@ use crate::wasi::{Errno, Result}; use std::os::unix::prelude::AsRawFd; pub(crate) fn unlink_file(dirfd: &OsDir, path: &str) -> Result<()> { - use yanix::file::{unlinkat, AtFlag}; - match unsafe { unlinkat(dirfd.as_raw_fd(), path, AtFlag::empty()) } { + use yanix::file::{unlinkat, AtFlags}; + match unsafe { unlinkat(dirfd.as_raw_fd(), path, AtFlags::empty()) } { Err(err) => { let raw_errno = err.raw_os_error().unwrap(); // Non-Linux implementations may return EPERM when attempting to remove a @@ -17,7 +17,7 @@ pub(crate) fn unlink_file(dirfd: &OsDir, path: &str) -> Result<()> { use yanix::file::{fstatat, FileType}; if raw_errno == libc::EPERM { - match unsafe { fstatat(dirfd.as_raw_fd(), path, AtFlag::SYMLINK_NOFOLLOW) } { + match unsafe { fstatat(dirfd.as_raw_fd(), path, AtFlags::SYMLINK_NOFOLLOW) } { Ok(stat) => { if FileType::from_stat_st_mode(stat.st_mode) == FileType::Directory { return Err(Errno::Isdir); @@ -36,7 +36,7 @@ pub(crate) fn unlink_file(dirfd: &OsDir, path: &str) -> Result<()> { } pub(crate) fn symlink(old_path: &str, new_dirfd: &OsDir, new_path: &str) -> Result<()> { - use yanix::file::{fstatat, symlinkat, AtFlag}; + use yanix::file::{fstatat, symlinkat, AtFlags}; log::debug!("path_symlink old_path = {:?}", old_path); log::debug!( @@ -54,7 +54,7 @@ pub(crate) fn symlink(old_path: &str, new_dirfd: &OsDir, new_path: &str) -> Resu // the trailing slash and check if the path exists, and // adjust the error code appropriately. let new_path = new_path.trim_end_matches('/'); - match unsafe { fstatat(new_dirfd.as_raw_fd(), new_path, AtFlag::SYMLINK_NOFOLLOW) } + match unsafe { fstatat(new_dirfd.as_raw_fd(), new_path, AtFlags::SYMLINK_NOFOLLOW) } { Ok(_) => return Err(Errno::Exist), Err(err) => { @@ -74,7 +74,7 @@ pub(crate) fn rename( new_dirfd: &OsDir, new_path: &str, ) -> Result<()> { - use yanix::file::{fstatat, renameat, AtFlag}; + use yanix::file::{fstatat, renameat, AtFlags}; match unsafe { renameat( old_dirfd.as_raw_fd(), @@ -95,7 +95,7 @@ pub(crate) fn rename( // Verify on other BSD-based OSes. if err.raw_os_error().unwrap() == libc::ENOENT { // check if the source path exists - match unsafe { fstatat(old_dirfd.as_raw_fd(), old_path, AtFlag::SYMLINK_NOFOLLOW) } + match unsafe { fstatat(old_dirfd.as_raw_fd(), old_path, AtFlags::SYMLINK_NOFOLLOW) } { Ok(_) => { // check if destination contains a trailing slash diff --git a/crates/wasi-common/src/sys/unix/emscripten/mod.rs b/crates/wasi-common/src/sys/unix/emscripten/mod.rs index ed0472e45d..de004ed605 100644 --- a/crates/wasi-common/src/sys/unix/emscripten/mod.rs +++ b/crates/wasi-common/src/sys/unix/emscripten/mod.rs @@ -3,4 +3,4 @@ pub(crate) mod osdir; #[path = "../linux/path.rs"] pub(crate) mod path; -pub(crate) const O_RSYNC: yanix::file::OFlag = yanix::file::OFlag::RSYNC; +pub(crate) const O_RSYNC: yanix::file::OFlags = yanix::file::OFlags::RSYNC; diff --git a/crates/wasi-common/src/sys/unix/linux/mod.rs b/crates/wasi-common/src/sys/unix/linux/mod.rs index d8bd3e7501..15e04ef570 100644 --- a/crates/wasi-common/src/sys/unix/linux/mod.rs +++ b/crates/wasi-common/src/sys/unix/linux/mod.rs @@ -1,4 +1,4 @@ pub(crate) mod osdir; pub(crate) mod path; -pub(crate) const O_RSYNC: yanix::file::OFlag = yanix::file::OFlag::RSYNC; +pub(crate) const O_RSYNC: yanix::file::OFlags = yanix::file::OFlags::RSYNC; diff --git a/crates/wasi-common/src/sys/unix/linux/path.rs b/crates/wasi-common/src/sys/unix/linux/path.rs index 611c57d22e..9bbcb34514 100644 --- a/crates/wasi-common/src/sys/unix/linux/path.rs +++ b/crates/wasi-common/src/sys/unix/linux/path.rs @@ -3,8 +3,8 @@ use crate::wasi::Result; use std::os::unix::prelude::AsRawFd; pub(crate) fn unlink_file(dirfd: &OsDir, path: &str) -> Result<()> { - use yanix::file::{unlinkat, AtFlag}; - unsafe { unlinkat(dirfd.as_raw_fd(), path, AtFlag::empty())? }; + use yanix::file::{unlinkat, AtFlags}; + unsafe { unlinkat(dirfd.as_raw_fd(), path, AtFlags::empty())? }; Ok(()) } diff --git a/crates/wasi-common/src/sys/unix/mod.rs b/crates/wasi-common/src/sys/unix/mod.rs index e71635db04..7a28810509 100644 --- a/crates/wasi-common/src/sys/unix/mod.rs +++ b/crates/wasi-common/src/sys/unix/mod.rs @@ -36,7 +36,7 @@ use std::mem::ManuallyDrop; use std::os::unix::prelude::{AsRawFd, FileTypeExt, FromRawFd}; use std::path::Path; use yanix::clock::ClockId; -use yanix::file::{AtFlag, OFlag}; +use yanix::file::{AtFlags, OFlags}; pub(crate) use sys_impl::*; @@ -80,7 +80,7 @@ pub(super) fn get_file_type(file: &File) -> io::Result { } pub(super) fn get_rights(file: &File, file_type: &types::Filetype) -> io::Result { - use yanix::{fcntl, file::OFlag}; + use yanix::{fcntl, file::OFlags}; let (base, inheriting) = match file_type { types::Filetype::BlockDevice => ( types::Rights::block_device_base(), @@ -116,10 +116,10 @@ pub(super) fn get_rights(file: &File, file_type: &types::Filetype) -> io::Result }; let mut rights = HandleRights::new(base, inheriting); let flags = unsafe { fcntl::get_status_flags(file.as_raw_fd())? }; - let accmode = flags & OFlag::ACCMODE; - if accmode == OFlag::RDONLY { + let accmode = flags & OFlags::ACCMODE; + if accmode == OFlags::RDONLY { rights.base &= !types::Rights::FD_WRITE; - } else if accmode == OFlag::WRONLY { + } else if accmode == OFlags::WRONLY { rights.base &= !types::Rights::FD_READ; } Ok(rights) @@ -233,7 +233,7 @@ impl From for Errno { } } -impl From for OFlag { +impl From for OFlags { fn from(fdflags: types::Fdflags) -> Self { let mut nix_flags = Self::empty(); if fdflags.contains(&types::Fdflags::APPEND) { @@ -255,29 +255,29 @@ impl From for OFlag { } } -impl From for types::Fdflags { - fn from(oflags: OFlag) -> Self { +impl From for types::Fdflags { + fn from(oflags: OFlags) -> Self { let mut fdflags = Self::empty(); - if oflags.contains(OFlag::APPEND) { + if oflags.contains(OFlags::APPEND) { fdflags |= Self::APPEND; } - if oflags.contains(OFlag::DSYNC) { + if oflags.contains(OFlags::DSYNC) { fdflags |= Self::DSYNC; } - if oflags.contains(OFlag::NONBLOCK) { + if oflags.contains(OFlags::NONBLOCK) { fdflags |= Self::NONBLOCK; } if oflags.contains(O_RSYNC) { fdflags |= Self::RSYNC; } - if oflags.contains(OFlag::SYNC) { + if oflags.contains(OFlags::SYNC) { fdflags |= Self::SYNC; } fdflags } } -impl From for OFlag { +impl From for OFlags { fn from(oflags: types::Oflags) -> Self { let mut nix_flags = Self::empty(); if oflags.contains(&types::Oflags::CREAT) { @@ -355,7 +355,7 @@ impl From for types::Filetype { } } -impl From for AtFlag { +impl From for AtFlags { fn from(flags: types::Lookupflags) -> Self { match flags { types::Lookupflags::SYMLINK_FOLLOW => Self::empty(), diff --git a/crates/wasi-common/src/sys/unix/osdir.rs b/crates/wasi-common/src/sys/unix/osdir.rs index 6c4ba35655..d87b4931fb 100644 --- a/crates/wasi-common/src/sys/unix/osdir.rs +++ b/crates/wasi-common/src/sys/unix/osdir.rs @@ -23,16 +23,16 @@ impl TryFrom for OsDir { } fn get_rights(file: &File) -> io::Result { - use yanix::{fcntl, file::OFlag}; + use yanix::{fcntl, file::OFlags}; let mut rights = HandleRights::new( types::Rights::directory_base(), types::Rights::directory_inheriting(), ); let flags = unsafe { fcntl::get_status_flags(file.as_raw_fd())? }; - let accmode = flags & OFlag::ACCMODE; - if accmode == OFlag::RDONLY { + let accmode = flags & OFlags::ACCMODE; + if accmode == OFlags::RDONLY { rights.base &= !types::Rights::FD_WRITE; - } else if accmode == OFlag::WRONLY { + } else if accmode == OFlags::WRONLY { rights.base &= !types::Rights::FD_READ; } Ok(rights) diff --git a/crates/wasi-common/src/sys/unix/osfile.rs b/crates/wasi-common/src/sys/unix/osfile.rs index f4d3b6e854..3749ff1700 100644 --- a/crates/wasi-common/src/sys/unix/osfile.rs +++ b/crates/wasi-common/src/sys/unix/osfile.rs @@ -22,16 +22,16 @@ impl TryFrom for OsFile { } fn get_rights(file: &File) -> io::Result { - use yanix::{fcntl, file::OFlag}; + use yanix::{fcntl, file::OFlags}; let mut rights = HandleRights::new( types::Rights::regular_file_base(), types::Rights::regular_file_inheriting(), ); let flags = unsafe { fcntl::get_status_flags(file.as_raw_fd())? }; - let accmode = flags & OFlag::ACCMODE; - if accmode == OFlag::RDONLY { + let accmode = flags & OFlags::ACCMODE; + if accmode == OFlags::RDONLY { rights.base &= !types::Rights::FD_WRITE; - } else if accmode == OFlag::WRONLY { + } else if accmode == OFlags::WRONLY { rights.base &= !types::Rights::FD_READ; } Ok(rights) diff --git a/crates/wasi-common/src/sys/unix/path.rs b/crates/wasi-common/src/sys/unix/path.rs index e416cdd06f..fcaf98a96b 100644 --- a/crates/wasi-common/src/sys/unix/path.rs +++ b/crates/wasi-common/src/sys/unix/path.rs @@ -7,7 +7,7 @@ use std::ffi::OsStr; use std::fs::File; use std::os::unix::prelude::{AsRawFd, FromRawFd, OsStrExt}; use std::str; -use yanix::file::OFlag; +use yanix::file::OFlags; pub(crate) use super::sys_impl::path::*; @@ -30,20 +30,20 @@ pub(crate) fn open_rights( let mut needed_inheriting = input_rights.base | input_rights.inheriting; // convert open flags - let oflags: OFlag = oflags.into(); - if oflags.contains(OFlag::CREAT) { + let oflags: OFlags = oflags.into(); + if oflags.contains(OFlags::CREAT) { needed_base |= types::Rights::PATH_CREATE_FILE; } - if oflags.contains(OFlag::TRUNC) { + if oflags.contains(OFlags::TRUNC) { needed_base |= types::Rights::PATH_FILESTAT_SET_SIZE; } // convert file descriptor flags - let fdflags: OFlag = fs_flags.into(); - if fdflags.contains(OFlag::DSYNC) { + let fdflags: OFlags = fs_flags.into(); + if fdflags.contains(OFlags::DSYNC) { needed_inheriting |= types::Rights::FD_DATASYNC; } - if fdflags.intersects(super::O_RSYNC | OFlag::SYNC) { + if fdflags.intersects(super::O_RSYNC | OFlags::SYNC) { needed_inheriting |= types::Rights::FD_SYNC; } @@ -74,11 +74,11 @@ pub(crate) fn link( new_path: &str, follow_symlinks: bool, ) -> Result<()> { - use yanix::file::{linkat, AtFlag}; + use yanix::file::{linkat, AtFlags}; let flags = if follow_symlinks { - AtFlag::SYMLINK_FOLLOW + AtFlags::SYMLINK_FOLLOW } else { - AtFlag::empty() + AtFlags::empty() }; unsafe { linkat( @@ -100,18 +100,18 @@ pub(crate) fn open( oflags: types::Oflags, fs_flags: types::Fdflags, ) -> Result> { - use yanix::file::{fstatat, openat, AtFlag, FileType, Mode, OFlag}; + use yanix::file::{fstatat, openat, AtFlags, FileType, Mode, OFlags}; let mut nix_all_oflags = if read && write { - OFlag::RDWR + OFlags::RDWR } else if write { - OFlag::WRONLY + OFlags::WRONLY } else { - OFlag::RDONLY + OFlags::RDONLY }; // on non-Capsicum systems, we always want nofollow - nix_all_oflags.insert(OFlag::NOFOLLOW); + nix_all_oflags.insert(OFlags::NOFOLLOW); // convert open flags nix_all_oflags.insert(oflags.into()); @@ -141,7 +141,7 @@ pub(crate) fn open( match e.raw_os_error().unwrap() { // Linux returns ENXIO instead of EOPNOTSUPP when opening a socket libc::ENXIO => { - match unsafe { fstatat(dirfd.as_raw_fd(), path, AtFlag::SYMLINK_NOFOLLOW) } { + match unsafe { fstatat(dirfd.as_raw_fd(), path, AtFlags::SYMLINK_NOFOLLOW) } { Ok(stat) => { if FileType::from_stat_st_mode(stat.st_mode) == FileType::Socket { return Err(Errno::Notsup); @@ -155,9 +155,9 @@ pub(crate) fn open( // Linux returns ENOTDIR instead of ELOOP when using O_NOFOLLOW|O_DIRECTORY // on a symlink. libc::ENOTDIR - if !(nix_all_oflags & (OFlag::NOFOLLOW | OFlag::DIRECTORY)).is_empty() => + if !(nix_all_oflags & (OFlags::NOFOLLOW | OFlags::DIRECTORY)).is_empty() => { - match unsafe { fstatat(dirfd.as_raw_fd(), path, AtFlag::SYMLINK_NOFOLLOW) } { + match unsafe { fstatat(dirfd.as_raw_fd(), path, AtFlags::SYMLINK_NOFOLLOW) } { Ok(stat) => { if FileType::from_stat_st_mode(stat.st_mode) == FileType::Symlink { return Err(Errno::Loop); @@ -170,7 +170,7 @@ pub(crate) fn open( } // FreeBSD returns EMLINK instead of ELOOP when using O_NOFOLLOW on // a symlink. - libc::EMLINK if !(nix_all_oflags & OFlag::NOFOLLOW).is_empty() => { + libc::EMLINK if !(nix_all_oflags & OFlags::NOFOLLOW).is_empty() => { return Err(Errno::Loop); } _ => {} @@ -201,17 +201,17 @@ pub(crate) fn readlink(dirfd: &OsDir, path: &str, buf: &mut [u8]) -> Result Result<()> { - use yanix::file::{unlinkat, AtFlag}; - unsafe { unlinkat(dirfd.as_raw_fd(), path, AtFlag::REMOVEDIR)? }; + use yanix::file::{unlinkat, AtFlags}; + unsafe { unlinkat(dirfd.as_raw_fd(), path, AtFlags::REMOVEDIR)? }; Ok(()) } pub(crate) fn filestat_get_at(dirfd: &OsDir, path: &str, follow: bool) -> Result { - use yanix::file::{fstatat, AtFlag}; + use yanix::file::{fstatat, AtFlags}; let flags = if follow { - AtFlag::empty() + AtFlags::empty() } else { - AtFlag::SYMLINK_NOFOLLOW + AtFlags::SYMLINK_NOFOLLOW }; let stat = unsafe { fstatat(dirfd.as_raw_fd(), path, flags)? }; let stat = stat.try_into()?; diff --git a/crates/wasi-common/yanix/src/fcntl.rs b/crates/wasi-common/yanix/src/fcntl.rs index b82e41cfc8..12c57cbd47 100644 --- a/crates/wasi-common/yanix/src/fcntl.rs +++ b/crates/wasi-common/yanix/src/fcntl.rs @@ -1,5 +1,5 @@ use crate::{ - file::{FdFlag, OFlag}, + file::{FdFlags, OFlags}, from_result, from_success_code, }; use std::io::Result; @@ -17,18 +17,18 @@ pub unsafe fn dup_fd(fd: RawFd, close_on_exec: bool) -> Result { }) } -pub unsafe fn get_fd_flags(fd: RawFd) -> Result { - from_result(libc::fcntl(fd, libc::F_GETFD)).map(FdFlag::from_bits_truncate) +pub unsafe fn get_fd_flags(fd: RawFd) -> Result { + from_result(libc::fcntl(fd, libc::F_GETFD)).map(FdFlags::from_bits_truncate) } -pub unsafe fn set_fd_flags(fd: RawFd, flags: FdFlag) -> Result<()> { +pub unsafe fn set_fd_flags(fd: RawFd, flags: FdFlags) -> Result<()> { from_success_code(libc::fcntl(fd, libc::F_SETFD, flags.bits())) } -pub unsafe fn get_status_flags(fd: RawFd) -> Result { - from_result(libc::fcntl(fd, libc::F_GETFL)).map(OFlag::from_bits_truncate) +pub unsafe fn get_status_flags(fd: RawFd) -> Result { + from_result(libc::fcntl(fd, libc::F_GETFL)).map(OFlags::from_bits_truncate) } -pub unsafe fn set_status_flags(fd: RawFd, flags: OFlag) -> Result<()> { +pub unsafe fn set_status_flags(fd: RawFd, flags: OFlags) -> Result<()> { from_success_code(libc::fcntl(fd, libc::F_SETFL, flags.bits())) } diff --git a/crates/wasi-common/yanix/src/file.rs b/crates/wasi-common/yanix/src/file.rs index 57eeb88e05..c525ac444f 100644 --- a/crates/wasi-common/yanix/src/file.rs +++ b/crates/wasi-common/yanix/src/file.rs @@ -11,13 +11,13 @@ use std::{ pub use crate::sys::file::*; bitflags! { - pub struct FdFlag: libc::c_int { + pub struct FdFlags: libc::c_int { const CLOEXEC = libc::FD_CLOEXEC; } } bitflags! { - pub struct AtFlag: libc::c_int { + pub struct AtFlags: libc::c_int { const REMOVEDIR = libc::AT_REMOVEDIR; const SYMLINK_FOLLOW = libc::AT_SYMLINK_FOLLOW; const SYMLINK_NOFOLLOW = libc::AT_SYMLINK_NOFOLLOW; @@ -48,7 +48,7 @@ bitflags! { } bitflags! { - pub struct OFlag: libc::c_int { + pub struct OFlags: libc::c_int { const ACCMODE = libc::O_ACCMODE; const APPEND = libc::O_APPEND; const CREAT = libc::O_CREAT; @@ -155,7 +155,7 @@ impl FileType { pub unsafe fn openat>( dirfd: RawFd, path: P, - oflag: OFlag, + oflag: OFlags, mode: Mode, ) -> Result { let path = CString::new(path.as_ref().as_bytes())?; @@ -194,7 +194,7 @@ pub unsafe fn linkat>( old_path: P, new_dirfd: RawFd, new_path: P, - flags: AtFlag, + flags: AtFlags, ) -> Result<()> { let old_path = CString::new(old_path.as_ref().as_bytes())?; let new_path = CString::new(new_path.as_ref().as_bytes())?; @@ -207,7 +207,7 @@ pub unsafe fn linkat>( )) } -pub unsafe fn unlinkat>(dirfd: RawFd, path: P, flags: AtFlag) -> Result<()> { +pub unsafe fn unlinkat>(dirfd: RawFd, path: P, flags: AtFlags) -> Result<()> { let path = CString::new(path.as_ref().as_bytes())?; from_success_code(libc::unlinkat(dirfd, path.as_ptr(), flags.bits())) } @@ -238,7 +238,11 @@ pub unsafe fn symlinkat>(old_path: P, new_dirfd: RawFd, new_path )) } -pub unsafe fn fstatat>(dirfd: RawFd, path: P, flags: AtFlag) -> Result { +pub unsafe fn fstatat>( + dirfd: RawFd, + path: P, + flags: AtFlags, +) -> Result { use std::mem::MaybeUninit; let path = CString::new(path.as_ref().as_bytes())?; let mut filestat = MaybeUninit::::uninit();