Skip to content

mv: recreate special files in directories moved across devices - #15123

Draft
abendrothj wants to merge 4 commits into
uutils:mainfrom
abendrothj:mv-special-files-in-moved-dirs
Draft

abendrothj wants to merge 4 commits into
uutils:mainfrom
abendrothj:mv-special-files-in-moved-dirs

Conversation

@abendrothj

@abendrothj abendrothj commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Based on #13334; only the last commit is new here (+38/−6).

Sockets and device nodes inside a directory moved across devices went through the regular file copy, which can't open them, so the move failed. FIFOs were recreated with mode 0666 minus the umask. All of them now go through copy_special_file, which keeps the mode. Run on macOS and Linux. On Debian GNU/Hurd the mv tests fail only where main does (the new ones are Linux-only), and a cross-device move of a 0640 FIFO, alone or in a directory, keeps its mode as with GNU 9.10. AIX is only cross-checked with clippy.

Closes #15113
Related to #13145

Copilot AI balanced review requested due to automatic review settings October 6, 2026 07:28

Copilot AI left a comment

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI left a comment

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions

github-actions Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

GNU testsuite comparison:

Congrats! The gnu test tests/mv/mv-special-1 is no longer failing!
Congrats! The gnu test tests/dd/nocache_fail is now passing!
Note: The gnu test tests/rm/rm-readdir-fail was skipped on 'main' but is now failing.

@codspeed

codspeed Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

Merging this PR will improve performance by 4.24%

1 warning, 1 note

⚠️ 122 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

⚡ 3 improved benchmarks
✅ 398 untouched benchmarks
⏩ 70 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
⚡ CPU Simulation hostname_ip_lookup[100000] 176 µs 165.7 µs +6.17%
⚡ CPU Simulation cksum_default 33.1 ms 32.1 ms +3.3%
⚡ CPU Simulation cksum_raw_output 33.4 ms 32.3 ms +3.27%

Tip

Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.


Comparing abendrothj:mv-special-files-in-moved-dirs (7334d83) with main (679d1f2)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 (eb7d426) during the generation of this report, so 679d1f2 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@abendrothj
abendrothj marked this pull request as draft October 7, 2026 00:20
@abendrothj
abendrothj force-pushed the mv-special-files-in-moved-dirs branch 3 times, most recently from 60d24ea to 5b7ce0f Compare October 12, 2026 10:05
@abendrothj
abendrothj force-pushed the mv-special-files-in-moved-dirs branch from 5b7ce0f to 7ffe3a7 Compare October 20, 2026 00:48
Move the temporary name and renameat logic of replace_link into
DirFd::replace_entry_at, which creates the entry through a callback
relative to the directory, so other callers can replace entries the
same way.

The parent is now opened with DirFd::open_anchor, so ln -sf and cp -sf
replacing an entry in a directory with write and search but no read
permission work, as they do with GNU, instead of failing with EACCES.
Create fifos, sockets and device nodes relative to an open directory.
nix and rustix do not provide mknodat on Apple targets, so this calls
libc directly.
@abendrothj
abendrothj force-pushed the mv-special-files-in-moved-dirs branch from 7ffe3a7 to a9dc76d Compare October 22, 2026 06:44
A cross-device move of a socket or device node went through the
regular file copy, which removed the destination and then failed to
open the source. A fifo also removed the destination before creating
the new one, and lost its mode.

Fifos, sockets and device nodes are now created with their mode and
ownership in a private directory next to the destination and renamed
over it, so the destination is kept if the node cannot be created, and
the ownership and mode cannot land on another file linked over the
destination name meanwhile. The private directory is made 0700 by name
right after it is created, before it is opened, without changing the
umask; the check after the open rejects a directory moved there in
between. As for regular files, setuid and setgid are dropped when the
ownership cannot be kept.

Fixes uutils#13145
Sockets and device nodes inside a directory moved across devices went
through the regular file copy, which cannot open them, so the move
failed. Fifos were recreated with mode 0666 minus the umask. Recreate
all of them with copy_special_file, which keeps the mode.
@abendrothj
abendrothj force-pushed the mv-special-files-in-moved-dirs branch from a9dc76d to 7334d83 Compare October 22, 2026 08:50

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.

mv: moving a directory with a socket or device node across filesystems fails

2 participants