Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

statx: Add an example of using this to determine mountpoint #831

Merged
merged 1 commit into from
Sep 19, 2023

Conversation

cgwalters
Copy link
Contributor

@cgwalters cgwalters commented Sep 18, 2023

  • This use case is a specific reason to directly use the statx
    system call
  • It's a bit of a subtle API because there's 4 different flags
    involved, and it's not necessarily obvious that the relevant
    bitmasks aren't (yet) exposed in rustix, so one needs to use
    libc/linux-raw-sys directly
  • On the general principle of adding examples

@sunfishcode
Copy link
Member

STATX_ATTR_MOUNT_ROOT is an stx_attributues_mask flag, while the StatxFlags type is only for the flags argument to the statx call.

Rustix currently just returns the stx_attributes_mask mask as the raw u64 value, so in the code where you want to use this, you can test it for libc::STAX_ATTR_MOUNT_ROOT manually.

Another option would be to change rustix to always use a custom statx struct so that it can replace stx_attributes_mask with a bitflags type with all the STATX_ATTR_* flags.

@cgwalters cgwalters marked this pull request as draft September 19, 2023 11:58
- This use case is a specific reason to directly use the `statx`
  system call
- It's a bit of a subtle API because there's 4 different flags
  involved, and it's not necessarily obvious that the relevant
  bitmasks aren't (yet) exposed in rustix, so one needs to use
  libc/linux-raw-sys directly
- On the general principle of adding examples
@cgwalters cgwalters marked this pull request as ready for review September 19, 2023 13:44
@cgwalters
Copy link
Contributor Author

Sorry for sending a broken PR here, and thanks for the review. I will try to salvage this by updating this PR to instead add an example.

I've pushed an updated commit but at least here the GH user interface hasn't updated? (Ah yes status is degraded).

@sunfishcode
Copy link
Member

Looks good, thanks!

@sunfishcode sunfishcode merged commit 41063ba into bytecodealliance:main Sep 19, 2023
44 checks passed
@cgwalters cgwalters changed the title fs: Add StatxFlags::MOUNT_ROOT statx: Add an example of using this to determine mountpoint Sep 19, 2023
@cgwalters
Copy link
Contributor Author

Another option would be to change rustix to always use a custom statx struct so that it can replace stx_attributes_mask with a bitflags type with all the STATX_ATTR_* flags.

Indeed, this seems like a good followup. May take a look at that at some point, but at least hopefully for now the example leads people in the right direction.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants