summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJim Meyering <meyering@redhat.com>2009-08-04 19:54:58 +0200
committerJim Meyering <meyering@redhat.com>2009-08-06 09:41:50 +0200
commit5929322ccb1f9d27c1b07b746d37419d17a7cbf6 (patch)
tree685ca3efe05ce619b33392ea499ad87c1c7a620c /src
parent365fb90eaae52c92d6af8e87769e72b872492f4a (diff)
downloadcoreutils-5929322ccb1f9d27c1b07b746d37419d17a7cbf6.tar.xz
dd: work around buffer length restrictions with oflag=direct (O_DIRECT)
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.
Diffstat (limited to 'src')
-rw-r--r--src/dd.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/dd.c b/src/dd.c
index 9a9d22ae7..43ad7189f 100644
--- a/src/dd.c
+++ b/src/dd.c
@@ -837,6 +837,14 @@ iwrite (int fd, char const *buf, size_t size)
{
size_t total_written = 0;
+ if ((output_flags & O_DIRECT) && size < output_blocksize)
+ {
+ int old_flags = fcntl (STDOUT_FILENO, F_GETFL);
+ if (fcntl (STDOUT_FILENO, F_SETFL, old_flags & ~O_DIRECT) != 0)
+ error (0, errno, _("failed to turn off O_DIRECT: %s"),
+ quote (output_file));
+ }
+
while (total_written < size)
{
ssize_t nwritten;
@@ -1897,7 +1905,7 @@ main (int argc, char **argv)
|| S_ISDIR (stdout_stat.st_mode)
|| S_TYPEISSHM (&stdout_stat))
error (EXIT_FAILURE, ftruncate_errno,
- _("truncating at %"PRIuMAX" bytes in output file %s"),
+ _("failed to truncate to %"PRIuMAX" bytes in output file %s"),
size, quote (output_file));
}
}