Skip to content

Commit

Permalink
Merge #1849
Browse files Browse the repository at this point in the history
1849: Add a Statfs::flags method r=rtzoeller a=asomers

It returns the mount flags on the BSDs.  On Linux, it returns a slightly different set of flags.

Co-authored-by: Alan Somers <asomers@gmail.com>
  • Loading branch information
bors[bot] and asomers committed Oct 24, 2022
2 parents fbdac70 + b2c0361 commit 20df092
Show file tree
Hide file tree
Showing 6 changed files with 142 additions and 112 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -6,6 +6,10 @@ This project adheres to [Semantic Versioning](https://semver.org/).
## [Unreleased] - ReleaseDate
### Added

- Add `MntFlags` and `unmount` on all of the BSDs.
([#1849](https://github.com/nix-rust/nix/pull/1849))
- Added a 'Statfs::flags' method.
([#1849](https://github.com/nix-rust/nix/pull/1849))
- Added `NSFS_MAGIC` FsType on Linux and Android.
([#1829](https://github.com/nix-rust/nix/pull/1829))
- Added `sched_getcpu` on platforms that support it.
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Expand Up @@ -27,7 +27,7 @@ targets = [
]

[dependencies]
libc = { version = "0.2.135", features = [ "extra_traits" ] }
libc = { git = "https://github.com/rust-lang/libc", rev = "cc19b6f0801", features = [ "extra_traits" ] }
bitflags = "1.1"
cfg-if = "1.0"
pin-utils = { version = "0.1.0", optional = true }
Expand Down
1 change: 0 additions & 1 deletion src/lib.rs
Expand Up @@ -106,7 +106,6 @@ feature! {
#[allow(missing_docs)]
pub mod kmod;
}
#[cfg(any(target_os = "android", target_os = "freebsd", target_os = "linux"))]
feature! {
#![feature = "mount"]
pub mod mount;
Expand Down
32 changes: 23 additions & 9 deletions src/mount/bsd.rs
@@ -1,16 +1,22 @@
#[cfg(target_os = "freebsd")]
use crate::{
Error,
};
use crate::{
Errno,
NixPath,
Result,
};
use libc::{c_char, c_int, c_uint, c_void};
#[cfg(target_os = "freebsd")]
use libc::{c_char, c_uint, c_void};
use libc::c_int;
#[cfg(target_os = "freebsd")]
use std::{
borrow::Cow,
ffi::{CString, CStr},
marker::PhantomData,
fmt,
io,
marker::PhantomData,
};


Expand Down Expand Up @@ -110,12 +116,14 @@ libc_bitflags!(
///
/// It wraps an [`Errno`], but also may contain an additional message returned
/// by `nmount(2)`.
#[cfg(target_os = "freebsd")]
#[derive(Debug)]
pub struct NmountError {
errno: Error,
errmsg: Option<String>
}

#[cfg(target_os = "freebsd")]
impl NmountError {
/// Returns the additional error string sometimes generated by `nmount(2)`.
pub fn errmsg(&self) -> Option<&str> {
Expand All @@ -135,8 +143,10 @@ impl NmountError {
}
}

#[cfg(target_os = "freebsd")]
impl std::error::Error for NmountError {}

#[cfg(target_os = "freebsd")]
impl fmt::Display for NmountError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
if let Some(errmsg) = &self.errmsg {
Expand All @@ -147,13 +157,15 @@ impl fmt::Display for NmountError {
}
}

#[cfg(target_os = "freebsd")]
impl From<NmountError> for io::Error {
fn from(err: NmountError) -> Self {
err.errno.into()
}
}

/// Result type of [`Nmount::nmount`].
#[cfg(target_os = "freebsd")]
pub type NmountResult = std::result::Result<(), NmountError>;

/// Mount a FreeBSD file system.
Expand Down Expand Up @@ -425,13 +437,15 @@ impl<'a> Drop for Nmount<'a> {
///
/// Useful flags include
/// * `MNT_FORCE` - Unmount even if still in use.
/// * `MNT_BYFSID` - `mountpoint` is not a path, but a file system ID
/// encoded as `FSID:val0:val1`, where `val0` and `val1`
/// are the contents of the `fsid_t val[]` array in decimal.
/// The file system that has the specified file system ID
/// will be unmounted. See
/// [`statfs`](crate::sys::statfs::statfs) to determine the
/// `fsid`.
#[cfg_attr(target_os = "freebsd", doc = "
* `MNT_BYFSID` - `mountpoint` is not a path, but a file system ID
encoded as `FSID:val0:val1`, where `val0` and `val1`
are the contents of the `fsid_t val[]` array in decimal.
The file system that has the specified file system ID
will be unmounted. See
[`statfs`](crate::sys::statfs::statfs) to determine the
`fsid`.
")]
pub fn unmount<P>(mountpoint: &P, flags: MntFlags) -> Result<()>
where P: ?Sized + NixPath
{
Expand Down
10 changes: 10 additions & 0 deletions src/sys/socket/mod.rs
Expand Up @@ -272,14 +272,17 @@ libc_bitflags! {
/// Sends or requests out-of-band data on sockets that support this notion
/// (e.g., of type [`Stream`](enum.SockType.html)); the underlying protocol must also
/// support out-of-band data.
#[allow(deprecated)] // Suppress useless warnings from libc PR 2963
MSG_OOB;
/// Peeks at an incoming message. The data is treated as unread and the next
/// [`recv()`](fn.recv.html)
/// or similar function shall still return this data.
#[allow(deprecated)] // Suppress useless warnings from libc PR 2963
MSG_PEEK;
/// Receive operation blocks until the full amount of data can be
/// returned. The function may return smaller amount of data if a signal
/// is caught, an error or disconnect occurs.
#[allow(deprecated)] // Suppress useless warnings from libc PR 2963
MSG_WAITALL;
/// Enables nonblocking operation; if the operation would block,
/// `EAGAIN` or `EWOULDBLOCK` is returned. This provides similar
Expand All @@ -291,8 +294,10 @@ libc_bitflags! {
/// which will affect all threads in
/// the calling process and as well as other processes that hold
/// file descriptors referring to the same open file description.
#[allow(deprecated)] // Suppress useless warnings from libc PR 2963
MSG_DONTWAIT;
/// Receive flags: Control Data was discarded (buffer too small)
#[allow(deprecated)] // Suppress useless warnings from libc PR 2963
MSG_CTRUNC;
/// For raw ([`Packet`](addr/enum.AddressFamily.html)), Internet datagram
/// (since Linux 2.4.27/2.6.8),
Expand All @@ -302,15 +307,18 @@ libc_bitflags! {
/// domain ([unix(7)](https://linux.die.net/man/7/unix)) sockets.
///
/// For use with Internet stream sockets, see [tcp(7)](https://linux.die.net/man/7/tcp).
#[allow(deprecated)] // Suppress useless warnings from libc PR 2963
MSG_TRUNC;
/// Terminates a record (when this notion is supported, as for
/// sockets of type [`SeqPacket`](enum.SockType.html)).
#[allow(deprecated)] // Suppress useless warnings from libc PR 2963
MSG_EOR;
/// This flag specifies that queued errors should be received from
/// the socket error queue. (For more details, see
/// [recvfrom(2)](https://linux.die.net/man/2/recvfrom))
#[cfg(any(target_os = "android", target_os = "linux"))]
#[cfg_attr(docsrs, doc(cfg(all())))]
#[allow(deprecated)] // Suppress useless warnings from libc PR 2963
MSG_ERRQUEUE;
/// Set the `close-on-exec` flag for the file descriptor received via a UNIX domain
/// file descriptor using the `SCM_RIGHTS` operation (described in
Expand All @@ -326,6 +334,7 @@ libc_bitflags! {
target_os = "netbsd",
target_os = "openbsd"))]
#[cfg_attr(docsrs, doc(cfg(all())))]
#[allow(deprecated)] // Suppress useless warnings from libc PR 2963
MSG_CMSG_CLOEXEC;
/// Requests not to send `SIGPIPE` errors when the other end breaks the connection.
/// (For more details, see [send(2)](https://linux.die.net/man/2/send)).
Expand All @@ -340,6 +349,7 @@ libc_bitflags! {
target_os = "openbsd",
target_os = "solaris"))]
#[cfg_attr(docsrs, doc(cfg(all())))]
#[allow(deprecated)] // Suppress useless warnings from libc PR 2963
MSG_NOSIGNAL;
}
}
Expand Down

0 comments on commit 20df092

Please sign in to comment.