Skip to content

Commit 3f66d1f

Browse files
committed
Define MntFlags and unmount on all of the BSDs.
1 parent d6fdd59 commit 3f66d1f

File tree

5 files changed

+51
-97
lines changed

5 files changed

+51
-97
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ This project adheres to [Semantic Versioning](https://semver.org/).
66
## [Unreleased] - ReleaseDate
77
### Added
88

9+
- Add `MntFlags` and `unmount` on all of the BSDs.
10+
([#1849](https://github.com/nix-rust/nix/pull/1849))
911
- Added `NSFS_MAGIC` FsType on Linux and Android.
1012
([#1829](https://github.com/nix-rust/nix/pull/1829))
1113
- Added `sched_getcpu` on platforms that support it.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ targets = [
2727
]
2828

2929
[dependencies]
30-
libc = { version = "0.2.135", features = [ "extra_traits" ] }
30+
libc = { git = "https://github.com/rust-lang/libc", rev = "cc19b6f0801", features = [ "extra_traits" ] }
3131
bitflags = "1.1"
3232
cfg-if = "1.0"
3333
pin-utils = { version = "0.1.0", optional = true }

src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ feature! {
106106
#[allow(missing_docs)]
107107
pub mod kmod;
108108
}
109-
#[cfg(any(target_os = "android", target_os = "freebsd", target_os = "linux"))]
110109
feature! {
111110
#![feature = "mount"]
112111
pub mod mount;

src/mount/bsd.rs

+23-9
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
1+
#[cfg(target_os = "freebsd")]
12
use crate::{
23
Error,
4+
};
5+
use crate::{
36
Errno,
47
NixPath,
58
Result,
69
};
7-
use libc::{c_char, c_int, c_uint, c_void};
10+
#[cfg(target_os = "freebsd")]
11+
use libc::{c_char, c_uint, c_void};
12+
use libc::c_int;
13+
#[cfg(target_os = "freebsd")]
814
use std::{
915
borrow::Cow,
1016
ffi::{CString, CStr},
17+
marker::PhantomData,
1118
fmt,
1219
io,
13-
marker::PhantomData,
1420
};
1521

1622

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

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

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

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

160+
#[cfg(target_os = "freebsd")]
150161
impl From<NmountError> for io::Error {
151162
fn from(err: NmountError) -> Self {
152163
err.errno.into()
153164
}
154165
}
155166

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

159171
/// Mount a FreeBSD file system.
@@ -425,13 +437,15 @@ impl<'a> Drop for Nmount<'a> {
425437
///
426438
/// Useful flags include
427439
/// * `MNT_FORCE` - Unmount even if still in use.
428-
/// * `MNT_BYFSID` - `mountpoint` is not a path, but a file system ID
429-
/// encoded as `FSID:val0:val1`, where `val0` and `val1`
430-
/// are the contents of the `fsid_t val[]` array in decimal.
431-
/// The file system that has the specified file system ID
432-
/// will be unmounted. See
433-
/// [`statfs`](crate::sys::statfs::statfs) to determine the
434-
/// `fsid`.
440+
#[cfg_attr(target_os = "freebsd", doc = "
441+
* `MNT_BYFSID` - `mountpoint` is not a path, but a file system ID
442+
encoded as `FSID:val0:val1`, where `val0` and `val1`
443+
are the contents of the `fsid_t val[]` array in decimal.
444+
The file system that has the specified file system ID
445+
will be unmounted. See
446+
[`statfs`](crate::sys::statfs::statfs) to determine the
447+
`fsid`.
448+
")]
435449
pub fn unmount<P>(mountpoint: &P, flags: MntFlags) -> Result<()>
436450
where P: ?Sized + NixPath
437451
{

src/sys/statfs.rs

+25-86
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,9 @@ impl Statfs {
422422
target_os = "macos",
423423
target_os = "android",
424424
target_os = "freebsd",
425+
target_os = "fuchsia",
425426
target_os = "openbsd",
427+
target_os = "linux",
426428
))]
427429
#[cfg_attr(docsrs, doc(cfg(all())))]
428430
pub fn blocks(&self) -> u64 {
@@ -437,24 +439,9 @@ impl Statfs {
437439
}
438440

439441
/// Total data blocks in filesystem
440-
#[cfg(all(target_os = "linux", any(target_env = "musl", target_arch = "riscv32", all(target_arch = "x86_64", target_pointer_width = "32"))))]
442+
#[cfg(target_os = "emscripten")]
441443
#[cfg_attr(docsrs, doc(cfg(all())))]
442-
pub fn blocks(&self) -> u64 {
443-
self.0.f_blocks
444-
}
445-
446-
/// Total data blocks in filesystem
447-
#[cfg(not(any(
448-
target_os = "ios",
449-
target_os = "macos",
450-
target_os = "android",
451-
target_os = "freebsd",
452-
target_os = "openbsd",
453-
target_os = "dragonfly",
454-
all(target_os = "linux", any(target_env = "musl", target_arch = "riscv32", all(target_arch = "x86_64", target_pointer_width = "32")))
455-
)))]
456-
#[cfg_attr(docsrs, doc(cfg(all())))]
457-
pub fn blocks(&self) -> libc::c_ulong {
444+
pub fn blocks(&self) -> u32 {
458445
self.0.f_blocks
459446
}
460447

@@ -464,7 +451,9 @@ impl Statfs {
464451
target_os = "macos",
465452
target_os = "android",
466453
target_os = "freebsd",
454+
target_os = "fuchsia",
467455
target_os = "openbsd",
456+
target_os = "linux",
468457
))]
469458
#[cfg_attr(docsrs, doc(cfg(all())))]
470459
pub fn blocks_free(&self) -> u64 {
@@ -479,29 +468,20 @@ impl Statfs {
479468
}
480469

481470
/// Free blocks in filesystem
482-
#[cfg(all(target_os = "linux", any(target_env = "musl", target_arch = "riscv32", all(target_arch = "x86_64", target_pointer_width = "32"))))]
471+
#[cfg(target_os = "emscripten")]
483472
#[cfg_attr(docsrs, doc(cfg(all())))]
484-
pub fn blocks_free(&self) -> u64 {
473+
pub fn blocks_free(&self) -> u32 {
485474
self.0.f_bfree
486475
}
487476

488-
/// Free blocks in filesystem
489-
#[cfg(not(any(
477+
/// Free blocks available to unprivileged user
478+
#[cfg(any(
490479
target_os = "ios",
491480
target_os = "macos",
492481
target_os = "android",
493-
target_os = "freebsd",
494-
target_os = "openbsd",
495-
target_os = "dragonfly",
496-
all(target_os = "linux", any(target_env = "musl", target_arch = "riscv32", all(target_arch = "x86_64", target_pointer_width = "32")))
497-
)))]
498-
#[cfg_attr(docsrs, doc(cfg(all())))]
499-
pub fn blocks_free(&self) -> libc::c_ulong {
500-
self.0.f_bfree
501-
}
502-
503-
/// Free blocks available to unprivileged user
504-
#[cfg(any(target_os = "ios", target_os = "macos", target_os = "android"))]
482+
target_os = "fuchsia",
483+
target_os = "linux",
484+
))]
505485
#[cfg_attr(docsrs, doc(cfg(all())))]
506486
pub fn blocks_available(&self) -> u64 {
507487
self.0.f_bavail
@@ -522,24 +502,9 @@ impl Statfs {
522502
}
523503

524504
/// Free blocks available to unprivileged user
525-
#[cfg(all(target_os = "linux", any(target_env = "musl", target_arch = "riscv32", all(target_arch = "x86_64", target_pointer_width = "32"))))]
505+
#[cfg(target_os = "emscripten")]
526506
#[cfg_attr(docsrs, doc(cfg(all())))]
527-
pub fn blocks_available(&self) -> u64 {
528-
self.0.f_bavail
529-
}
530-
531-
/// Free blocks available to unprivileged user
532-
#[cfg(not(any(
533-
target_os = "ios",
534-
target_os = "macos",
535-
target_os = "android",
536-
target_os = "freebsd",
537-
target_os = "openbsd",
538-
target_os = "dragonfly",
539-
all(target_os = "linux", any(target_env = "musl", target_arch = "riscv32", all(target_arch = "x86_64", target_pointer_width = "32")))
540-
)))]
541-
#[cfg_attr(docsrs, doc(cfg(all())))]
542-
pub fn blocks_available(&self) -> libc::c_ulong {
507+
pub fn blocks_available(&self) -> u32 {
543508
self.0.f_bavail
544509
}
545510

@@ -549,7 +514,9 @@ impl Statfs {
549514
target_os = "macos",
550515
target_os = "android",
551516
target_os = "freebsd",
517+
target_os = "fuchsia",
552518
target_os = "openbsd",
519+
target_os = "linux",
553520
))]
554521
#[cfg_attr(docsrs, doc(cfg(all())))]
555522
pub fn files(&self) -> u64 {
@@ -564,33 +531,20 @@ impl Statfs {
564531
}
565532

566533
/// Total file nodes in filesystem
567-
#[cfg(all(target_os = "linux", any(target_env = "musl", target_arch = "riscv32", all(target_arch = "x86_64", target_pointer_width = "32"))))]
534+
#[cfg(target_os = "emscripten")]
568535
#[cfg_attr(docsrs, doc(cfg(all())))]
569-
pub fn files(&self) -> libc::fsfilcnt_t {
536+
pub fn files(&self) -> u32 {
570537
self.0.f_files
571538
}
572539

573-
/// Total file nodes in filesystem
574-
#[cfg(not(any(
540+
/// Free file nodes in filesystem
541+
#[cfg(any(
575542
target_os = "ios",
576543
target_os = "macos",
577544
target_os = "android",
578-
target_os = "freebsd",
545+
target_os = "fuchsia",
579546
target_os = "openbsd",
580-
target_os = "dragonfly",
581-
all(target_os = "linux", any(target_env = "musl", target_arch = "riscv32", all(target_arch = "x86_64", target_pointer_width = "32")))
582-
)))]
583-
#[cfg_attr(docsrs, doc(cfg(all())))]
584-
pub fn files(&self) -> libc::c_ulong {
585-
self.0.f_files
586-
}
587-
588-
/// Free file nodes in filesystem
589-
#[cfg(any(
590-
target_os = "android",
591-
target_os = "ios",
592-
target_os = "macos",
593-
target_os = "openbsd"
547+
target_os = "linux",
594548
))]
595549
#[cfg_attr(docsrs, doc(cfg(all())))]
596550
pub fn files_free(&self) -> u64 {
@@ -612,24 +566,9 @@ impl Statfs {
612566
}
613567

614568
/// Free file nodes in filesystem
615-
#[cfg(all(target_os = "linux", any(target_env = "musl", target_arch = "riscv32", all(target_arch = "x86_64", target_pointer_width = "32"))))]
616-
#[cfg_attr(docsrs, doc(cfg(all())))]
617-
pub fn files_free(&self) -> libc::fsfilcnt_t {
618-
self.0.f_ffree
619-
}
620-
621-
/// Free file nodes in filesystem
622-
#[cfg(not(any(
623-
target_os = "ios",
624-
target_os = "macos",
625-
target_os = "android",
626-
target_os = "freebsd",
627-
target_os = "openbsd",
628-
target_os = "dragonfly",
629-
all(target_os = "linux", any(target_env = "musl", target_arch = "riscv32", all(target_arch = "x86_64", target_pointer_width = "32")))
630-
)))]
569+
#[cfg(target_os = "emscripten")]
631570
#[cfg_attr(docsrs, doc(cfg(all())))]
632-
pub fn files_free(&self) -> libc::c_ulong {
571+
pub fn files_free(&self) -> u32 {
633572
self.0.f_ffree
634573
}
635574

0 commit comments

Comments
 (0)