diff -u util-linux-2.20.1/debian/changelog util-linux-2.20.1/debian/changelog --- util-linux-2.20.1/debian/changelog +++ util-linux-2.20.1/debian/changelog @@ -1,3 +1,10 @@ +util-linux (2.20.1-5.1ubuntu20.2) trusty; urgency=medium + + * Backport of 569d1dac to fix invalid ioctl when blockdev is called against + loopback devices. (LP: #1174098) + + -- Chris J Arges Mon, 22 Sep 2014 15:21:59 -0500 + util-linux (2.20.1-5.1ubuntu20.1) trusty-proposed; urgency=medium * fstrim-all: Fix typo that made unwanted stderr output from hdparm appear. only in patch2: unchanged: --- util-linux-2.20.1.orig/disk-utils/Makefile.am +++ util-linux-2.20.1/disk-utils/Makefile.am @@ -36,7 +36,7 @@ dist_man_MANS += fdformat.8 blockdev.8 sbin_PROGRAMS += blockdev usrsbin_exec_PROGRAMS += fdformat -blockdev_SOURCES = blockdev.c $(utils_common) +blockdev_SOURCES = blockdev.c $(top_srcdir)/lib/sysfs.c $(top_srcdir)/lib/at.c $(utils_common) endif if BUILD_LIBBLKID only in patch2: unchanged: --- util-linux-2.20.1.orig/disk-utils/blockdev.c +++ util-linux-2.20.1/disk-utils/blockdev.c @@ -15,6 +15,7 @@ #include "nls.h" #include "blkdev.h" #include "pathnames.h" +#include "sysfs.h" struct bdc { long ioc; /* ioctl code */ @@ -435,7 +436,9 @@ int ro, ssz, bsz; long ra; unsigned long long bytes; - struct hd_geometry g; + uint64_t start = 0; + struct sysfs_cxt cxt; + struct stat st; fd = open(device, O_RDONLY | O_NONBLOCK); if (fd < 0) { @@ -445,15 +448,22 @@ } ro = ssz = bsz = 0; - g.start = ra = 0; + ra = 0; + if (fstat(fd, &st) == 0) { + if (sysfs_init(&cxt, st.st_rdev, NULL)) + err(EXIT_FAILURE, + _("%s: failed to initialize sysfs handler"), + device); + sysfs_read_u64(&cxt, "start", &start); + sysfs_deinit(&cxt); + } if (ioctl(fd, BLKROGET, &ro) == 0 && ioctl(fd, BLKRAGET, &ra) == 0 && ioctl(fd, BLKSSZGET, &ssz) == 0 && ioctl(fd, BLKBSZGET, &bsz) == 0 && - ioctl(fd, HDIO_GETGEO, &g) == 0 && blkdev_get_size(fd, &bytes) == 0) { - printf("%s %5ld %5d %5d %10ld %15lld %s\n", - ro ? "ro" : "rw", ra, ssz, bsz, g.start, bytes, device); + printf("%s %5ld %5d %5d %10ju %15lld %s\n", + ro ? "ro" : "rw", ra, ssz, bsz, start, bytes, device); } else { if (!quiet) warnx(_("ioctl error on %s"), device);