Commit Graph

182 Commits

Author SHA1 Message Date
David E. O'Brien
e6588b178c Mention the dd-like recoverdisk(1) to help folks find this great BSD command. 2015-07-16 23:38:12 +00:00
Simon J. Gerraty
ccfb965433 Add META_MODE support.
Off by default, build behaves normally.
WITH_META_MODE we get auto objdir creation, the ability to
start build from anywhere in the tree.

Still need to add real targets under targets/ to build packages.

Differential Revision:       D2796
Reviewed by: brooks imp
2015-06-13 19:20:56 +00:00
Simon J. Gerraty
44d314f704 dirdeps.mk now sets DEP_RELDIR 2015-06-08 23:35:17 +00:00
Simon J. Gerraty
9268022b74 Merge from head@274682 2014-11-19 01:07:58 +00:00
Kurt Jaeger
f4cfd28bb5 bin/dd: revert 273734, as it fails on 32bit platforms
Revert: insufficient testing on 32bit platforms

PR:		191263
2014-10-27 17:39:37 +00:00
Kurt Jaeger
179eb7112b bin/dd: Fix incorrect casting of arguments
dd(1) casts many of its numeric arguments from uintmax_t to intmax_t
and back again to detect whether or not the original arguments were
negative. This caused wrong behaviour in some boundary cases:

$ dd if=/dev/zero of=/dev/null count=18446744073709551615
dd: count cannot be negative

After the fix:

$ dd if=/dev/zero of=/dev/null count=18446744073709551615
dd: count: Result too large

PR:		191263
Submitted by:	will@worrbase.com
Approved by:	cognet@
2014-10-27 11:38:17 +00:00
Warner Losh
a83c9ec1e5 Update the date for last example.
Sponsored by: Netflix
2014-08-30 02:12:58 +00:00
Warner Losh
56fd128433 Add canonical population of a disk / thumb drive from an image
example.
2014-08-28 21:30:39 +00:00
Simon J. Gerraty
fae50821ae Updated dependencies 2014-05-16 14:09:51 +00:00
Simon J. Gerraty
76b28ad6ab Updated dependencies 2014-05-10 05:16:28 +00:00
Simon J. Gerraty
cc3f4b9965 Merge from head 2014-05-08 23:54:15 +00:00
Alan Somers
540c78258c Incorporate feedback from bde and jilles regarding r265472 to dd(1).
* Don't use sysexits.h.  Just exit 1 on error and 0 otherwise.
* Don't sacrifice precision by converting the output of clock_gettime() to a
  double and then comparing the results.  Instead, subtract the values of
  the two clock_gettime() calls, then convert to double.
* Don't use CLOCK_MONOTONIC_PRECISE.  It's an unportable synonym for
  CLOCK_MONOTONIC.
* Use more appropriate names for some local variables.
* In the summary message, round elapsed time to the nearest microsecond.

Reported by:	bde, jilles
MFC after:	3 days
X-MFC-With:	265472
2014-05-08 19:10:04 +00:00
Thomas Quinot
aa7a161b40 (dd_out): Fix handling of all-zeroes block at end of input with
conv=sparse.

This change fixes two separate issues observed when the last output
block is all zeroes, and conv=sparse is in use. In this case, care
must be taken to roll back the last seek and write the entire last zero
block at the original offset where it should have occurred: when the
destination file is a block device, it is not possible to roll back
by just one character as the write would then not be properly aligned.

Furthermore, the buffer used to write this last all-zeroes block
needs to be properly zeroed-out. This was not the case previously,
resulting in a junk data byte appearing instead of a zero in the
output stream.

PR:		bin/189174
PR:		bin/189284
Reviewed by:	kib
MFC after:	2 weeks
2014-05-07 19:33:29 +00:00
Alan Somers
d1d66eac15 dd(1) uses gettimeofday(2) to compute the throughput statistics. However,
gettimeofday returns the system clock, which may jump forward or back,
especially if NTP is in use.  If the time jumps backwards, then dd will see
negative elapsed time, round it up to 1usec, and print an absurdly fast
transfer rate.

