summaryrefslogtreecommitdiff
path: root/src/dd.c
AgeCommit message (Collapse)Author
2013-07-19dd: make status=none suppress all diagnosticsPádraig Brady
* src/dd.c (STATUS_NONE): Simplify the enum so that it's more general than just suppressing transfer counts. Then test this in all locations where non fatal diagnostics are output. * tests/dd/misc.sh: Ensure the diagnostic about being unable to skip past the end of input is suppressed. * NEWS: Mention the change in behavior. Fixes http://bugs.gnu.org/14897
2013-04-14dd: avoid buffer allocations unless neededOndrej Oprala
* src/dd.c: Add new static global variable ibuf. (alloc_ibuf, alloc_obuf): New functions factored from dd_copy(). (dd_copy): Call the new functions to allocate memory for ibuf and obuf when necessary. (skip): Likewise. * tests/dd/no-allocate.sh: New test. * tests/local.mk: Reference the test.
2013-02-06maint: improve error messages upon failed read, write, access, closeBenno Schulenberg
Note we use "failed to {access,close}" for those single operations, and "error {read,writ}ing" for those partial operation failures. * src/copy.c: Improve error messages for failing read, write and close. * src/cp.c: Improve error messages for failing access. * src/dd.c: Improve error messages for failing read, write and open. * src/head.c: Improve error message for failing close. * src/install.c: Improve error messages for failing access. * src/ln.c: Likewise. * src/mv.c: Likewise. * src/touch.c: Improve error message for failing close. * src/truncate.c: Likewise.
2013-01-01maint: update all copyright year number rangesJim Meyering
Run "make update-copyright", but then also run this, perl -pi -e 's/2\d\d\d-//' tests/sample-test to make that one script use the single most recent year number.
2012-12-21dd: fix a printf format mismatch in an error messagePádraig Brady
* src/dd.c (dd_copy): To print an off_t portably we need to use PRIdMAX and cast to intmax_t, otherwise there could be a mismatch between say a 32 bit off_t and uintmax_t. This was flagged by -Wformat on a 64 bit host when compiling with CFLAGS=-m32.
2012-09-24dd: new option, status=none to suppress output statisticsPozsár Balázs
* src/dd.c (STATUS_NONE): A new bitmask combining all STATUS_ options, thus used to suppress all informational output. (struct symbol_value statuses): Expose the "none" option, corresponding to the STATUS_NONE bitmask above. (print_stats): Return early if STATUS_NONE is specified. Also move the call to gethrxtime() down so that it's only called when needed. (usage): Describe the new options. * doc/coreutils.texi (dd invocation): Likewise. * NEWS: Mention the new feature. * tests/dd/misc.sh: Ensure the new option works.
2012-09-18dd: remove references to the word BLOCKS from help and texi docsBenno Schulenberg
The renaming from BLOCKS to N was done in v8.15-38-g140eca1, and documentation for N was added again in v8.17-26-g4f2e9d5 without noticing that. Now, finally remove the word BLOCKS from the documentation. * src/dd.c (usage): Remove the word BLOCKS. * doc/coreutils.texi (dd invocation): Likewise. Improved by: Bernhard Voelker <mail@bernhard-voelker.de>
2012-06-22doc: document multiplier for dd number options like count=NBernhard Voelker
* src/dd.c (usage): Add "N" to the description of multipliers. * doc/coreutils.texi (dd invocation): Likewise.
2012-06-22maint: refactor common mode bits used to create filesPádraig Brady
* src/system.h (MODE_RW_UGO): The new refactored define (666). * src/mkfifo.c: Use the new define. * src/mknod.c: Likewise. * src/split.c: Likewise. * src/system.h: Likewise. * src/touch.c: Likewise. * src/truncate.c: Likewise. Suggested-by: Jim Meyering
2012-05-10maint: handle file sizes more reliablyPaul Eggert
Problem reported by Samuel Thibault in <http://bugs.gnu.org/11424>. * NEWS: Document this. * src/dd.c (skip): Handle skipping past EOF on shared or typed memory objects the same way as with regular files. (dd_copy): It's OK to truncate shared memory objects. * src/du.c (duinfo_add): Check for overflow. (print_only_size): Report overflow. (process_file): Ignore negative file sizes in the --apparent-size case. * src/od.c (skip): Fix comment about st_size. * src/split.c (main): * src/truncate.c (do_ftruncate, main): On files where st_size is not portable, fall back on using lseek with SEEK_END to determine the size. Although strictly speaking POSIX says the behavior is implementation-defined, in practice if lseek returns a nonnegative value it's a reasonable one to use for the file size. * src/system.h (usable_st_size): Symlinks have reliable st_size too. * tests/misc/truncate-dir-fail: Don't assume that getting the size of a dir is not allowed, as it's now allowed on many platforms, e.g., GNU/Linux.
2012-03-06maint: refactor copy to use is_nul()Pádraig Brady
* src/dd.c: Move is_nul() from here to ... * src/system.h: ... here * src/copy.c (sparse_copy): Adjust to use the refactored is_nul()
2012-02-29dd: add support for the conv=sparse optionRoman Rybalko
Notes: Small seeks are not coalesced to larger ones, like is done in cache_round() for example. conv= is used rather then oflag= for FreeBSD compatibility. * src/dd.c (final_op_was_seek): A new global boolean to flag whether the final "write" was converted to a seek. (usage): Describe the new conf=sparse option. (iwrite): Convert a write of a NUL block to a seek if requested. (do_copy): Initialize the output buffer to have a sentinel, to allow for efficient testing for NUL output blocks. If the last block in the file was converted to a seek, then convert back to a write so the size is updated. * NEWS: Mention the new feature. * tests/dd/sparse: A new test for the feature. * tests/Makefile.am: Reference the new test.
2012-02-13dd: fix issues in the count_bytes and seek_bytes flags changePádraig Brady
These edge cases were missed in the previous commit 140eca15c. * src/dd.c (main): Include the bytes slop when truncating without further I/O. Don't invalidate the whole file cache in the case where 0 < count < ibs. * tests/dd/bytes: Change to using the independent truncate command to generate the file for comparison. Remove a redundant test case and replace with one testing the truncation only logic.
2012-02-12dd: add count_bytes, skip_bytes and seek_bytes flagsJérémy Compostella
dd now accepts the count_bytes and skip_bytes input flag and the seek_bytes output flag, to more easily allow processing portions of a file. * src/dd.c (scanargs): Compute skip_records and skip_bytes when 'skip_bytes' iflag is used. Compute max_records and max_bytes when 'count_bytes' iflag is used. Compute seek_records and seek_bytes when 'seek_bytes' oflag is used. (skip_via_lseek): Use new 'bytes' parameter and handle potential 'records' equals to zero. Update the bytes parameter when called with 'fdesc' equal to STDOUT_FILENO. Update the header comments. (dd_copy): Skip accordingly to skip_records AND skip_bytes. Count accordingly to max_records AND max_bytes. Seek on output accordingly to seek_records AND seek_bytes. * NEWS (New features): Mention it. * doc/coreutils.texi (dd invocation): Detail new flags and behaviors. * tests/dd/bytes: New file. Tests for these new flags. * tests/Makefile.am (TESTS): Add it.
2012-02-06maint: add braces as requested by HACKING coding standardJérémy Compostella
* src/dd.c (dd_copy): Braces were missing for this do/while statement.
2012-01-27maint: use single copyright year rangeJim Meyering
Run "make update-copyright".
2012-01-09maint: src/*.c: change remaining quotes (without embedded spaces)Jim Meyering
Run this (twice): git grep -E -l '`[^ ]+'\' src/*.c \ |xargs perl -pi -e 's/`([^ ]+'\'')/'\''$1/'
2012-01-09maint: convert `...' to '...' in --help outputJim Meyering
All affected lines end with \ or \n\, so run this command until it produces no new changes (4 times): git grep -E -l '`[^ ]+'\''.*\\' src \ |xargs perl -pi -e 's/`([^ ]+'\''.*\\)/'\''$1/'
2012-01-07maint: use new emit_try_help in place of equivalent fprintfJim Meyering
Run this command: perl -0777 -pi -e \ 's/fprintf \(stderr, _\("Try `%s --help.*\n.*;/emit_try_help ();/m'\ src/*.c
2012-01-01maint: update all copyright year number rangesJim Meyering
Run "make update-copyright".
2011-07-16dd: port to NonStop (Bug#9076)Paul Eggert
* src/dd.c (SA_RESETHAND): Define to 0 if not defined.
2011-07-15* src/dd.c: Remove obsolete comments re POSIX.Paul Eggert
2011-07-02maint: use "const" and "pure" function attributes where possibleJim Meyering
* configure.ac (WARN_CFLAGS): Add -Wsuggest-attribute=const, -Wsuggest-attribute=pure and -Wsuggest-attribute=noreturn. (GNULIB_WARN_CFLAGS): But do not add them here... yet. * src/chown-core.h (chopt_free, uid_to_name): Add function attribute(s). * src/copy.c (is_ancestor, valid_options): Likewise. * src/copy.h (chown_failure_ok): Likewise. * src/dd.c (operand_matches, operand_is): Likewise. * src/df.c (selected_fstype, excluded_fstype): Likewise. * src/expr.c (null looks_like_integer): Likewise. * src/md5sum.c (hex_digits): Likewise. * src/od.c (get_lcm): Likewise. * src/pathchk.c (component_start, component_len): Likewise. * src/pinky.c (count_ampersands): Likewise. * src/pr.c (cols_ready_to_print): Likewise. * src/ptx.c (search_table): Likewise. * src/sort.c (find_unit_order): Likewise. * src/stty.c (mode_type_flag, string_to_baud, baud_to_value): Likewise. * src/system.h (gcd, lcm): Likewise. * src/tr.c (is_char_class_member, look_up_char_class): Likewise. (star_digits_closebracket): Likewise. * src/uniq.c (find_field): Likewise. * src/wc.c (compute_number_width): Likewise. * lib/xfts.h (cycle_warning_required): Likewise. * gl/lib/randint.h (randint_get_source): Likewise. * gl/lib/randperm.c (ceil_lg): Likewise. * gl/lib/randperm.h (randperm_bound): Likewise. * lib/strnumcmp.h (strintcmp): Likewise.
2011-06-09maint: remove unneeded includesPádraig Brady
Remove unneeded includes as reported by: http://code.google.com/p/include-what-you-use/ * src/cp-hash.c: Remove unused include. * src/dd.c: Likewise. * src/du.c: Likewise. * src/head.c: Likewise. * src/kill.c: Likewise. * src/ls.c: Likewise. * src/stdbuf.c: Likewise. * src/timeout.c: Likewise. * src/truncate.c: Likewise.
2011-04-26dd: work around compilation failure on AIX 5.1 and 5.2Jim Meyering
* src/dd.c (O_NOCACHE): Undefine. This symbol is defined via AIX's <fcntl.h>, yet used as an enum name in dd.c. Reported by Gary V. Vaughan in http://debbugs.gnu.org/8555 * NEWS (Portability): Mention this.
2011-04-26maint: move two small functions, so we can remove a fwd declJim Meyering
* src/dd.c (cleanup, quit): Move the definition of quit to follow the definition of process_signals, so we can remove the declaration of the latter.
2011-03-05dd: avoid or diagnose some problems with short readsPaul Eggert
* src/dd.c (warn_partial_read): New static var. (iread): Diagnose partial reads if needed. (iwrite): Don't diagnose them here; not needed any more. (scanargs): Determine whether partial reads should be diagnosted.
2011-03-05dd: add a flag to discard cached dataPádraig Brady
* src/dd.c (FFS_MASK): A new macro (Find First Set) refactored from the following enum as it's now used twice. (usage): Mention the new 'nocache' flag. (cache_round): A new function to help ignore requests to drop cache, that are less than page_size. (invalidate_cache): A new function to call posix_fadvise() with the appropriate offset and length. Note we don't use fdadvise() so we can detect errors when count=0. (dd_copy): Call invalidate_cache() for the portions read. (iwrite): Likewise for the portions written. (main): Call invalidate_cache for page_size slop or for full file when count=0. * cfg.mk (sc_dd_O_FLAGS): Adjust to pass. * doc/coreutils.texi (dd invocation): Describe the 'nocache' flag, and give some examples of how it can be used. * tests/dd/nocache: A new test. * tests/Makefile.am: Reference the new test. * NEWS: Mention the new feature.
2011-03-05doc: clarify that `dd bs=` can immediately output short readsPádraig Brady
* doc/coreutils.texi (dd invocation): Clarify that bs= can cause parital reads to be immediately written to output. * src/dd.c (usage): Hint that bs= can cause partial writes. See http://debbugs.gnu.org/cgi/bugreport.cgi?bug=8171
2011-03-05doc: group dd conv= options that are actually flagsPádraig Brady
* src/dd.c (usage): Move 'sync' up with other data transformation options. Having it alongside 'fsync' and 'fdatasync' is particularly confusing. Also the double line description of the 'sync' option, serves as a visual break from the "flag" type options that follow. * doc/coreutils.texi (dd invocation): Apply the same grouping as above, by splitting the "conv=" table in two.
2011-03-05dd: warn when we disable oflag=direct not at EOFPádraig Brady
An alternative to this is to auto enable iflag=fullblock when oflag=direct and bs= is specified. It was thought better though, to warn about the specific issue, and give full control of dd's options to the user. * src/dd.c (iwrite): Warn, when we write after having disabled O_DIRECT. See https://bugzilla.redhat.com/show_bug.cgi?id=614605
2011-01-01maint: update all copyright year number rangesJim Meyering
Run "make update-copyright".
2010-12-28coreutils: keep lines within 80-column limitsPaul Eggert
* cfg.mk (LINE_LEN_MAX, FILTER_LONG_LINES): New macros. (sc_long_lines): New rule. * HACKING: Use shorter URLs to the same material. * doc/Makefile.am, doc/coreutils.texi, m4/boottime.m4: * man/help2man, man/stdbuf.x, src/Makefile.am, src/cat.c, src/copy.c: * src/cp.c, src/dd.c, src/df.c, src/du.c, src/groups.c, src/install.c: * src/ls.c, src/md5sum.c, src/mv.c, src/od.c, src/pinky.c, src/ptx.c: * src/readlink.c, src/remove.c, src/rmdir.c, src/setuidgid.c: * src/sort.c, src/tail.c, src/touch.c, tests/Coreutils.pm: * tests/cp/existing-perm-race, tests/cp/perm, tests/cp/preserve-gid: * tests/du/2g, tests/du/long-from-unreadable, tests/init.sh: * tests/install/basic-1, tests/ls/nameless-uid: * tests/ls/readdir-mountpoint-inode, tests/misc/chroot-credentials: * tests/misc/cut, tests/misc/date, tests/misc/join, tests/misc/md5sum: * tests/misc/sha1sum, tests/misc/sha224sum, tests/misc/sort: * tests/misc/sort-continue, tests/misc/sort-files0-from: * tests/misc/sort-rand, tests/misc/stdbuf, tests/misc/tr: * tests/misc/uniq, tests/mv/atomic, tests/mv/part-fail: * tests/mv/part-symlink, tests/mv/sticky-to-xpart, tests/pr/pr-tests: * tests/rm/fail-2eperm, tests/rm/interactive-always: Reformat to fit within 80 columns. * doc/Makefile.am (BAD_POSIX_PERL): New macro. * doc/coreutils.texi: Reword slightly, to make menus and index lines shorter. * src/md5sum.c: Redo --help output so that it fits within 79 columns, since that's a bit more portable and all the other --help strings fit in 79 columns.
2010-07-22fadvise: new module providing a simpler interface to posix_fadvisePádraig Brady
* bootstrap.conf: Include the new module * gl/lib/fadvise.c: Provide a simpler interface to posix_fadvise. (fadvise): Provide hint to the whole file associated with a stream. (fdadvise): Provide hint to the specific portion of a file associated with a file descriptor. * gl/lib/fadvise.h: Redefine POSIX_FADV_* to FADVISE_* enums. * gl/modules/fadvise: New file. * m4/jm-macros.m4: Remove the no longer needed posix_fadvise check. * .x-sc_program_name: Exclude test-fadvise.c from this check. * gl/tests/test-fadvise (main): New test program. * gl/modules/fadvise-testss: A new index to reference the tests. * src/sort.c (stream_open): Use the new interface. * src/dd.c (iwrite): Likewise.
2010-07-12dd: also spell out size on memory exhaustionPaul R. Eggert
* src/dd.c (dd_copy): Use requested blocksize (not adjusted) in diagnostic, to forestall user complaints that the numbers don't match exactly. Report both exact and human-readable sizes, using a message format that is consistent with both "BBBB bytes (N XB) copied" in dd.c and "memory exhausted" in lib/xmalloc.c.
2010-06-14dd: print a better diagnostic for an invalid block sizeJim Meyering
* src/dd.c (dd_copy): Give a better diagnostic than "dd: memory exhausted" for an over-large bs= block size setting. Same for ibs= and obs=. Reported by Imre Péntek in http://bugs.launchpad.net/ubuntu/+source/coreutils/+bug/591969
2010-05-31maint: replace each "for (;;)" with "while (true)"Jim Meyering
Run this command: git ls-files | grep '\.[ch]$' \ | xargs perl -pi -e 's/for \(;;\)/while (true)/g' ...except for randint.c, which does not include stdbool.h. In that case, use "while (1)". * gl/lib/randint.c (randint_genmax): Use "while (1)" for infloops. * src/cat.c (simple_cat, cat): Use "while (true)" for infloops. * gl/lib/randread.c (readsource, readisaac): Likewise. * src/copy.c (copy_reg): Likewise. * src/csplit.c (record_line_starts, process_regexp): Likewise. * src/cut.c (set_fields): Likewise. * src/dd.c (iread, parse_symbols): Likewise. * src/df.c (find_mount_point, main): Likewise. * src/du.c (main): Likewise. * src/expand.c (expand): Likewise. * src/factor.c (factor_using_division, do_stdin): Likewise. * src/fmt.c (get_space): Likewise. * src/ls.c (decode_switches): Likewise. * src/od.c (main): Likewise. * src/pr.c (main, read_line): Likewise. * src/shred.c (dopass, genpattern): Likewise. * src/sort.c (initbuf, fillbuf, getmonth, keycompare): Likewise. * src/split.c (bytes_split, lines_split): Likewise. * src/tac.c (tac_seekable): Likewise. * src/test.c (and, or): Likewise. * src/tr.c (squeeze_filter, main): Likewise. * src/tsort.c (search_item): Likewise. * src/unexpand.c (unexpand): Likewise. * src/uniq.c (main): Likewise. * src/yes.c (main): Likewise.
2010-05-03maint: remove now-redundant definitions provided by signal.hJim Meyering
* src/dd.c (SA_NODEFER, SA_RESETHAND): Remove definitions, now that gnulib guarantees they are defined in <signal.h>. * src/ls.c (SA_RESTART): Likewise.
2010-03-17maint: add a space before open-paren, where lackingJim Meyering
* src/copy.c (copy_reg): Likewise. * src/cut.c (main): Likewise. * src/dd.c (main): Likewise. * src/getlimits.c (print_int): Likewise. * src/join.c (join): Likewise. * src/pwd.c (logical_getcwd): Likewise. * src/sort.c (specify_nmerge, mergefps, avoid_trashing_input): Likewise. (merge): Likewise. * src/uptime.c (usage): Likewise.
2010-01-01maint: update all FSF copyright year lists to include 2010Jim Meyering
Use this command: git ls-files | grep -v COPYING \ | xargs env UPDATE_COPYRIGHT_USE_INTERVALS=1 \ build-aux/update-copyright
2009-09-23maint: Use logical rather than bitwise operators on boolsPádraig Brady
This is because bitwise operators are: - confusing and inconsistent in a boolean context - non short circuiting - brittle in C89 where bool can be an int (so > 1)
2009-09-21doc: mention the texinfo documentation in --helpPádraig Brady
* src/system.h: Rename emit_bug_reporting_address() to emit_ancillary_info() and update it to not print the translation project address in en_* locales, and _do_ print it in the 'C' (and other) locales so that it's included in the default man page. Also mention how to invoke the texinfo documentation for each command. Also move the "hard-locale.h" include to the 8 files that now use it. * man/help2man: Strip the newly added texinfo reference from the --help output as a more verbose version is already added by help2man. Suggestion from C de-Avillez
2009-09-10dd conv=unblock: print final newline consistentlyJim Meyering
* src/dd.c (dd_copy) [C_UNBLOCK]: Always print the final newline for non-empty output, not just when output size is a multiple of cbs. * doc/coreutils.texi (dd invocation) [conv=unblock]: Mention that dd prints a newline after each output record, not just when replacing trailing spaces. Reported by Ulrich Drepper. * tests/dd/unblock: New file. Test for this. * tests/Makefile.am (TESTS): Add it. * NEWS (Bug fixes): Mention it.
2009-09-01maint: dd: remove unnecessary initializationJim Meyering
* src/dd.c (skip): Remove set-but-never-used variable, soffset.
2009-08-28dd: detect closed stderrEric Blake
* src/dd.c (maybe_close_stdout): Always flush stderr; regression introduced in commit 381e69ea. * tests/misc/close-stdout (p): Use consistent style. * tests/dd/stderr: New test, borrowing from misc/close-stdout. * tests/Makefile.am (TESTS): Run it. * NEWS: Mention this.
2009-08-25global: convert indentation-TABs to spacesJim Meyering
Transformed via this shell code: t=$'\t' git ls-files \ | grep -vE '(^|/)((GNU)?[Mm]akefile|ChangeLog)|\.(am|mk)$' \ | grep -vE 'tests/pr/|help2man' \ | xargs grep -lE "^ *$t" \ | xargs perl -MText::Tabs -ni -le \ '$m=/^( *\t[ \t]*)(.*)/; print $m ? expand($1) . $2 : $_'
2009-08-13dd: fix a signal handling racePádraig Brady
* src/dd.c (main): Install the signal handlers at startup rather than just before the copy starts. In this way signals received before the copy (like during a slow truncate for e.g.) will be deferred and handled consistently. * THANKS: Add Bernhard's email address. * NEWS: Mention the fix. Reported by Bernhard Voelker.
2009-08-07dd: preserve semantics of O_DIRECT even for final blockJim Meyering
* src/dd.c: Include "ignore-value.h" (iwrite): When disabling O_DIRECT, try to compensate via POSIX_FADV_DONTNEED and fsync. Suggested by Eric Sandeen.
2009-08-06dd: work around buffer length restrictions with oflag=direct (O_DIRECT)Jim Meyering
dd oflag=direct would fail to copy a file with size that is not a multiple of 512 (destination file system specific) * NEWS (Bug fixes): Mention it. * src/dd.c (iwrite): Turn off O_DIRECT for any smaller-than-obs-sized write. Don't bother to restore it. * tests/dd/direct: New test for the above. * tests/Makefile.am (TESTS): Add dd/direct. * doc/coreutils.texi (dd invocation): Mention oflag=direct buffer size restriction. Details in http://thread.gmane.org/gmane.comp.gnu.coreutils.bugs/17586 Reported by Eric Sandeen.
2009-08-04dd: remove unnecessary #if HAVE_FTRUNCATEJim Meyering
* src/dd.c (main): Remove unnecessary cpp directives. Gnulib guarantees that ftruncate is usable.