Skip to content

Implement Metadata:from_statx for Linux MetadataExt trait#156269

Open
asder8215 wants to merge 2 commits into
rust-lang:mainfrom
asder8215:statx_metadata
Open

Implement Metadata:from_statx for Linux MetadataExt trait#156269
asder8215 wants to merge 2 commits into
rust-lang:mainfrom
asder8215:statx_metadata

Conversation

@asder8215
Copy link
Copy Markdown
Contributor

@asder8215 asder8215 commented May 7, 2026

This PR implements the Metadata::from_statx for Linux MetadataExt ACP. You can create a std::fs::Metadata from a *const c_void populated by the statx syscall.

The tracking issue for this ACP is here.

I had a couple of questions regarding to what Josh said in the ACP:

We'd also be interested in adding a constant for "the statx flags std normally requests", so that code wanting to request everything std knows about can use those.
^I wanted a little bit more clarity on what Josh meant by this.

  • How should I go about adding in flags/masks for populating the Metadata struct with the *const c_void pointer containing the statx info? I'm assuming it's possible that not all of the fields from our statxbuf will be submitted or given to Metadata stat fields (since I understood that this function is supposed to be flexible), so we risk accessing something not initialized?
  • Should this function return a Result<Metadata>? Should I be checking whether the given *const c_void is a null pointer or not, and returning an Error if it is?

Documentation for this function is a WIP. There's probably a lot more I have to say for this function.

@rustbot rustbot added O-linux Operating system: Linux S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels May 7, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 7, 2026

r? @jhpratt

rustbot has assigned @jhpratt.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: @ChrisDenton, libs
  • @ChrisDenton, libs expanded to 8 candidates
  • Random selection from Mark-Simulacrum, jhpratt, nia-e

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@joshtriplett
Copy link
Copy Markdown
Member

I had a couple of questions regarding to what Josh said in the ACP:

We'd also be interested in adding a constant for "the statx flags std normally requests", so that code wanting to request everything std knows about can use those.
^I wanted a little bit more clarity on what Josh meant by this.

* How should I go about adding in flags/masks for populating the `Metadata` struct with the `*const c_void` pointer containing the statx info? I'm assuming it's possible that not all of the fields from our `statxbuf` will be submitted or given to `Metadata` stat fields (since I understood that this function is supposed to be flexible), so we risk accessing something not initialized?

You can provide a single public const STATX_MASK, of type c_int, for the appropriate mask. It's the caller's responsibility to make sure std doesn't encounter uninitialized data.

* Should this function return a `Result<Metadata>`? Should I be checking whether the given `*const c_void` is a null pointer or not, and returning an `Error` if it is?

It's an unsafe function; you have to pass it a valid pointer. We could panic if we get null, as a precaution, but I'm not sure we should; I think we should just assume the pointer is valid. The function should return a Metadata.

Comment thread library/std/src/os/linux/fs.rs
@asder8215
Copy link
Copy Markdown
Contributor Author

r? libs

Comment on lines +65 to +66
/// Currently [`Metadata::from_statx`] is only supported on Linux platforms with a target
/// environment of GNU.
Copy link
Copy Markdown
Member

@Darksonn Darksonn May 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was planning to wait for #154981 before implementing this to avoid this clause.

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got you. I think the order doesn't matter right now since this function would automatically have musl support once #154981 lands as the PR updates the cfg_has_statx macro. The only thing that needs to be updated is the documentation for this function, which I'm down to keep my eyes on #154981 to see it get merged in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

O-linux Operating system: Linux S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants