Skip to content

mknod: replace nix::sys::stat with rustix - #12321

Draft
mattsu2020 wants to merge 2 commits into
uutils:mainfrom
mattsu2020:mknod_rustix
Draft

mattsu2020 wants to merge 2 commits into
uutils:mainfrom
mattsu2020:mknod_rustix

Conversation

@mattsu2020

@mattsu2020 mattsu2020 commented May 16, 2026 •

Copy link
Copy Markdown
Contributor

Replace nix::sys::stat in mknod with rustix::fs and remove the direct nix dependency.

Depends on bytecodealliance/rustix#1625.

Additional FIFO tests are split into #16348.

@github-actions

github-actions Bot commented May 16, 2026 •

Copy link
Copy Markdown

GNU testsuite comparison:

Congrats! The gnu test tests/shred/shred-remove is no longer failing!

Comment thread src/uu/mknod/src/mknod.rs Resolved
Comment thread src/uu/mknod/src/mknod.rs Resolved
@codspeed

codspeed Bot commented May 16, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

1 warning, 1 note

⚠️ 123 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

ℹ️ 1 benchmark has no flamegraph

The flamegraph wasn't generated: most of the time was spent in runtime internals, which would leave nothing useful to analyze.

See affected benchmarks

✅ 405 untouched benchmarks
⏩ 70 skipped benchmarks1


Comparing mattsu2020:mknod_rustix (85eb326) with main (630890c)2

Open in CodSpeed

Footnotes

  1. 70 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

  2. No successful run was found on main (108e87b) during the generation of this report, so 630890c was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

Comment thread src/uu/mknod/Cargo.toml Resolved
@oech3

oech3 commented May 16, 2026

Copy link
Copy Markdown
Contributor

mkfifo is subset of mknod. So it should be able to remake existing mkfifo wrapper without unsafe by this one.

@mattsu2020

Copy link
Copy Markdown
Contributor Author

mkfifo is subset of mknod. So it should be able to remake existing mkfifo wrapper without unsafe by this one.

Thanks for the suggestion! You're right
mkfifo is essentially mknod with S_IFIFO and dev=0, so the do_mknod helper could be reused there to eliminate the nix dependency and unsafe as well.

@oech3

oech3 commented May 16, 2026

Copy link
Copy Markdown
Contributor

Is it able to open a PR on rustix to support rustix::fs::mk*at on macOS?
I have no access on macOS now...

@mattsu2020

Copy link
Copy Markdown
Contributor Author

Is it able to open a PR on rustix to support rustix::fs::mk*at on macOS? I have no access on macOS now...

I created the PR, but there are some errors on the Rustix side during CI, so I'll review the code again once the fixes are complete.
bytecodealliance/rustix#1625

@oech3

oech3 commented May 16, 2026

Copy link
Copy Markdown
Contributor

Thankyou

@xtqqczze

xtqqczze commented Sep 28, 2026 •

Copy link
Copy Markdown
Collaborator

Depends on bytecodealliance/rustix#1691.

@xtqqczze

Copy link
Copy Markdown
Collaborator

Compiles successfully on Redox:

cargo check -q -p uu_mknod --target x86_64-unknown-redox

@xtqqczze

This comment was marked as resolved.

@mattsu2020
mattsu2020 marked this pull request as draft September 29, 2026 00:05
@mattsu2020 mattsu2020 changed the title mknod: replace nix::sys::stat with rustix + libc mknod: replace nix::sys::stat with rustix Sep 29, 2026
@mattsu2020

This comment was marked as resolved.

@xtqqczze

This comment was marked as resolved.

@xtqqczze

This comment was marked as resolved.

Comment thread src/uu/mknod/src/mknod.rs Outdated
use clap::{Arg, ArgAction, Command, value_parser};
use nix::libc::{S_IRGRP, S_IROTH, S_IRUSR, S_IWGRP, S_IWOTH, S_IWUSR, mode_t};
use nix::sys::stat::{Mode, SFlag, dev_t, mknod as nix_mknod};
use rustix::fs::{CWD, Dev, FileType as RustixFileType, Mode, mknodat};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If we drop nix, as RustixFileType is innecessary.

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.

thanks.
The code is much cleaner now.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

rustix::fs::FileType has additional variants that we don't currently handle. This change could expose us to unexpected behavior when encountering those variants through the public API.

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.

I see, so we need to set some restrictions.
I've added restrictions at the entry point.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

mknod isn't the entry point, so the change is still not correct.

Comment thread tests/by-util/test_mknod.rs Resolved
@mattsu2020
mattsu2020 marked this pull request as ready for review November 11, 2026 11:02
@sylvestre

Copy link
Copy Markdown
Contributor

thanks for working on this!
This can't land while it depends on a rustix git rev. Please keep it in draft until a rustix release ships the change and bump the version instead, which should also fix the red CI.
Please also rebase without the merge commit and squash everything into one commit.

@mattsu2020
mattsu2020 marked this pull request as draft November 12, 2026 07:01
@oech3

oech3 commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Can we use cargo vendor? But it might difficult to audit copied src.

@xtqqczze

Copy link
Copy Markdown
Collaborator

This can't land while it depends on a rustix git rev.

We should ensure git sources fail CI: #16366.

This branch has not been deployed

No deployments
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.

4 participants