mknod: replace nix::sys::stat with rustix + libc#12321
Conversation
Replace `nix::sys::stat` usage with `rustix::fs` types and `libc::mknod`: - `nix::sys::stat::Mode` → `rustix::fs::Mode` - `nix::sys::stat::SFlag` → `rustix::fs::FileType` - `nix::sys::stat::umask` → `rustix::process::umask` with RAII `UmaskGuard` - `nix::sys::stat::mknod` → `libc::mknod` (rustix::fs::mknodat is unavailable on apple targets) - `nix::libc::S_I*` constants → `0o666` literal The `UmaskGuard` pattern (borrowed from mkdir) ensures umask is restored on drop, even on panic — an improvement over the previous manual save/restore.
|
GNU testsuite comparison: |
|
|
||
| impl FileType { | ||
| fn as_sflag(&self) -> SFlag { | ||
| fn to_rustix(self) -> RustixFileType { |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
| uucore::execution_phrase(), | ||
| std::io::Error::from(err) | ||
| ); | ||
| eprintln!("{}: {err}", uucore::execution_phrase()); |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
Merging this PR will improve performance by 13.71%
|
| Mode | Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|---|
| ⚡ | Simulation | ls_recursive_balanced_tree[(6, 4, 15)] |
50.9 ms | 48.9 ms | +4.01% |
| ⚡ | Memory | cp_recursive_deep_tree[(120, 4)] |
699.2 KB | 562.5 KB | +24.31% |
Tip
Curious why this is faster? Comment @codspeedbot explain why this is faster on this PR, or directly use the CodSpeed MCP with your agent.
Comparing mattsu2020:mknod_rustix (000ee9d) with main (d09f351)
Footnotes
-
46 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. ↩
| fluent = { workspace = true } | ||
| nix = { workspace = true } | ||
| rustix = { workspace = true, features = ["process", "fs"] } | ||
| libc = { workspace = true } |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
|
|
- Rename `to_rustix` → `to_file_type` to avoid embedding crate name - Use `let _ = writeln!(stderr, ...)` to prevent SIGABRT on /dev/full - Sort Cargo.toml dependencies alphabetically (libc before rustix)
Replaced the multi-line writeln! macro call with a single-line version for better readability.
Thanks for the suggestion! You're right |
|
Is it able to open a PR on rustix to support |
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. |
|
Thankyou |
Summary
nix::sys::stat::{Mode, SFlag, mknod, umask}withrustix::fs::{Mode, FileType}andrustix::process::umasklibc::mknoddirectly for themknod(2)syscall sincerustix::fs::mknodatis unavailable on Apple targetsUmaskGuard(pattern frommkdir) ensuring umask is restored on drop, even on panic — improving over the previous manual save/restoreMODE_RW_UGOfrom individualnix::libc::S_I*constants to0o666literalDependency changes
nixrustix(features:process,fs),libcTest plan
cargo build -p uu_mknod— compiles cleanlycargo clippy -p uu_mknod— no warningsmknod /tmp/test_fifo p— creates FIFO with correct default mode (prw-r--r--, umask applied)mknod -m 0600 /tmp/test_fifo2 p— creates FIFO with exact mode (prw-------, umask bypassed)