summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Somers <asomers@gmail.com>2022-10-18 08:38:16 -0600
committerAlan Somers <asomers@gmail.com>2022-10-23 22:41:07 -0600
commit3f66d1f4ce06403f646876864260c59ca3627ee4 (patch)
tree22764a3f53b830dfb55db2f979de4805e3981d9d
parentd6fdd5952deb826a0428ba54f08f8048291030c0 (diff)
downloadnix-3f66d1f4ce06403f646876864260c59ca3627ee4.zip
Define `MntFlags` and `unmount` on all of the BSDs.
-rw-r--r--CHANGELOG.md2
-rw-r--r--Cargo.toml2
-rw-r--r--src/lib.rs1
-rw-r--r--src/mount/bsd.rs32
-rw-r--r--src/sys/statfs.rs111
5 files changed, 51 insertions, 97 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index de01c2f7..5c3a3d1d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,8 @@ 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 `NSFS_MAGIC` FsType on Linux and Android.
([#1829](https://github.com/nix-rust/nix/pull/1829))
- Added `sched_getcpu` on platforms that support it.
diff --git a/Cargo.toml b/Cargo.toml
index 2edb003b..e09f758a 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -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 }
diff --git a/src/lib.rs b/src/lib.rs
index 770258dd..6b821257 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -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;
diff --git a/src/mount/bsd.rs b/src/mount/bsd.rs
index 109522f9..1ba8b809 100644
--- a/src/mount/bsd.rs
+++ b/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,
};
@@ -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> {
@@ -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 {
@@ -147,6 +157,7 @@ impl fmt::Display for NmountError {
}
}
+#[cfg(target_os = "freebsd")]
impl From<NmountError> for io::Error {
fn from(err: NmountError) -> Self {
err.errno.into()
@@ -154,6 +165,7 @@ impl From<NmountError> for io::Error {
}
/// Result type of [`Nmount::nmount`].
+#[cfg(target_os = "freebsd")]
pub type NmountResult = std::result::Result<(), NmountError>;
/// Mount a FreeBSD file system.
@@ -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
{
diff --git a/src/sys/statfs.rs b/src/sys/statfs.rs
index a302b4e8..acbc75cd 100644
--- a/src/sys/statfs.rs
+++ b/src/sys/statfs.rs
@@ -422,7 +422,9 @@ impl Statfs {
target_os = "macos",
target_os = "android",
target_os = "freebsd",
+ target_os = "fuchsia",
target_os = "openbsd",
+ target_os = "linux",
))]
#[cfg_attr(docsrs, doc(cfg(all())))]
pub fn blocks(&self) -> u64 {
@@ -437,24 +439,9 @@ impl Statfs {
}
/// Total data blocks in filesystem
- #[cfg(all(target_os = "linux", any(target_env = "musl", target_arch = "riscv32", all(target_arch = "x86_64", target_pointer_width = "32"))))]
+ #[cfg(target_os = "emscripten")]
#[cfg_attr(docsrs, doc(cfg(all())))]
- pub fn blocks(&self) -> u64 {
- self.0.f_blocks
- }
-
- /// Total data blocks in filesystem
- #[cfg(not(any(
- target_os = "ios",
- target_os = "macos",
- target_os = "android",
- target_os = "freebsd",
- target_os = "openbsd",
- target_os = "dragonfly",
- all(target_os = "linux", any(target_env = "musl", target_arch = "riscv32", all(target_arch = "x86_64", target_pointer_width = "32")))
- )))]
- #[cfg_attr(docsrs, doc(cfg(all())))]
- pub fn blocks(&self) -> libc::c_ulong {
+ pub fn blocks(&self) -> u32 {
self.0.f_blocks
}
@@ -464,7 +451,9 @@ impl Statfs {
target_os = "macos",
target_os = "android",
target_os = "freebsd",
+ target_os = "fuchsia",
target_os = "openbsd",
+ target_os = "linux",
))]
#[cfg_attr(docsrs, doc(cfg(all())))]
pub fn blocks_free(&self) -> u64 {
@@ -479,29 +468,20 @@ impl Statfs {
}
/// Free blocks in filesystem
- #[cfg(all(target_os = "linux", any(target_env = "musl", target_arch = "riscv32", all(target_arch = "x86_64", target_pointer_width = "32"))))]
+ #[cfg(target_os = "emscripten")]
#[cfg_attr(docsrs, doc(cfg(all())))]
- pub fn blocks_free(&self) -> u64 {
+ pub fn blocks_free(&self) -> u32 {
self.0.f_bfree
}
- /// Free blocks in filesystem
- #[cfg(not(any(
+ /// Free blocks available to unprivileged user
+ #[cfg(any(
target_os = "ios",
target_os = "macos",
target_os = "android",
- target_os = "freebsd",
- target_os = "openbsd",
- target_os = "dragonfly",
- all(target_os = "linux", any(target_env = "musl", target_arch = "riscv32", all(target_arch = "x86_64", target_pointer_width = "32")))
- )))]
- #[cfg_attr(docsrs, doc(cfg(all())))]
- pub fn blocks_free(&self) -> libc::c_ulong {
- self.0.f_bfree
- }
-
- /// Free blocks available to unprivileged user
- #[cfg(any(target_os = "ios", target_os = "macos", target_os = "android"))]
+ target_os = "fuchsia",
+ target_os = "linux",
+ ))]
#[cfg_attr(docsrs, doc(cfg(all())))]
pub fn blocks_available(&self) -> u64 {
self.0.f_bavail
@@ -522,24 +502,9 @@ impl Statfs {
}
/// Free blocks available to unprivileged user
- #[cfg(all(target_os = "linux", any(target_env = "musl", target_arch = "riscv32", all(target_arch = "x86_64", target_pointer_width = "32"))))]
+ #[cfg(target_os = "emscripten")]
#[cfg_attr(docsrs, doc(cfg(all())))]
- pub fn blocks_available(&self) -> u64 {
- self.0.f_bavail
- }
-
- /// Free blocks available to unprivileged user
- #[cfg(not(any(
- target_os = "ios",
- target_os = "macos",
- target_os = "android",
- target_os = "freebsd",
- target_os = "openbsd",
- target_os = "dragonfly",
- all(target_os = "linux", any(target_env = "musl", target_arch = "riscv32", all(target_arch = "x86_64", target_pointer_width = "32")))
- )))]
- #[cfg_attr(docsrs, doc(cfg(all())))]
- pub fn blocks_available(&self) -> libc::c_ulong {
+ pub fn blocks_available(&self) -> u32 {
self.0.f_bavail
}
@@ -549,7 +514,9 @@ impl Statfs {
target_os = "macos",
target_os = "android",
target_os = "freebsd",
+ target_os = "fuchsia",
target_os = "openbsd",
+ target_os = "linux",
))]
#[cfg_attr(docsrs, doc(cfg(all())))]
pub fn files(&self) -> u64 {
@@ -564,33 +531,20 @@ impl Statfs {
}
/// Total file nodes in filesystem
- #[cfg(all(target_os = "linux", any(target_env = "musl", target_arch = "riscv32", all(target_arch = "x86_64", target_pointer_width = "32"))))]
+ #[cfg(target_os = "emscripten")]
#[cfg_attr(docsrs, doc(cfg(all())))]
- pub fn files(&self) -> libc::fsfilcnt_t {
+ pub fn files(&self) -> u32 {
self.0.f_files
}
- /// Total file nodes in filesystem
- #[cfg(not(any(
+ /// Free file nodes in filesystem
+ #[cfg(any(
target_os = "ios",
target_os = "macos",
target_os = "android",
- target_os = "freebsd",
+ target_os = "fuchsia",
target_os = "openbsd",
- target_os = "dragonfly",
- all(target_os = "linux", any(target_env = "musl", target_arch = "riscv32", all(target_arch = "x86_64", target_pointer_width = "32")))
- )))]
- #[cfg_attr(docsrs, doc(cfg(all())))]
- pub fn files(&self) -> libc::c_ulong {
- self.0.f_files
- }
-
- /// Free file nodes in filesystem
- #[cfg(any(
- target_os = "android",
- target_os = "ios",
- target_os = "macos",
- target_os = "openbsd"
+ target_os = "linux",
))]
#[cfg_attr(docsrs, doc(cfg(all())))]
pub fn files_free(&self) -> u64 {
@@ -612,24 +566,9 @@ impl Statfs {
}
/// Free file nodes in filesystem
- #[cfg(all(target_os = "linux", any(target_env = "musl", target_arch = "riscv32", all(target_arch = "x86_64", target_pointer_width = "32"))))]
- #[cfg_attr(docsrs, doc(cfg(all())))]
- pub fn files_free(&self) -> libc::fsfilcnt_t {
- self.0.f_ffree
- }
-
- /// Free file nodes in filesystem
- #[cfg(not(any(
- target_os = "ios",
- target_os = "macos",
- target_os = "android",
- target_os = "freebsd",
- target_os = "openbsd",
- target_os = "dragonfly",
- all(target_os = "linux", any(target_env = "musl", target_arch = "riscv32", all(target_arch = "x86_64", target_pointer_width = "32")))
- )))]
+ #[cfg(target_os = "emscripten")]
#[cfg_attr(docsrs, doc(cfg(all())))]
- pub fn files_free(&self) -> libc::c_ulong {
+ pub fn files_free(&self) -> u32 {
self.0.f_ffree
}