Date: Sat, 21 Dec 2013 14:37:44 GMT From: Chang-Hsien Tsai <luke.tw@gmail.com> To: freebsd-gnats-submit@FreeBSD.org Subject: bin/185070: [patch] dd(1) add better error message when partial write to dev Message-ID: <201312211437.rBLEbiJQ005537@oldred.freebsd.org> Resent-Message-ID: <201312211440.rBLEe0Ug011438@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 185070 >Category: bin >Synopsis: [patch] dd(1) add better error message when partial write to dev >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Sat Dec 21 14:40:00 UTC 2013 >Closed-Date: >Last-Modified: >Originator: Chang-Hsien Tsai >Release: FreeBSD 10.0-RC2 >Organization: >Environment: FreeBSD bsd10 10.0-RC2 FreeBSD 10.0-RC2 #0 r259404: Sun Dec 15 08:18:20 UTC 2013 root@snap.freebsd.org:/usr/obj/usr/src/sys/GENERIC amd64 >Description: when dd writes to a device, the error message is misleading if the write size is less than the sector size of the device. >How-To-Repeat: 1. create input files bsd10# dd if=/dev/random of=/root/512b bs=1 count=512 512+0 records in 512+0 records out 512 bytes transferred in 0.001007 secs (508400 bytes/sec) bsd10# dd if=/dev/random of=/root/513b bs=1 count=513 513+0 records in 513+0 records out 513 bytes transferred in 0.000936 secs (548059 bytes/sec) 2. dd these input files to /dev/ bsd10# dd if=/root/512b of=/dev/da1 1+0 records in 1+0 records out 512 bytes transferred in 0.005722 secs (89478 bytes/sec) bsd10# dd if=/root/513b of=/dev/da1 dd: /dev/da1: Invalid argument 1+1 records in 1+0 records out 512 bytes transferred in 0.000363 secs (1410962 bytes/sec) bsd10# dd if=/root/513b of=/dev/da1 bs=1 dd: /dev/da1: Invalid argument 1+0 records in 0+0 records out 0 bytes transferred in 0.000159 secs (0 bytes/sec) >Fix: 3. after applying the patch: bsd10# ./dd if=/root/513b of=/dev/da1 dd: /root/513b: not a multiple of /dev/da1's sector size (512 bytes) 1+1 records in 1+0 records out 512 bytes transferred in 0.003080 secs (166227 bytes/sec) bsd10# ./dd if=/root/513b of=/dev/da1 bs=1 dd: bs=1: not a multiple of /dev/da1's sector size (512 bytes) 1+0 records in 0+0 records out 0 bytes transferred in 0.000059 secs (0 bytes/sec) Patch attached with submission follows: --- dd.c.old 2013-12-21 21:07:38.000000000 +0800 +++ dd.c 2013-12-21 21:57:32.000000000 +0800 @@ -49,6 +49,7 @@ #include <sys/stat.h> #include <sys/conf.h> #include <sys/disklabel.h> +#include <sys/disk.h> #include <sys/filio.h> #include <sys/time.h> @@ -469,6 +470,17 @@ if (nw <= 0) { if (nw == 0) errx(1, "%s: end of device", out.name); + if (errno == EINVAL){ + size_t sectorsz = 0; + if (ioctl(out.fd, DIOCGSECTORSIZE , §orsz) == 0) { + if ( out.dbsz % sectorsz) + errx(1, "bs=%zu: not a multiple of %s's sector size (%zu bytes)", + out.dbsz, out.name, sectorsz); + else if (cnt < sectorsz) + errx(1, "%s: not a multiple of %s's sector size (%zu bytes)", + in.name, out.name, sectorsz); + } + } if (errno != EINTR) err(1, "%s", out.name); nw = 0; >Release-Note: >Audit-Trail: >Unformatted:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201312211437.rBLEbiJQ005537>