This patch implements new erase modifier for the conv=xx option, which acts similarly to "sparse", but uses ioctl(DIOCGDELETE) to erase the block in question rather than seeking over it.
Why explicit cast to off_t is needed for zero?
Here sparse is checked as boolean (no != 0)...
... yet here, it is checked correctly (as int). Also, since it is ||, the order does not matter, and sparse can also be checked before ddflags like in the expression above?
My acceptance is provisional here.
If I can do
zcat image.gz | dd of=/dev/foo conv=sparse,erase
and have the data bits there, and the blocks of 0's erased, then I think this offers a cool-enough new feature to warrant putting it into dd and ditching a simpler, standalone utility.
There's a suggestion that the new trim program be named 'discard' to match linux's discard option on mount. Perhaps discard would be a better name. Though I hesitate to make such a bike-sheddy suggestion.
It's because this code is old. K&R required you cast all long args. off_t is a long arg, so it has to be cast. It hasn't been required since we've had a ANSI compiler in the tree (so ~30 years, eg 4.4BSD could have ditched it).
Well I think it's a rather bad name and while both trim and erase are pretty common in flash media contexts, to an extent being self-explanatory, I'd very likely ignore discard when quickly glancing through the manpage.
Can we please not copy things and ideas coming from Linux so eagerly? They are often dubious and questionable (at best).
A new test in bin/dd/tests that does dd if=/dev/null of=/dev/null status=none conv=trim would be nice (by not writing/trimming any bytes, it does not need a fake disk setup, but it does verify that the option is recognized). Even better would be something using md but that would need more ATF/Kyua magic.