Skip to content

fix(dev): synthesize /dev/zero, /dev/random, /dev/urandom, /dev/full (#1779) - #1781

Merged
caomengxuan666 merged 1 commit into
mainfrom
fix/niu993-1779-dev-synth
Nov 16, 2026
Merged

caomengxuan666 merged 1 commit into
mainfrom
fix/niu993-1779-dev-synth

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Summary

Closes #1779. Part of the niubash#993 Git-Bash drop-in compatibility audit (§5).

Linux synthesizes /dev/zero, /dev/random, /dev/urandom and /dev/full in the kernel (drivers/char/mem.c); WinuxCmd answered them only inside dd, while every other command hit the ordinary filesystem open and reported ENOENT. This folds the same answer into the shared operand boundary so every tool behaves identically:

  • Metadata: native_path::SynthDev + is_character_device_w; ls, ls -d, stat, test -e/-c report character special files. Rust2 mirrors via winux_core::path::synthesized_device + fs_win::file_meta.
  • Reads: file_io::open_binary_file (C++) and fsutil::open_read_operand (rust2) return infinite streams — zeros for /dev/zero//dev/full, mt19937_64/xorshift64* for /dev/random//dev/urandom. ~12 rust read sites migrated to the seam; cat's direct ifstream bypass removed.
  • Writes: zero/random/urandom discard like NUL; /dev/full fails ENOSPC — tee/cp report "No space left on device".
  • Bounded consumers: od -N now uses Read::take, so od -N8 /dev/zero terminates.
  • test: synthesized devices get the device record (-e/-r/-w/-c true, -f/-d/-x/-s false); -ef identity by operand spelling (random != urandom).
  • test infra: TempDir::extended_path routes DOS-device-stem leaves (NUL.txt) through lexical absolutization — GetFullPathNameW collapsed the stem onto \\.\NUL, so fixture writes went to the device and cat.nul_txt_reads_file_issue1333 could never pass.

Test plan

  • winuxcmd-tests: 665/665 on ls.*:stat.*:head.*:cp.*:tee.*:test.*:cat.*:od.*:wc.*:dd.*:realpath.*:readlink.*:mkfifo.*:mknod.* (includes new pins: ls char-device listing, stat %F/%A, test -e/-c/-f/-x, head -c, cp/tee to /dev/full + /dev/zero)
  • cargo test -p winux-cmds: stat::, test_cmd::, tee::, od::, fsutil::, cp:: all green
  • Smoke: head -c8 /dev/zero, head -c32 /dev/urandom, cp x /dev/full (ENOSPC), cp x /dev/zero, tee /dev/full, ls -l /dev/{zero,urandom,full}

Generated with Devin

…1779)

dd was the only tool that answered these operands; every other command
fell through to the ordinary filesystem open and reported ENOENT. Linux
synthesizes them in the kernel (drivers/char/mem.c), so fold the same
answer into the shared operand boundary instead of per-command hacks.

- native_path: SynthDev classification; is_character_device_w answers
  true for the synthesized spellings.
- file_io: open_binary_file returns an infinite CRT-pipe stream for
  zero/random/urandom (xorshift64*/mt19937_64 for random) and zeros for
  full; create_binary_file maps zero/random/urandom to NUL and fails
  full with ENOSPC.
- cat: route operand reads through open_binary_file — the direct
  ifstream branch bypassed the device boundary.
- ls: probe_path, -d and list_file recognize the devices as character
  special even without a Win32 directory entry.
- rust2 winux-core: SynthesizedDevice path classification; fs_win
  file_meta returns a character-device record; fsutil gains
  SynthDeviceReader and open_write_operand; ~12 read sites (head, wc,
  od, cksum, basenc, digestsum, expand, fmt, fold, join, paste, rev,
  sort, tac, tsort, unexpand, xargs, sed) now go through
  open_read_operand.
- od: bound stdin/file reads with Read::take when -N is given so
  `od -N8 /dev/zero` terminates.
- tee: report raw OS error 28 as "No space left on device"; cp opens
  device destinations through the operand boundary.
- test: synthesized devices take the character-device record
  (-e/-r/-w/-c true, -f/-d/-x/-s false); -ef identity by operand
  spelling.
- tests/framework: TempDir extended_path routes DOS-device-stem leaves
  ("NUL.txt") through lexical absolutization — GetFullPathNameW
  collapses the stem onto \\.\NUL, so fixture writes previously landed
  on the device (cat.nul_txt_reads_file_issue1333 was unfixable).

GNU semantics (9.4, drivers/char/mem.c): reads of zero/random/urandom
are infinite (full reads zeros); writes to zero/random/urandom discard,
writes to full fail ENOSPC. All four report character special file.

Regression pins: ls -l/-d, stat %F/%A, test -e/-c/-f/-x, head -c,
cp to /dev/full + /dev/zero, tee to /dev/full.
@caomengxuan666
caomengxuan666 force-pushed the fix/niu993-1779-dev-synth branch from 5b02954 to 195fd6b Compare November 16, 2026 00:24
@caomengxuan666
caomengxuan666 merged commit 537b55d into main Nov 16, 2026
23 of 28 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/niu993-1779-dev-synth branch November 16, 2026 01:10
caomengxuan666 added a commit that referenced this pull request Nov 16, 2026
… merged C++ surface PRs (#1781 #1786 #1795 family)

The gate's own protocol for deliberate new source strings: record the
growth so the ratchet stays honest (it may only shrink as translation
sync batches land in unixwin/winuxcmd-i18n). The 22 zh-CN legacy.*
missing items come from the C++ command surface that landed with the
/dev synthesis, ps -W and cp-revert wave — all merged by owner; their
zh-CN translations ride the next i18n sync batch (same choreography as
the du keys earlier today).

Verified locally on origin/main (f6d5386): same 22-item set as the
failing CI run 43814990474; en-US side clean.
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.

Synthesize /dev/zero, /dev/random, /dev/urandom, /dev/full for all tools (niubash#993 §5)

1 participant