@@ -9,7 +9,7 @@ use core::mem;
99use crate :: fs:: Metadata ;
1010#[ allow( deprecated) ]
1111use crate :: os:: linux:: raw;
12- use crate :: os:: raw:: c_void;
12+ use crate :: os:: raw:: { c_uint , c_void} ;
1313use crate :: sys:: AsInner ;
1414use crate :: sys:: fs:: cfg_has_statx;
1515cfg_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
@@ -52,11 +61,18 @@ pub trait MetadataExt {
5261 fn as_raw_stat ( & self ) -> & raw:: stat ;
5362
5463 /// Creates a [`Metadata`] from a const void pointer populated by the [`statx`] syscall.
64+ /// Note that the relevant information is copied out of the structure and the pointer is
65+ /// not retained past the call.
66+ ///
67+ /// Currently [`Metadata::from_statx`] is only supported on Linux platforms with a target
68+ /// environment of GNU.
5569 ///
5670 /// # Safety
5771 ///
5872 /// The caller must take care to provide a valid const void pointer containing information
59- /// populated by the [`statx`] syscall.
73+ /// populated by the [`statx`] syscall. In particular, the provided pointer should contain
74+ /// statx information pertaining to the mask [`STATX_MASK`], so that there will be no
75+ /// uninitialized data encountered in constructing [`Metadata`].
6076 ///
6177 /// [`Metadata`]: crate::fs::Metadata
6278 /// [`statx`]: https://docs.rs/libc/latest/libc/struct.statx.html
@@ -67,7 +83,7 @@ pub trait MetadataExt {
6783 /// use std::ffi::c_void;
6884 /// use std::fs::{write, Metadata};
6985 /// use std::io;
70- /// use std::os::linux::fs::MetadataExt;
86+ /// use std::os::linux::fs::{ MetadataExt, STATX_MASK} ;
7187 ///
7288 /// fn main() -> io::Result<()> {
7389 /// write("hello.txt", "Hello World!")?;
@@ -77,7 +93,7 @@ pub trait MetadataExt {
7793 /// libc::AT_FDCWD,
7894 /// "hello.txt".as_ptr().cast(),
7995 /// libc::AT_STATX_SYNC_AS_STAT,
80- /// libc::STATX_BASIC_STATS ,
96+ /// STATX_MASK ,
8197 /// buf.as_mut_ptr().cast()
8298 /// );
8399 /// }
0 commit comments