Skip to content

Add stat and lstat shims for all Unixes#4934

Open
enricobolzonello wants to merge 2 commits intorust-lang:masterfrom
enricobolzonello:lstat-stat-support
Open

Add stat and lstat shims for all Unixes#4934
enricobolzonello wants to merge 2 commits intorust-lang:masterfrom
enricobolzonello:lstat-stat-support

Conversation

@enricobolzonello
Copy link
Copy Markdown

@enricobolzonello enricobolzonello commented Apr 1, 2026

Closes #4744

Adds stat and lstat shims for Linux, following the same approach as #4714 did for fstat.

  • Add "stat" and "lstat" arms to the generic Unix foreign items handler
  • Add Os::Linux to the supported targets in fs.rs for both functions
  • Add tests for stat and lstat. The test for lstat verifies it does not follow symlinks

@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 1, 2026

Thank you for contributing to Miri! A reviewer will take a look at your PR, typically within a week or two.
Please remember to not force-push to the PR branch except when you need to rebase due to a conflict or when the reviewer asks you for it.

@rustbot rustbot added the S-waiting-on-review Status: Waiting for a review to complete label Apr 1, 2026
Copy link
Copy Markdown
Member

@RalfJung RalfJung left a comment

Choose a reason for hiding this comment

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

Sorry for the slow review.

This looks just right, thanks! However, the test could do with a bit of code deduplication.

@rustbot author

View changes since this review

Comment on lines +501 to +516
// Check that all fields are initialized.
let _st_nlink = stat.st_nlink;
let _st_blksize = stat.st_blksize;
let _st_blocks = stat.st_blocks;
let _st_ino = stat.st_ino;
let _st_dev = stat.st_dev;
let _st_uid = stat.st_uid;
let _st_gid = stat.st_gid;
let _st_rdev = stat.st_rdev;
let _st_atime = stat.st_atime;
let _st_mtime = stat.st_mtime;
let _st_ctime = stat.st_ctime;
let _st_atime_nsec = stat.st_atime_nsec;
let _st_mtime_nsec = stat.st_mtime_nsec;
let _st_ctime_nsec = stat.st_ctime_nsec;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Instead of duplicating this code, please move it into a shared function.

@rustbot rustbot added S-waiting-on-author Status: Waiting for the PR author to address review comments and removed S-waiting-on-review Status: Waiting for a review to complete labels Apr 26, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 26, 2026

Reminder, once the PR becomes ready for a review, use @rustbot ready.

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

Labels

S-waiting-on-author Status: Waiting for the PR author to address review comments

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support "lstat" and "stat" on Linux (and all other Unixes)

3 participants