The solution is to use clock_gettime(2) with CLOCK_MONOTONIC_PRECISE as the
clock_id.  That clock advances steadily, regardless of changes to the system
clock.

Reviewed by:	delphij
MFC after:	3 days
Sponsored by:	Spectra Logic
2014-05-06 22:06:39 +00:00
Thomas Quinot
37f1b88ba0 Minor comment fix: dbsz is the block size as set by bs/ibs/obs,
not the size of the buffer.
2014-05-03 09:07:02 +00:00
Thomas Quinot
66d5f71966 Minor comment fix. 2014-05-03 09:06:11 +00:00
Simon J. Gerraty
3b8f084595 Merge head 2014-04-28 07:50:45 +00:00
Xin LI
413ef2a3d1 Make C_* contants fit in 32 bits again by using 4 unused bits.
Noticed by:	bde
2014-04-03 06:32:02 +00:00
Xin LI
c3f5e9c515 Implement GNU's extension of 'status' operand. The GNU syntax is
borrowed where syntax status=noxfer means no transfer statistics
and status=none means no status information at all.

This feature is useful because the statistics information can
sometimes be annoying, and redirecting stderr to /dev/null would
mean error messages also gets silenced.

Obtained from:	OpenBSD
MFC after:	2 weeks
2014-04-03 00:55:16 +00:00
Simon J. Gerraty
3caf0790a8 Merge head@256284 2013-10-13 02:35:19 +00:00
Sergey Kandaurov
05d98029e9 Sweep man pages replacing ad -> ada.
Approved by:	re (blackend)
MFC after:	1 week
X-MFC note:	stable/9 only
2013-10-01 18:41:53 +00:00
Simon J. Gerraty
d1d0158641 Merge from head 2013-09-05 20:18:59 +00:00
Eitan Adler
4ac1163902 Make dd's signal handler async safe.
PR:		bin/75258
Submitted by:	"Oleg V. Nauman" <oleg@reis.zp.ua>
Arrival Date:	Sun Dec 19 14:50:21 GMT 2004
Reviewed by:	mjg, jhb
Reviewed by:	jilles (earlier version)
MFC after:	1 week
2013-05-10 18:43:36 +00:00
Konstantin Belousov
6784d416a5 Literally follow POSIX:
If the bs= expr operand is specified and no conversions other than sync,
noerror, or notrunc are requested, the data returned from each input
block shall be written as a separate output block.

In particular, when both bs=size and conv=sparce were specified, the
resulted file was fully filled, instead of sparce.

PR:	standards/177742
Submitted by:	Matthew Rezny <mrezny@hexaneinc.com>
MFC after:	2 weeks
2013-04-23 16:08:24 +00:00
Simon J. Gerraty
69e6d7b75e sync from head 2013-04-12 20:48:55 +00:00
Brooks Davis
c183a03b17 IFP4 change 222074.
Introduce an explicit close of the output descriptor so that work done
on close is accounted for in the summary output triggered at exit
(implicit close()s occur after atexit() hooks).

This is useful because some devices such as cfi(4) may perform
signficant work after a close occurs (e.g. erasing and rewriting a
block of flash).
2013-04-03 19:19:45 +00:00
Simon J. Gerraty
7cf3a1c6b2 Updated dependencies 2013-03-11 17:21:52 +00:00
Simon J. Gerraty
f5f7c05209 Updated dependencies 2013-02-16 01:23:54 +00:00
Simon J. Gerraty
23090366f7 Sync from head 2012-11-04 02:52:03 +00:00
Ed Schouten
eccad22277 More -Wmissing-variable-declarations fixes.
In addition to adding missing `static' keywords:
- bin/dd: Pull in `extern.h' to guarantee consistency with source file.
- libexec/rpc.rusersd: Move shared globals into an extern.h.
- libexec/talkd: Move `debug' and `hostname' into extern.h.
- usr.bin/cksum: Put counters in extern.h, as they are used by ckdist/mtree.
- usr.bin/m4: Move `end_result' into extern.h.
- usr.sbin/services_mkdb: Move shared globals into an extern.h.
2012-10-20 10:33:15 +00:00
Ed Schouten
902d9eafbf Rework all non-contributed files that use `struct timezone'.
This structure is not part of POSIX. According to POSIX, gettimeofday()
has the following prototype:

	int gettimeofday(struct timeval *restrict tp, void *restrict tzp);

