Skip to content

Commit

Permalink
Define MntFlags and unmount on all of the BSDs.
Browse files Browse the repository at this point in the history
  • Loading branch information
asomers committed Oct 18, 2022
1 parent a06e80f commit 7c692e7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 a 'Statfs::flags' method.
([#1849](https://github.com/nix-rust/nix/pull/1849))
- Added `NSFS_MAGIC` FsType on Linux and Android.
Expand Down
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
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
16 changes: 14 additions & 2 deletions src/mount/bsd.rs
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 7c692e7

Please sign in to comment.