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.
Details
- Reviewers
eugen_grosbein.net imp sbruno bcr - Group Reviewers
manpages
Make memory disk, fill with random data, run dd if=/dev/zero conv=erase on it.
Diff Detail
- Repository
- rS FreeBSD src repository - subversion
- Lint
Lint Skipped - Unit
Tests Skipped - Build Status
Buildable 22010
Event Timeline
bin/dd/dd.1 | ||
---|---|---|
313 | Typo. | |
bin/dd/dd.c | ||
480 | Why explicit cast to off_t is needed for zero? | |
537 | Here sparse is checked as boolean (no != 0)... | |
559 | ... 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? |
bin/dd/dd.1 | ||
---|---|---|
316 | Would it be possible to somehow add the words "TRIM" and "UNMAP" to that sentence, to make it easier to find? |
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.
o Due to popular request rename "erase" into "trim".
o Fix typo in manpage.
o unify comparison (style).
bin/dd/dd.c | ||
---|---|---|
480 | ENOIDEA. :) I just copied code from some other place in the dd.c. I can only guess it's perhaps used to workaround some early cc(1) idiosyncrasy. |
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.
bin/dd/dd.c | ||
---|---|---|
480 | 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).
You need now fix clist[] array in the args.c as it must be sorted or else bsearch() fails to find "trim" and dd conv=trim bails out with error "unknown conversion trim".
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.
Keep clist[] array in the args.c sorted by the name so that bsearch() DTRT.
Reported by: eugen_grosbein.net
@eugen_grosbein.net thanks, good catch. Should be fixed now. Also updated diff to match C_PROGRESS changes.