Commit Graph

182 Commits

Author SHA1 Message Date
obrien
0a9c353f64 Mention the dd-like recoverdisk(1) to help folks find this great BSD command. 2015-07-16 23:38:12 +00:00
sjg
008d7c831f 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
sjg
75a137820d dirdeps.mk now sets DEP_RELDIR 2015-06-08 23:35:17 +00:00
sjg
b137080f19 Merge from head@274682 2014-11-19 01:07:58 +00:00
pi
4280e8bc36 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
pi
0b6ca5ce8d 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
imp
8515eb534e Update the date for last example.
Sponsored by: Netflix
2014-08-30 02:12:58 +00:00
imp
f6fd3e39b4 Add canonical population of a disk / thumb drive from an image
example.
2014-08-28 21:30:39 +00:00
sjg
5860f0d106 Updated dependencies 2014-05-16 14:09:51 +00:00
sjg
1a7e48acf1 Updated dependencies 2014-05-10 05:16:28 +00:00
sjg
ed3fc70bf5 Merge from head 2014-05-08 23:54:15 +00:00
asomers
5bd695fd96 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
a29159cd70 (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
asomers
c9e9fdb2a1 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
574a744c49 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
4346e12888 Minor comment fix. 2014-05-03 09:06:11 +00:00
sjg
5e568154a0 Merge head 2014-04-28 07:50:45 +00:00
delphij
5e09731152 Make C_* contants fit in 32 bits again by using 4 unused bits.
Noticed by:	bde
2014-04-03 06:32:02 +00:00
delphij
101a8946cc 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
sjg
7fcd33c1fa Merge head@256284 2013-10-13 02:35:19 +00:00
pluknet
3f9b259642 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
sjg
62bb106222 Merge from head 2013-09-05 20:18:59 +00:00
eadler
9f34a8fbd1 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
kib
f96ceb3029 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
sjg
97d8b94956 sync from head 2013-04-12 20:48:55 +00:00
brooks
e241794c89 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
sjg
6d37b86f2b Updated dependencies 2013-03-11 17:21:52 +00:00
sjg
0ee5295509 Updated dependencies 2013-02-16 01:23:54 +00:00
sjg
778e93c51a Sync from head 2012-11-04 02:52:03 +00:00
ed
c23d2a42d7 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
02dcf28b58 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
9dd41e3647 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
keramida
f5f831de53 Bump .Dd for r187609 2009-01-30 16:23:57 +00:00
keramida
c2287d6285 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
markm
f6ff2e99e6 More inactive maintainers. 2006-07-09 21:47:37 +00:00
keramida
8090607544 Spell "protections" correctly. 2005-07-28 18:28:11 +00:00
ru
291174c7f1 Sort sections.
Approved by:	re (blanket)
2005-06-14 08:25:54 +00:00
scottl
986a072ce4 Document problems with writing to disks under GEOM. 2005-04-07 20:50:38 +00:00
ru
ffd9fd4c0e 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
imp
a76898b849 /*- or .\"- or #- to begin license clauses. 2005-01-10 08:39:26 +00:00
ru
1cd8ce95ba Scheduled mdoc(7) sweep. 2005-01-09 19:54:23 +00:00
rwatson
9e69bea9f1 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
pjd
a9d4d391b8 Allow for capital letters as size suffixes.
Inspired by:	le
Approved by:	green (maintainer)
2004-07-31 15:13:08 +00:00
ru
7cba80f9da Bump document date for the latest functional change.
Minor markup tweaks.
2004-05-16 21:34:15 +00:00
njl
d7b4a9c5ca Style fixes and add gen to CLEANFILES.
Submitted by:	bde
2004-04-09 07:13:27 +00:00
markm
4383f14801 Remove clause 3 from the UCB licenses.
OK'ed by:	imp, core
2004-04-06 20:06:54 +00:00
ache
d33e9b93a7 Remove a.out at the end of 'make test' 2004-03-08 18:09:33 +00:00
bde
ac2e10a4f5 Fixed some style bugs (mainly unsorting and tab lossage in previous commit). 2004-03-06 08:21:32 +00:00
ache
ebdf8c08b8 Add a.out to CLEANFILES 2004-03-06 06:54:58 +00:00
ache
432e315dd7 Change locale name from non-existent ASCII to en_US.US-ASCII 2004-03-06 06:10:16 +00:00
phk
d0818243a9 Teach dd(1) about parity bits. 2004-03-05 19:35:51 +00:00
phk
99a4684d72 Add a test-target and reference vectors for the character converions. 2004-03-05 19:30:13 +00:00
markm
aafc494847 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
obrien
eaf3fff90a Quiet warnings about copyright[]. 2003-05-01 16:58:57 +00:00
ru
e6fb7d9461 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
ru
6999b65340 Fixed (soon might be fatal) -Wformat warnings. 2003-03-15 07:56:59 +00:00
markm
5736aa9039 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
phk
eed7833b83 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
ru
10c48e457c 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
obrien
c84c569bd1 Consistently use __FBSDID 2002-06-30 05:13:54 +00:00
keramida
b309515be2 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
ru
c17d65090d mdoc(7) police: replace the XXX with the correct width. 2002-05-29 14:01:27 +00:00
jedgar
47acb76e7c Add semicolon to empty default case to silence warning. 2002-05-11 03:12:02 +00:00
keramida
9e46855391 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
markm
43cc55dd2f 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
markm
7b7558d884 Fix warnings inspired by lint, a commercial lint and WARNS=4. 2002-02-22 20:51:00 +00:00
green
b3206d8278 Correct a logic bug that snuck in and broke multiplication of off_ts. 2002-02-07 02:54:30 +00:00
kris
bb3058824a Lock down with WFORMAT=1 except those directories with unfixed warnings.
Tested on i386 and alpha.
2002-02-04 02:49:19 +00:00
imp
5203a0a465 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
green
db659d013d 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
obrien
099f8ecbe9 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
ru
bde8ec1b70 mdoc(7) police: utilize the new .Ex macro. 2001-08-15 09:09:47 +00:00
ru
24c7b0a61d mdoc(7) police: s/BSD/.Bx/ where appropriate. 2001-08-14 10:01:54 +00:00
green
a9b531b74d Use __unused for non-used variables.
Submitted by:	Mike Barcroft <mike@q9media.com>
2001-06-29 20:06:47 +00:00
dd
3dc2f99bef 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
dd
7438ee8a47 Don't call exit(3) from a signal handler.
Obtained from:	OpenBSD
2001-06-24 01:55:17 +00:00
des
8e8983228c Add more headers that are required with -fno-builtin (stdlib and strings) 2001-06-19 15:41:57 +00:00
ru
be1f850a8f mdoc(7) police: use the new features of the Nm macro. 2000-11-20 11:39:41 +00:00
green
aa2e16431f 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
wollman
c5c43ce91f Don't depend on <sys/stat.h> bogusly including <sys/time.h> (and thereby
<time.h>).
2000-10-10 01:50:26 +00:00
green
1ab6aa1440 Make the comment regarding ftruncate() correct. 2000-07-20 19:21:40 +00:00
green
5f788961ba 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
obrien
f84c12deda 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
green
bcb4b1ee2b 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
green
198256e173 Fix style bugs I introduced in the last revision.
Brucified by:	bde
2000-02-27 16:40:39 +00:00
green
708c7f49eb 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
gsutter
b5faf349c6 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
green
9ad0971067 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
green
277eda1860 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
green
0a7a70c712 Nuke the FIODTYPE compatibility bits. It's time. 1999-10-03 18:49:51 +00:00
green
a12ece1af8 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
green
4e25c183b5 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
green
996b2b913e 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
green
e40ba94136 ISDISK -> ISSEEK
Allow a device type of D_DISK or D_MEM to be ISSEEK.
1999-09-12 18:56:12 +00:00
green
4c16a85a3f 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
green
a9f7b5ee69 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
green
c4aced0891 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
66312e4a8d $Id$ -> $FreeBSD$ 1999-08-27 23:15:48 +00:00
green
1b913741fc Use FIODTYPE to unbogosify much of the file type checking in dd. 1999-08-27 16:36:46 +00:00
green
ac63841b82 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