bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

dd and binary mode


From: Eric Blake
Subject: dd and binary mode
Date: Fri, 13 May 2005 16:42:04 +0000

After further thought and discussion on the cygwin list, I'm convinced
that dd should default to binary mode (on non-ttys) on systems that
have a distinct text mode.  Otherwise, consider the harmful effects of
`dd of=/dev/sda if=mbr' to overwrite the master boot record, if the
user did not realize that mbr was on a text-mode mount.  dd(1) is too
commonly associated with binary files, similar to od(1), to risk making it
default according to the underlying mount mode.

I noticed that system.h defines SET_BINARY to avoid changing the mode
of ttys, so by using that, iflag=binary is not necessarily a no-op.  But in
general, to get text mode, a user should need to explicitly ask for it with
iflag=text.

Also, cygwin requires the use of setmode() to change a file's mode;
fcntl(F_GETFL) shows the current mode, but fcntl(F_SETFL) masks mode
and permissions bits, having no effect on the mode.  POSIX does mention
that fcntl(F_SETFL) only has specified results on file status bits.  One
question remains - system.h assumes that the return value of SET_MODE
should be ignored (when O_BINARY is undefined, SET_MODE is (void)0).
But on cygwin, setmode can return -1 on failure with EBADF or EINVAL.  Should
this assumption in system.h be changed, or my patch tweaked to ignore the
value of SET_MODE?

2005-05-13  Eric Blake  <address@hidden>  (tiny change)

        * src/dd.c (set_fd_flags): Handle mode changes with SET_MODE,
        since Cygwin cannot change mode with fcntl.
        (main): Default to binary if [io]flag= did not choose mode.

--
Eric Blake

Attachment: coreutils.patch
Description: Binary data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]