Skip to content

Commit b494d28

Browse files
authored
Miscellaneous documentation cleanups (#1036)
* Reword the documentation for `tcsendbreak`. * Add documentation for `mount2`. * Comment formatting cleanups.
1 parent a754c48 commit b494d28

File tree

13 files changed

+72
-57
lines changed

13 files changed

+72
-57
lines changed

src/backend/libc/fs/syscalls.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -2282,7 +2282,8 @@ pub(crate) fn lgetxattr(path: &CStr, name: &CStr, value: &mut [u8]) -> io::Resul
22822282

22832283
#[cfg(apple)]
22842284
{
2285-
// Passing an empty to slice to getxattr leads to ERANGE on macOS. Pass null instead.
2285+
// Passing an empty to slice to getxattr leads to ERANGE on macOS. Pass null
2286+
// instead.
22862287
let ptr = if value.is_empty() {
22872288
core::ptr::null_mut()
22882289
} else {

src/backend/libc/net/sockopt.rs

+15-13
Original file line numberDiff line numberDiff line change
@@ -1000,11 +1000,13 @@ pub(crate) fn set_xdp_rx_ring_size(fd: BorrowedFd<'_>, value: u32) -> io::Result
10001000
#[cfg(target_os = "linux")]
10011001
#[inline]
10021002
pub(crate) fn get_xdp_mmap_offsets(fd: BorrowedFd<'_>) -> io::Result<XdpMmapOffsets> {
1003-
// The kernel will write `xdp_mmap_offsets` or `xdp_mmap_offsets_v1` to the supplied pointer,
1004-
// depending on the kernel version. Both structs only contain u64 values.
1005-
// By using the larger of both as the parameter, we can shuffle the values to the non-v1 version
1006-
// returned by `get_xdp_mmap_offsets` while keeping the return type unaffected by the kernel
1007-
// version. This works because C will layout all struct members one after the other.
1003+
// The kernel will write `xdp_mmap_offsets` or `xdp_mmap_offsets_v1` to the
1004+
// supplied pointer, depending on the kernel version. Both structs only
1005+
// contain u64 values. By using the larger of both as the parameter, we can
1006+
// shuffle the values to the non-v1 version returned by
1007+
// `get_xdp_mmap_offsets` while keeping the return type unaffected by the
1008+
// kernel version. This works because C will layout all struct members one
1009+
// after the other.
10081010

10091011
let mut optlen = core::mem::size_of::<xdp_mmap_offsets>().try_into().unwrap();
10101012
debug_assert!(
@@ -1015,8 +1017,8 @@ pub(crate) fn get_xdp_mmap_offsets(fd: BorrowedFd<'_>) -> io::Result<XdpMmapOffs
10151017
getsockopt_raw(fd, c::SOL_XDP, c::XDP_MMAP_OFFSETS, &mut value, &mut optlen)?;
10161018

10171019
if optlen as usize == core::mem::size_of::<c::xdp_mmap_offsets_v1>() {
1018-
// Safety: All members of xdp_mmap_offsets are u64 and thus are correctly initialized
1019-
// by `MaybeUninit::<xdp_statistics>::zeroed()`
1020+
// Safety: All members of xdp_mmap_offsets are u64 and thus are correctly
1021+
// initialized by `MaybeUninit::<xdp_statistics>::zeroed()`
10201022
let xpd_mmap_offsets = unsafe { value.assume_init() };
10211023
Ok(XdpMmapOffsets {
10221024
rx: XdpRingOffset {
@@ -1050,8 +1052,8 @@ pub(crate) fn get_xdp_mmap_offsets(fd: BorrowedFd<'_>) -> io::Result<XdpMmapOffs
10501052
core::mem::size_of::<xdp_mmap_offsets>(),
10511053
"unexpected getsockopt size"
10521054
);
1053-
// Safety: All members of xdp_mmap_offsets are u64 and thus are correctly initialized
1054-
// by `MaybeUninit::<xdp_statistics>::zeroed()`
1055+
// Safety: All members of xdp_mmap_offsets are u64 and thus are correctly
1056+
// initialized by `MaybeUninit::<xdp_statistics>::zeroed()`
10551057
let xpd_mmap_offsets = unsafe { value.assume_init() };
10561058
Ok(XdpMmapOffsets {
10571059
rx: XdpRingOffset {
@@ -1094,8 +1096,8 @@ pub(crate) fn get_xdp_statistics(fd: BorrowedFd<'_>) -> io::Result<XdpStatistics
10941096
getsockopt_raw(fd, c::SOL_XDP, c::XDP_STATISTICS, &mut value, &mut optlen)?;
10951097

10961098
if optlen as usize == core::mem::size_of::<xdp_statistics_v1>() {
1097-
// Safety: All members of xdp_statistics are u64 and thus are correctly initialized
1098-
// by `MaybeUninit::<xdp_statistics>::zeroed()`
1099+
// Safety: All members of xdp_statistics are u64 and thus are correctly
1100+
// initialized by `MaybeUninit::<xdp_statistics>::zeroed()`
10991101
let xdp_statistics = unsafe { value.assume_init() };
11001102
Ok(XdpStatistics {
11011103
rx_dropped: xdp_statistics.rx_dropped,
@@ -1111,8 +1113,8 @@ pub(crate) fn get_xdp_statistics(fd: BorrowedFd<'_>) -> io::Result<XdpStatistics
11111113
core::mem::size_of::<xdp_statistics>(),
11121114
"unexpected getsockopt size"
11131115
);
1114-
// Safety: All members of xdp_statistics are u64 and thus are correctly initialized
1115-
// by `MaybeUninit::<xdp_statistics>::zeroed()`
1116+
// Safety: All members of xdp_statistics are u64 and thus are correctly
1117+
// initialized by `MaybeUninit::<xdp_statistics>::zeroed()`
11161118
let xdp_statistics = unsafe { value.assume_init() };
11171119
Ok(XdpStatistics {
11181120
rx_dropped: xdp_statistics.rx_dropped,

src/backend/linux_raw/net/addr.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ use crate::backend::c;
1010
use crate::ffi::CStr;
1111
use crate::{io, path};
1212
use core::cmp::Ordering;
13-
use core::fmt;
1413
use core::hash::{Hash, Hasher};
15-
use core::slice;
14+
use core::{fmt, slice};
1615

1716
/// `struct sockaddr_un`
1817
#[derive(Clone)]

src/backend/linux_raw/net/netdevice.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
use crate::backend::io::syscalls::ioctl;
44
use crate::fd::AsFd;
55
use crate::io;
6-
use core::slice;
7-
use core::str;
6+
use core::{slice, str};
87
use linux_raw_sys::ctypes::c_char;
98
use linux_raw_sys::ioctl::SIOCGIFINDEX;
109
#[cfg(feature = "alloc")]

src/backend/linux_raw/net/sockopt.rs

+15-13
Original file line numberDiff line numberDiff line change
@@ -836,11 +836,13 @@ pub(crate) fn set_xdp_rx_ring_size(fd: BorrowedFd<'_>, value: u32) -> io::Result
836836
#[cfg(target_os = "linux")]
837837
#[inline]
838838
pub(crate) fn get_xdp_mmap_offsets(fd: BorrowedFd<'_>) -> io::Result<XdpMmapOffsets> {
839-
// The kernel will write `xdp_mmap_offsets` or `xdp_mmap_offsets_v1` to the supplied pointer,
840-
// depending on the kernel version. Both structs only contain u64 values.
841-
// By using the larger of both as the parameter, we can shuffle the values to the non-v1 version
842-
// returned by `get_xdp_mmap_offsets` while keeping the return type unaffected by the kernel
843-
// version. This works because C will layout all struct members one after the other.
839+
// The kernel will write `xdp_mmap_offsets` or `xdp_mmap_offsets_v1` to the
840+
// supplied pointer, depending on the kernel version. Both structs only
841+
// contain u64 values. By using the larger of both as the parameter, we can
842+
// shuffle the values to the non-v1 version returned by
843+
// `get_xdp_mmap_offsets` while keeping the return type unaffected by the
844+
// kernel version. This works because C will layout all struct members one
845+
// after the other.
844846

845847
let mut optlen = core::mem::size_of::<xdp_mmap_offsets>().try_into().unwrap();
846848
debug_assert!(
@@ -851,8 +853,8 @@ pub(crate) fn get_xdp_mmap_offsets(fd: BorrowedFd<'_>) -> io::Result<XdpMmapOffs
851853
getsockopt_raw(fd, c::SOL_XDP, c::XDP_MMAP_OFFSETS, &mut value, &mut optlen)?;
852854

853855
if optlen as usize == core::mem::size_of::<c::xdp_mmap_offsets_v1>() {
854-
// Safety: All members of xdp_mmap_offsets are u64 and thus are correctly initialized
855-
// by `MaybeUninit::<xdp_statistics>::zeroed()`
856+
// Safety: All members of xdp_mmap_offsets are u64 and thus are correctly
857+
// initialized by `MaybeUninit::<xdp_statistics>::zeroed()`
856858
let xpd_mmap_offsets = unsafe { value.assume_init() };
857859
Ok(XdpMmapOffsets {
858860
rx: XdpRingOffset {
@@ -886,8 +888,8 @@ pub(crate) fn get_xdp_mmap_offsets(fd: BorrowedFd<'_>) -> io::Result<XdpMmapOffs
886888
core::mem::size_of::<xdp_mmap_offsets>(),
887889
"unexpected getsockopt size"
888890
);
889-
// Safety: All members of xdp_mmap_offsets are u64 and thus are correctly initialized
890-
// by `MaybeUninit::<xdp_statistics>::zeroed()`
891+
// Safety: All members of xdp_mmap_offsets are u64 and thus are correctly
892+
// initialized by `MaybeUninit::<xdp_statistics>::zeroed()`
891893
let xpd_mmap_offsets = unsafe { value.assume_init() };
892894
Ok(XdpMmapOffsets {
893895
rx: XdpRingOffset {
@@ -930,8 +932,8 @@ pub(crate) fn get_xdp_statistics(fd: BorrowedFd<'_>) -> io::Result<XdpStatistics
930932
getsockopt_raw(fd, c::SOL_XDP, c::XDP_STATISTICS, &mut value, &mut optlen)?;
931933

932934
if optlen as usize == core::mem::size_of::<xdp_statistics_v1>() {
933-
// Safety: All members of xdp_statistics are u64 and thus are correctly initialized
934-
// by `MaybeUninit::<xdp_statistics>::zeroed()`
935+
// Safety: All members of xdp_statistics are u64 and thus are correctly
936+
// initialized by `MaybeUninit::<xdp_statistics>::zeroed()`
935937
let xdp_statistics = unsafe { value.assume_init() };
936938
Ok(XdpStatistics {
937939
rx_dropped: xdp_statistics.rx_dropped,
@@ -947,8 +949,8 @@ pub(crate) fn get_xdp_statistics(fd: BorrowedFd<'_>) -> io::Result<XdpStatistics
947949
core::mem::size_of::<xdp_statistics>(),
948950
"unexpected getsockopt size"
949951
);
950-
// Safety: All members of xdp_statistics are u64 and thus are correctly initialized
951-
// by `MaybeUninit::<xdp_statistics>::zeroed()`
952+
// Safety: All members of xdp_statistics are u64 and thus are correctly
953+
// initialized by `MaybeUninit::<xdp_statistics>::zeroed()`
952954
let xdp_statistics = unsafe { value.assume_init() };
953955
Ok(XdpStatistics {
954956
rx_dropped: xdp_statistics.rx_dropped,

src/fs/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,12 @@ impl StatExt for Stat {
167167
fn atime(&self) -> i64 {
168168
self.st_atime as i64
169169
}
170+
170171
#[inline]
171172
fn mtime(&self) -> i64 {
172173
self.st_mtime as i64
173174
}
175+
174176
#[inline]
175177
fn ctime(&self) -> i64 {
176178
self.st_ctime as i64

src/mount/mount_unmount.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,9 @@
33
use crate::backend::mount::types::{
44
InternalMountFlags, MountFlags, MountFlagsArg, MountPropagationFlags, UnmountFlags,
55
};
6-
use crate::{
7-
backend,
8-
ffi::CStr,
9-
io,
10-
path::{self, option_into_with_c_str},
11-
};
6+
use crate::ffi::CStr;
7+
use crate::path::{self, option_into_with_c_str};
8+
use crate::{backend, io};
129

1310
/// `mount(source, target, filesystemtype, mountflags, data)`
1411
///
@@ -43,6 +40,10 @@ pub fn mount<Source: path::Arg, Target: path::Arg, Fs: path::Arg, Data: path::Ar
4340

4441
/// `mount2(source, target, filesystemtype, mountflags, data)`
4542
///
43+
/// This is same as the [`mount`], except it adds support for
44+
/// the source, target, and data being omitted, and the data
45+
/// is passed as a `CStr` rather than a `path::Arg`.
46+
///
4647
/// # References
4748
/// - [Linux]
4849
///

src/net/netdevice.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
//! Low-level Linux network device access
22
//!
3-
//! The methods in this module take a socket's file descriptor to communicate with
4-
//! the kernel in their ioctl call:
3+
//! The methods in this module take a socket's file descriptor to communicate
4+
//! with the kernel in their ioctl call:
55
//! - glibc uses an `AF_UNIX`, `AF_INET`, or `AF_INET6` socket.
6-
//! The address family itself does not matter and glibc tries the next address family if socket creation with one fails.
6+
//! The address family itself does not matter and glibc tries the next address
7+
//! family if socket creation with one fails.
78
//! - Android (bionic) uses an `AF_INET` socket.
89
//! - Both create the socket with `SOCK_DGRAM|SOCK_CLOEXEC` type/flag.
9-
//! - The [man-pages] specify, that the ioctl calls "can be used on any socket's file descriptor regardless of the
10+
//! - The [man-pages] specify, that the ioctl calls "can be used on any
11+
//! socket's file descriptor regardless of the
1012
//! family or type".
1113
//!
1214
//! # References
@@ -20,7 +22,8 @@ use crate::alloc::string::String;
2022
use crate::fd::AsFd;
2123
use crate::io;
2224

23-
/// `ioctl(fd, SIOCGIFINDEX, ifreq)`—Returns the interface index for a given name.
25+
/// `ioctl(fd, SIOCGIFINDEX, ifreq)`—Returns the interface index for a given
26+
/// name.
2427
///
2528
/// See the [module-level documentation] for information about `fd` usage.
2629
///
@@ -35,7 +38,8 @@ pub fn name_to_index(fd: impl AsFd, if_name: &str) -> io::Result<u32> {
3538
crate::backend::net::netdevice::name_to_index(fd, if_name)
3639
}
3740

38-
/// `ioctl(fd, SIOCGIFNAME, ifreq)`—Returns the interface name for a given index.
41+
/// `ioctl(fd, SIOCGIFNAME, ifreq)`—Returns the interface name for a given
42+
/// index.
3943
///
4044
/// See the [module-level documentation] for information about `fd` usage.
4145
///

src/net/send_recv/msg.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,8 @@ pub struct AncillaryDrain<'buf> {
478478
}
479479

480480
impl<'buf> AncillaryDrain<'buf> {
481-
/// Create an iterator for control messages that were received without [`RecvAncillaryBuffer`].
481+
/// Create an iterator for control messages that were received without
482+
/// [`RecvAncillaryBuffer`].
482483
///
483484
/// # Safety
484485
///

src/net/socket.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,8 @@ pub fn bind_unix<Fd: AsFd>(sockfd: Fd, addr: &SocketAddrUnix) -> io::Result<()>
275275
backend::net::syscalls::bind_unix(sockfd.as_fd(), addr)
276276
}
277277

278-
/// `bind(sockfd, addr, sizeof(struct sockaddr_un))`—Binds a socket to a XDP address.
278+
/// `bind(sockfd, addr, sizeof(struct sockaddr_un))`—Binds a socket to a XDP
279+
/// address.
279280
///
280281
/// # References
281282
/// - [Linux]

src/net/types.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -1465,8 +1465,8 @@ pub mod xdp {
14651465
}
14661466
}
14671467

1468-
// Constant needs to be cast because bindgen does generate a u32 but the struct expects a u16.
1469-
// https://github.com/torvalds/linux/blob/v6.6/include/uapi/linux/if_xdp.h#L15-L44
1468+
// Constant needs to be cast because bindgen does generate a u32 but the struct
1469+
// expects a u16. https://github.com/torvalds/linux/blob/v6.6/include/uapi/linux/if_xdp.h#L15-L44
14701470
bitflags! {
14711471
/// `XDP_*` constants for use in [`SockaddrXdp`].
14721472
#[repr(transparent)]
@@ -1722,11 +1722,12 @@ pub mod xdp {
17221722
/// Offset for mmapping completion ring.
17231723
pub const XDP_UMEM_PGOFF_COMPLETION_RING: u64 = c::XDP_UMEM_PGOFF_COMPLETION_RING;
17241724

1725-
/// Offset used to shift the [`XdpDesc`] addr to the right to extract the address offset in
1726-
/// unaligned mode.
1725+
/// Offset used to shift the [`XdpDesc`] addr to the right to extract the
1726+
/// address offset in unaligned mode.
17271727
pub const XSK_UNALIGNED_BUF_OFFSET_SHIFT: u64 = c::XSK_UNALIGNED_BUF_OFFSET_SHIFT as u64;
1728-
/// Mask used to binary `and` the [`XdpDesc`] addr to extract the address without the offset
1729-
/// carried in the upper 16 bits of the address in unaligned mode.
1728+
/// Mask used to binary `and` the [`XdpDesc`] addr to extract the address
1729+
/// without the offset carried in the upper 16 bits of the address in
1730+
/// unaligned mode.
17301731
pub const XSK_UNALIGNED_BUF_ADDR_MASK: u64 = c::XSK_UNALIGNED_BUF_ADDR_MASK;
17311732
}
17321733

src/process/pidfd.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ pub fn pidfd_open(pid: Pid, flags: PidfdFlags) -> io::Result<OwnedFd> {
3030
backend::process::syscalls::pidfd_open(pid, flags)
3131
}
3232

33-
/// `syscall(SYS_pidfd_send_signal, pidfd, sig, NULL, 0)`—Send a signal to a process
34-
/// specified by a file descriptor.
33+
/// `syscall(SYS_pidfd_send_signal, pidfd, sig, NULL, 0)`—Send a signal to a
34+
/// process specified by a file descriptor.
3535
///
3636
/// # References
3737
/// - [Linux]

src/termios/tc.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,13 @@ pub fn tcsetattr<Fd: AsFd>(
107107

108108
/// `tcsendbreak(fd, 0)`—Transmit zero-valued bits.
109109
///
110-
/// Also known as the `TCSBRK` operation with `ioctl`, with a duration of 0.
110+
/// This transmits zero-valued bits for at least 0.25 seconds.
111111
///
112-
/// This function always uses an effective duration parameter of zero. For the
113-
/// equivalent of a `tcsendbreak` with a non-zero duration parameter, use
114-
/// `tcdrain`.
112+
/// This function does not have a `duration` parameter, and always uses the
113+
/// implementation-defined value, which transmits for at least 0.25 seconds.
114+
///
115+
/// Also known as the `TCSBRK` operation with `ioctl`, with a duration
116+
/// parameter of 0.
115117
///
116118
/// # References
117119
/// - [POSIX `tcsendbreak`]

0 commit comments

Comments
 (0)