Skip to content

Commit 20df092

Browse files
bors[bot]asomers
andauthored
Merge #1849
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 <[email protected]>
2 parents fbdac70 + b2c0361 commit 20df092

File tree

6 files changed

+142
-112
lines changed

6 files changed

+142
-112
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ 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))
11+
- Added a 'Statfs::flags' method.
12+
([#1849](https://github.com/nix-rust/nix/pull/1849))
913
- Added `NSFS_MAGIC` FsType on Linux and Android.
1014
([#1829](https://github.com/nix-rust/nix/pull/1829))
1115
- 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/socket/mod.rs

+10
Original file line numberDiff line numberDiff line change
@@ -272,14 +272,17 @@ libc_bitflags! {
272272
/// Sends or requests out-of-band data on sockets that support this notion
273273
/// (e.g., of type [`Stream`](enum.SockType.html)); the underlying protocol must also
274274
/// support out-of-band data.
275+
#[allow(deprecated)] // Suppress useless warnings from libc PR 2963
275276
MSG_OOB;
276277
/// Peeks at an incoming message. The data is treated as unread and the next
277278
/// [`recv()`](fn.recv.html)
278279
/// or similar function shall still return this data.
280+
#[allow(deprecated)] // Suppress useless warnings from libc PR 2963
279281
MSG_PEEK;
280282
/// Receive operation blocks until the full amount of data can be
281283
/// returned. The function may return smaller amount of data if a signal
282284
/// is caught, an error or disconnect occurs.
285+
#[allow(deprecated)] // Suppress useless warnings from libc PR 2963
283286
MSG_WAITALL;
284287
/// Enables nonblocking operation; if the operation would block,
285288
/// `EAGAIN` or `EWOULDBLOCK` is returned. This provides similar
@@ -291,8 +294,10 @@ libc_bitflags! {
291294
/// which will affect all threads in
292295
/// the calling process and as well as other processes that hold
293296
/// file descriptors referring to the same open file description.
297+
#[allow(deprecated)] // Suppress useless warnings from libc PR 2963
294298
MSG_DONTWAIT;
295299
/// Receive flags: Control Data was discarded (buffer too small)
300+
#[allow(deprecated)] // Suppress useless warnings from libc PR 2963
296301
MSG_CTRUNC;
297302
/// For raw ([`Packet`](addr/enum.AddressFamily.html)), Internet datagram
298303
/// (since Linux 2.4.27/2.6.8),
@@ -302,15 +307,18 @@ libc_bitflags! {
302307
/// domain ([unix(7)](https://linux.die.net/man/7/unix)) sockets.
303308
///
304309
/// For use with Internet stream sockets, see [tcp(7)](https://linux.die.net/man/7/tcp).
310+
#[allow(deprecated)] // Suppress useless warnings from libc PR 2963
305311
MSG_TRUNC;
306312
/// Terminates a record (when this notion is supported, as for
307313
/// sockets of type [`SeqPacket`](enum.SockType.html)).
314+
#[allow(deprecated)] // Suppress useless warnings from libc PR 2963
308315
MSG_EOR;
309316
/// This flag specifies that queued errors should be received from
310317
/// the socket error queue. (For more details, see
311318
/// [recvfrom(2)](https://linux.die.net/man/2/recvfrom))
312319
#[cfg(any(target_os = "android", target_os = "linux"))]
313320
#[cfg_attr(docsrs, doc(cfg(all())))]
321+
#[allow(deprecated)] // Suppress useless warnings from libc PR 2963
314322
MSG_ERRQUEUE;
315323
/// Set the `close-on-exec` flag for the file descriptor received via a UNIX domain
316324
/// file descriptor using the `SCM_RIGHTS` operation (described in
@@ -326,6 +334,7 @@ libc_bitflags! {
326334
target_os = "netbsd",
327335
target_os = "openbsd"))]
328336
#[cfg_attr(docsrs, doc(cfg(all())))]
337+
#[allow(deprecated)] // Suppress useless warnings from libc PR 2963
329338
MSG_CMSG_CLOEXEC;
330339
/// Requests not to send `SIGPIPE` errors when the other end breaks the connection.
331340
/// (For more details, see [send(2)](https://linux.die.net/man/2/send)).
@@ -340,6 +349,7 @@ libc_bitflags! {
340349
target_os = "openbsd",
341350
target_os = "solaris"))]
342351
#[cfg_attr(docsrs, doc(cfg(all())))]
352+
#[allow(deprecated)] // Suppress useless warnings from libc PR 2963
343353
MSG_NOSIGNAL;
344354
}
345355
}

0 commit comments

Comments
 (0)