shred: residual-entropy scheduling for --random-source - #13700
shred: residual-entropy scheduling for --random-source#13700sankalpsthakur wants to merge 3 commits into
Conversation
Introduce a Pattern model with three repeating bytes and an optional sector-phase flag (pattern code bit 0x1000). Decode codes via Pattern::from_code; on write, XOR the first byte of every 512-byte sector with 0x80 and keep buffer offset locked so flips stay sector-aligned. Keep the existing pass schedulers for production behavior. Scheduler and distribution changes land in follow-up PRs.
Replace max(n/10,3)+cycle+shuffle for the default path with clean-room genpattern over PASS_GROUPS (group select, Bresenham random spacing, shuffle fixed patterns). Phase-variant codes enter the scheduled set. Keep create_test_compatible for --random-source until residual entropy lands so integration tests stay green.
Draw scheduling integers from --random-source with residual-byte entropy so genpattern pass order matches GNU for a given stream. Remove the create_test_compatible_sequence hack. Restore full unit coverage from the earlier patch: n=20 sequence, distribution matrix for uutils#11611 counts, and file-source scheduling (non-WASI). Fixes uutils#11611
Merging this PR will improve performance by 3.03%
Performance Changes
Tip Curious why this is faster? Comment Comparing Footnotes
|
Note that the format and comments here are clearly copied from GNU source source code: Unsure if it was you who wrote that or mechahitler [1]. [1] https://www.npr.org/2025/07/09/nx-s1-5462609/grok-elon-musk-antisemitic-racist-content |
Summary
Depends on #13699 (genpattern) which depends on #13694 (patterns).
Implement residual-byte integer generation (
FilePassRng) sochoose()over a given byte stream matches GNU pass order. Both default and--random-sourcepaths usegenpattern. Deletescreate_test_compatible_sequence.Clean-room residual scheme matching public randint residual behavior / observed
gshred9.11; not a GPL port.Fixes #11611
Tests
Assisted by Grok (xAI); reviewed and tested locally.