Also, POSIX states that gettimeofday() shall return 0 (as long as tzp is
not used). Remove dead error handling code. Also use NULL for a
nul-pointer instead of integer 0.

While there, change all pieces of code that only use tv_sec to use
time(3), as this provides less overhead.
2012-09-01 14:45:15 +00:00
Marcel Moolenaar
7750ad47a9 Sync FreeBSD's bmake branch with Juniper's internal bmake branch.
Requested by: Simon Gerraty <sjg@juniper.net>
2012-08-22 19:25:57 +00:00
Giorgos Keramidas
74f13fb3b6 Bump .Dd for r187609 2009-01-30 16:23:57 +00:00
Giorgos Keramidas
4dd47928b7 Add an example of using bs=2048 to duplicate data CD-ROMs.
This should be a bit useful for users who look at the manpage and
then try to copy data CD-ROM disks using dd.  A lot of us know
that bs=2048 is required, but it still manages to cause a bit of
grief to those who haven't heard about it.

PR:		bin/130857
Submitted by:	Tri Brotoharsono < mail at tribrotoharsono.net >
MFC after:	3 days
2009-01-23 03:46:44 +00:00
Mark Murray
1da811ef16 More inactive maintainers. 2006-07-09 21:47:37 +00:00
Giorgos Keramidas
9358c0e397 Spell "protections" correctly. 2005-07-28 18:28:11 +00:00
Ruslan Ermilov
7b020a2f1e Sort sections.
Approved by:	re (blanket)
2005-06-14 08:25:54 +00:00
Scott Long
fd525b85a7 Document problems with writing to disks under GEOM. 2005-04-07 20:50:38 +00:00
Ruslan Ermilov
6fca4c7c3f Add the new standard EXIT STATUS section where appropriate.
Sort standard sections in the (documented) preferred order.
2005-01-16 16:41:59 +00:00
Warner Losh
9ddb49cbe4 /*- or .\"- or #- to begin license clauses. 2005-01-10 08:39:26 +00:00
Ruslan Ermilov
6fa13ec06f Scheduled mdoc(7) sweep. 2005-01-09 19:54:23 +00:00
Robert Watson
e3edab4a91 Add a "fillchar" command line argument to dd(1) that permits the user
to specify an alternative padding character when using a conversion
mode, or when using noerror with sync and an input error occurs.  This
facilities reading old and error-prone media by allowing the user to
more effectively mark error blocks in the output stream.
2004-08-15 19:10:05 +00:00
Pawel Jakub Dawidek
1e1d03d7fc Allow for capital letters as size suffixes.
Inspired by:	le
Approved by:	green (maintainer)
2004-07-31 15:13:08 +00:00
Ruslan Ermilov
2360f509c5 Bump document date for the latest functional change.
Minor markup tweaks.
2004-05-16 21:34:15 +00:00
Nate Lawson
3066c4a4bd Style fixes and add gen to CLEANFILES.
Submitted by:	bde
2004-04-09 07:13:27 +00:00
Mark Murray
6195fb4102 Remove clause 3 from the UCB licenses.
OK'ed by:	imp, core
2004-04-06 20:06:54 +00:00
Andrey A. Chernov
c65eeb736e Remove a.out at the end of 'make test' 2004-03-08 18:09:33 +00:00
Bruce Evans
d493ed0f97 Fixed some style bugs (mainly unsorting and tab lossage in previous commit). 2004-03-06 08:21:32 +00:00
Andrey A. Chernov
c6f22660ff Add a.out to CLEANFILES 2004-03-06 06:54:58 +00:00
Andrey A. Chernov
adde319c62 Change locale name from non-existent ASCII to en_US.US-ASCII 2004-03-06 06:10:16 +00:00
Poul-Henning Kamp
6a3d33ac5e Teach dd(1) about parity bits. 2004-03-05 19:35:51 +00:00
Poul-Henning Kamp
3d36fd4271 Add a test-target and reference vectors for the character converions. 2004-03-05 19:30:13 +00:00
Mark Murray
eac4bdcca4 Get this area compiling with the highest WARNS= that it works with.
Obsolete WFORMAT= junk also removed where possible.

OK'ed by:	obrien
Tested on:	sparc64, alpha, i386
2003-06-13 07:04:02 +00:00
David E. O'Brien
09a80d4867 Quiet warnings about copyright[]. 2003-05-01 16:58:57 +00:00
Ruslan Ermilov
bfd86a6070 ssize_t is not required to be the same width as size_t by the
specs, so cast to intmax_t where appropriate.

Pointed out by:	bde
2003-03-15 13:34:48 +00:00
Ruslan Ermilov
024ae00499 Fixed (soon might be fatal) -Wformat warnings. 2003-03-15 07:56:59 +00:00
Mark Murray
7503d74f54 WARNS=4 fixes. This would be WARNS=9 if we were -std=99 instead of
-ansi, due to 'long long'.

Reviewed by:	green (slightly earlier version)
2003-02-27 18:04:54 +00:00
Poul-Henning Kamp
cd967e322a Don't call DIOCWLABEL on disks, it is not implemented, and calling it
like this negated any practical value of the feature.
2003-01-26 11:13:40 +00:00
Ruslan Ermilov
e27480d64d mdoc(7) police:
Revert to using the .Tn POSIX and .Tn ANSI instead of \*[Px] and \*[Ai]
strings; using these strings is unsafe in troff mode, as they include a
change in a font size.

Approved by:	re
2002-11-26 17:55:41 +00:00
David E. O'Brien
5eb43ac2f7 Consistently use __FBSDID 2002-06-30 05:13:54 +00:00
Giorgos Keramidas
a7c1ac2f62 Replace <strings.h> with <string.h>. No functions from the former are
used in this file, and strlen() needs to be prototyped by the latter,
for this to compile without warnings.

Reviewed by:	mike
2002-06-09 04:15:40 +00:00
Ruslan Ermilov
7b3e3e39c7 mdoc(7) police: replace the XXX with the correct width. 2002-05-29 14:01:27 +00:00
Chris D. Faulhaber
c01df1d365 Add semicolon to empty default case to silence warning. 2002-05-11 03:12:02 +00:00
Giorgos Keramidas
80c7362ce3 Various mdoc fixes, including a change that corrects spacing as
described in PR docs/36461.

PR:		docs/36461
Noticed by:	Gary W. Swearingen <swear@blarg.net>
Submitted by:	ru
2002-03-31 20:49:37 +00:00
Mark Murray
afa5289a98 1) Rev.1.35 of dd.c has a more serious regression. It backs out rev.1.31,
thus breaking systems with unpolluted <sys/stat.h>'s.

2) Back out an initialisation of a variable in BSS.

Reported by:	bde (1), many(2)
2002-03-07 14:00:33 +00:00
Mark Murray
9afa09cd0e Fix warnings inspired by lint, a commercial lint and WARNS=4. 2002-02-22 20:51:00 +00:00
Brian Feldman
2fb080722f Correct a logic bug that snuck in and broke multiplication of off_ts. 2002-02-07 02:54:30 +00:00
Kris Kennaway
afe781faa2 Lock down with WFORMAT=1 except those directories with unfixed warnings.
Tested on i386 and alpha.
2002-02-04 02:49:19 +00:00
Warner Losh
f9bcb0beb5 o __P has been reoved
o Old-style K&R declarations have been converted to new C89 style
o register has been removed
o prototype for main() has been removed (gcc3 makes it an error)
o int main(int argc, char *argv[]) is the preferred main definition.
o Attempt to not break style(9) conformance for declarations more than
  they already are.

Approved by: arch@, new style(9)
2002-02-02 06:24:13 +00:00
Brian Feldman
4ed955372c Commit general cleanups (separate get_num() and get_off_t() functions to
debogosify some of the command-line string-number conversions into
an unsigned and signed variant.)
2002-01-25 17:44:47 +00:00
David E. O'Brien
a748290789 Default to WARNS=2. Binary builds that cannot handle this must explicitly
set WARNS=0.

Reviewed by:	mike
2001-12-04 01:57:47 +00:00
Ruslan Ermilov
d628d776c4 mdoc(7) police: utilize the new .Ex macro. 2001-08-15 09:09:47 +00:00
Ruslan Ermilov
753d686d34 mdoc(7) police: s/BSD/.Bx/ where appropriate. 2001-08-14 10:01:54 +00:00
Brian Feldman
9f3537caad Use __unused for non-used variables.
Submitted by:	Mike Barcroft <mike@q9media.com>
2001-06-29 20:06:47 +00:00
Dima Dorfman
7a507517de Previous commit broke dd(1)'s I/O summary when it's terminated by a
signal.  Fix it by adding an explicit call to summary() in terminate()
(it was previously called implicitly by exit() because summary() was
registered with atexit()).  summary() is supposed to be signal-safe--
it handles SIGINFO almost exclusively--so this should be safe.

Submitted by:	bde
2001-06-25 06:17:02 +00:00
Dima Dorfman
e0e97f0aab Don't call exit(3) from a signal handler.
Obtained from:	OpenBSD
2001-06-24 01:55:17 +00:00
Dag-Erling Smørgrav
26f6b0fbe8 Add more headers that are required with -fno-builtin (stdlib and strings) 2001-06-19 15:41:57 +00:00
Ruslan Ermilov
be8b149795 mdoc(7) police: use the new features of the Nm macro. 2000-11-20 11:39:41 +00:00
Brian Feldman
53885065b7 Allow negative seek offsets for files that can be seeked upon. It
makes dd(1) a more complete "filter", even if this functionality is
limited to seekable streams.
2000-10-22 23:00:32 +00:00
Garrett Wollman
eb2fc78027 Don't depend on <sys/stat.h> bogusly including <sys/time.h> (and thereby
<time.h>).
2000-10-10 01:50:26 +00:00
Brian Feldman
5976ee7e31 Make the comment regarding ftruncate() correct. 2000-07-20 19:21:40 +00:00
Brian Feldman
c15c898eff Various cleanups are made to reduce warnings and make code prettier :)
Also, check for ftruncate() return value and die on failure, but only
try to ftruncate() when the file is a regular file.
2000-07-01 05:36:25 +00:00
David E. O'Brien
015a53cfff Fix ``dd if=/dev/zero of=/dev/daN'' on the Alpha by allowing the label
to be overwritten.

Submitted by:	green
2000-05-24 06:47:10 +00:00
Brian Feldman
6be607d0d5 After Bruce kindly explained the whole groff "sentence" idea to me, I've
put the whitespace in the right place.
2000-03-01 05:28:45 +00:00
Brian Feldman
c107f9e04f Fix style bugs I introduced in the last revision.
Brucified by:	bde
2000-02-27 16:40:39 +00:00
Brian Feldman
a6d413e7f8 Add iseek= and oseek= aliases for the preexisting skip= and seek=
operands.  Can _YOU_ tell skip= and seek= apart with 100% accuracy
every time?

This also seems to make us option-for-option compatible with the
Solaris dd(1).

Approved by:	jkh
Suggested by:	peter
2000-02-26 21:29:44 +00:00
Gregory Sutter
276d5ee851 Reflect that dd accepts octal and hexadecimal numbers (in addition to decimal).
PR:		16750
Submitted by:	Giorgos Keramidas <keramida@ceid.upatras.gr>
2000-02-18 04:55:40 +00:00
Brian Feldman
dd92370286 I've been Brucified! I did evil things with typedefs, but I'll do it
the correct (but less aesthetic) way, now.  New lesson: correctness
and aestheticity may be mutually exclusive at times.

Brucified by:	bde
1999-12-08 02:44:46 +00:00
Brian Feldman
67f80d12af Do proper constification in args.c. This shuts up -Wcast-qual (thanks,
bfumerola for that pointer!) in GCC complaining about losing a const.

While I'm here, might as well mark in the Makefile that I'm the
${MAINTAINER}.  It seems like that's what everyone's doing these days.
1999-12-07 03:32:37 +00:00
Brian Feldman
bf3367d091 Nuke the FIODTYPE compatibility bits. It's time. 1999-10-03 18:49:51 +00:00
Brian Feldman
5ff6541e7a Make count=0 set cpy_cnt to -1, which is slight overloading, but makes
what I was trying to do work much better (ie at all.  I could have sworn
it was working...) Fix a SEEK_SET to be SEEK_CUR, and make Bruce's
lseek() test work correctly.
1999-09-16 19:50:59 +00:00
Brian Feldman
1838cf5671 Let count=-something fail, while count=0 may succeed, thus making dd(1)
useful as a seeking-tool as well as its many other uses.  Previously,
dd(1) would succeed with count=0, but wouldn't get to the point that
blocks were to be read/written. This is a more useful behavior, and
this specific case doesn't seem to be handled by POSIX.
1999-09-16 05:12:59 +00:00
Brian Feldman
7599187e0d Even more dd(1) cleanups! Thanks to Bruce for staying on my case until
we're done (not yet!) :)
1999-09-13 21:47:10 +00:00
Brian Feldman
32952d4b37 ISDISK -> ISSEEK
Allow a device type of D_DISK or D_MEM to be ISSEEK.
1999-09-12 18:56:12 +00:00
Brian Feldman
5868747254 Even more cleanups to dd(1). This is probably the culmination of the
BDEification process of dd(1). Most of the changes are from BDE's archive.
Support for negative offsets is gone again, but the case where you
lseek() onto byte -1 of something from a negative offset using seek/skip
is fixed; if you end up on -1, you won't get a false positive lseek failure.
  The biggest changes are to data types (more size_t, for instance) and
argument parsing. skip/seek on /dev/{,k}mem now occurs (instead of "read
until you reach the offset") due to mem devices now being D_DISK. Some
const things are now correctly declared as such, and the "case table"
building is better. The only thing that seems to be left to make dd(1)
everything TOG wants it to be is l10n.
1999-09-12 16:51:53 +00:00
Brian Feldman
e14f7e789a Make a bit more headway with dd's argument parsing, etc. get_bsz() is
renamed get_num() since it's not just about block sizes. skip and
seek can be any offset, including negative, now. Some style bogons are fixed.
1999-09-11 00:02:42 +00:00
Brian Feldman
ff8bb989ab Relax things a bit. Not having FIODTYPE will be a warning for now.
Pointy hat:	green
Pointed out by:	peter
1999-08-28 03:37:38 +00:00
Peter Wemm
2a4562393f $Id$ -> $FreeBSD$ 1999-08-27 23:15:48 +00:00
Brian Feldman
e08d7384ee Use FIODTYPE to unbogosify much of the file type checking in dd. 1999-08-27 16:36:46 +00:00
Brian Feldman
769e5815e3 Implement seekability for disk devices (not just regular files).
Also, fix pos_out() to do the same checks pos_in() did.

Done for:	jdp, luigi, the good of the world
1999-07-13 18:44:56 +00:00