shims: improve Linux statx#4913
Conversation
|
Thank you for contributing to Miri! A reviewer will take a look at your PR, typically within a week or two. |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Sorry for the slow review!
I left some comments. Let's narrow the scope of the PR a bit and avoid those weird device number hacks. The rest looks like with a bit of cleanup it should work nicely. :)
@rustbot author
| unix => { | ||
| mask |= this.eval_libc_u32("STATX_INO") | ||
| | this.eval_libc_u32("STATX_NLINK") | ||
| | this.eval_libc_u32("STATX_UID") |
There was a problem hiding this comment.
It seems you are making a salient assumption here that every FileMetadata constructed on a unix host has all these fields. First of all, this took me some time to figure out since you didn't didn't document this assumption anywhere -- please ensure to leave more comments in the code to explain your reasoning.
Secondly, I don't think this is the right approach. Instead it'd be better if the FileMetadata type knew whether all these fields are present. That avoids non-local assumptions that could be easily broken in the future. In fact there's a concurrent PR that's about to land (#4812) that would have caused the assumption to be broken.
There was a problem hiding this comment.
Working on this. Thanks for hearing from you!
| fn linux_decode_dev(&self, dev: u64) -> (u32, u32) { | ||
| // Linux glibc and musl encode major and minor in a non-contiguous layout. | ||
| // In hex nybbles, the layout is: MMMM Mmmm mmmM MMmm | ||
|
|
||
| let major = ((dev & 0x0000_0000_000f_ff00) >> 8) | ((dev & 0xffff_f000_0000_0000) >> 32); | ||
| let minor = (dev & 0x0000_0000_0000_00ff) | ((dev & 0x0000_0fff_fff0_0000) >> 12); | ||
|
|
||
| (u32::try_from(major).unwrap(), u32::try_from(minor).unwrap()) | ||
| } | ||
|
|
||
| #[cfg(not(target_os = "linux"))] | ||
| fn linux_decode_dev(&self, _dev: u64) -> (u32, u32) { | ||
| (0, 0) | ||
| } |
There was a problem hiding this comment.
Wow, what a mess...
Unless there's a concrete need, I'd prefer to skip handling device numbers in this PR and focus on things that don't need hacks like this.
There was a problem hiding this comment.
The source code I used can be found here for glibc and here for musl. Surely we can remove from this PR for now and think about this later. Working on this.
|
Reminder, once the PR becomes ready for a review, use |
|
Has conflicts, but no worries, I work on resolving them |
|
This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
This comment has been minimized.
This comment has been minimized.
|
@rustbot ready |
|
Let's continue on #4983 that I did on the tip of the recent master branch. This looks for me safer, I messed up too much to undo reliably. |
|
Continuing in the same PR would make it much easier for me to track what changed since I first looked at the PR. If you make a new PR I have to basically redo the entire review from scratch. So I'd prefer if you could figure out how to properly rebase this PR. The bot posted some instructions above and the internet has tons of git tutorials as well. Please note that you have to reopen this PR before pushing to the old branch or else github won't let you reopen. |
- Track more fields in `FileMetadata` (`ino`, `nlink`, `rdev`, `blksize`, `blocks`). - Populate these new fields in the `statx` shim and update the returned mask. - Implement `unix_dev_major`/`unix_dev_minor` helpers to split `dev_t` using glibc layout. - Add an integration test in `tests/pass-dep/libc/libc-fs.rs` and remove the FIXME in `foreign_items.rs`.
Address PR feedback by dynamically checking the presence of Unix-specific metadata fields instead of making unconditional platform assumptions. - Update `FileMetadata` to wrap fields like `ino`, `nlink`, `uid`, `gid`, `rdev`, `blksize`, and `blocks` in `Option`. - Only advertise `STATX_*` flags in the `statx` syscall if the corresponding data is actually present in the `FileMetadata`. - Provide zero fallbacks for unavailable fields when writing to `stat` and `statx` buffers.
85cd052 to
d968320
Compare
d968320 to
6732643
Compare
|
A risk to address is not to touch recently merged change that modifies overlapping things. I added an extra regression test. |
|
Thank you for contributing to Miri! A reviewer will take a look at your PR, typically within a week or two. |
|
@rustbot ready |
|
Thanks for figuring out how to rescue your old PR. :) |
Uh oh!
There was an error while loading. Please reload this page.