Skip to content

Commit ee5ca82

Browse files
committed
Added STATX_MASK constant and included documentation for it
1 parent af938e3 commit ee5ca82

1 file changed

Lines changed: 18 additions & 4 deletions

File tree

  • library/std/src/os/linux

library/std/src/os/linux/fs.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use core::mem;
99
use crate::fs::Metadata;
1010
#[allow(deprecated)]
1111
use crate::os::linux::raw;
12-
use crate::os::raw::c_void;
12+
use crate::os::raw::{c_uint, c_void};
1313
use crate::sys::AsInner;
1414
use crate::sys::fs::cfg_has_statx;
1515
cfg_has_statx! {{
@@ -19,6 +19,15 @@ cfg_has_statx! {{
1919
use crate::sys::unsupported;
2020
}}
2121

22+
/// This is the [`statx`] mask expected by [`Metadata::from_statx`], which sets both
23+
/// `STATX_BASIC_STATS` and `STATX_BTIME`. See the [Linux man page] for statx for more
24+
/// details.
25+
///
26+
/// [`statx`]: https://docs.rs/libc/latest/libc/struct.statx.html
27+
/// [Linux man page]: https://man7.org/linux/man-pages/man2/statx.2.html
28+
#[unstable(feature = "metadata_statx", issue = "156268")]
29+
pub const STATX_MASK: c_uint = libc::STATX_BASIC_STATS | libc::STATX_BTIME;
30+
2231
/// OS-specific extensions to [`fs::Metadata`].
2332
///
2433
/// [`fs::Metadata`]: crate::fs::Metadata
@@ -53,10 +62,15 @@ pub trait MetadataExt {
5362

5463
/// Creates a [`Metadata`] from a const void pointer populated by the [`statx`] syscall.
5564
///
65+
/// Currently [`Metadata::from_statx`] is only supported on Linux platforms with a target
66+
/// environment of GNU.
67+
///
5668
/// # Safety
5769
///
5870
/// The caller must take care to provide a valid const void pointer containing information
59-
/// populated by the [`statx`] syscall.
71+
/// populated by the [`statx`] syscall. In particular, the provided pointer should contain
72+
/// statx information pertaining to the mask [`STATX_MASK`], so that there will be no
73+
/// uninitialized data encountered in constructing [`Metadata`].
6074
///
6175
/// [`Metadata`]: crate::fs::Metadata
6276
/// [`statx`]: https://docs.rs/libc/latest/libc/struct.statx.html
@@ -67,7 +81,7 @@ pub trait MetadataExt {
6781
/// use std::ffi::c_void;
6882
/// use std::fs::{write, Metadata};
6983
/// use std::io;
70-
/// use std::os::linux::fs::MetadataExt;
84+
/// use std::os::linux::fs::{MetadataExt, STATX_MASK};
7185
///
7286
/// fn main() -> io::Result<()> {
7387
/// write("hello.txt", "Hello World!")?;
@@ -77,7 +91,7 @@ pub trait MetadataExt {
7791
/// libc::AT_FDCWD,
7892
/// "hello.txt".as_ptr().cast(),
7993
/// libc::AT_STATX_SYNC_AS_STAT,
80-
/// libc::STATX_BASIC_STATS,
94+
/// STATX_MASK,
8195
/// buf.as_mut_ptr().cast()
8296
/// );
8397
/// }

0 commit comments

Comments
 (0)