--- dd.c 2013-12-21 21:07:38.000000000 +0800 +++ dd.c 2013-12-21 21:57:32.000000000 +0800 @@ -49,6 +49,7 @@ #include #include #include +#include #include #include @@ -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;