diff options
author | Phillip Susi | 2013-11-01 18:37:05 +0100 |
---|---|---|
committer | Karel Zak | 2013-11-04 15:09:18 +0100 |
commit | 569d1dac7bc64457aac11163b6a91ce9b41a6715 (patch) | |
tree | a055e2cd912296c3fbcaea6c54b0cd757465fcd2 /disk-utils/blockdev.c | |
parent | blkdiscard: BLKSSZGET fills in an int, not a uint64 (diff) | |
download | kernel-qcow2-util-linux-569d1dac7bc64457aac11163b6a91ce9b41a6715.tar.gz kernel-qcow2-util-linux-569d1dac7bc64457aac11163b6a91ce9b41a6715.tar.xz kernel-qcow2-util-linux-569d1dac7bc64457aac11163b6a91ce9b41a6715.zip |
blockdev: don't use HDIO_GETGEO
blockdev was still using this depreciated ioctl and that was
causing blockdev --report to fail on loop and nbd devices.
Switch to reading the partition start from sysfs instead.
This also allows it to correctly report > 2^32 sector counts.
[kzak@redhat.com: - check sysfs_init() return,
- use uint64_t rather than unsigned long long]
Signed-off-by: Phillip Susi <psusi@ubuntu.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'disk-utils/blockdev.c')
-rw-r--r-- | disk-utils/blockdev.c | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/disk-utils/blockdev.c b/disk-utils/blockdev.c index d030217d7..efaa0ead2 100644 --- a/disk-utils/blockdev.c +++ b/disk-utils/blockdev.c @@ -16,6 +16,7 @@ #include "blkdev.h" #include "pathnames.h" #include "closestream.h" +#include "sysfs.h" struct bdc { long ioc; /* ioctl code */ @@ -436,7 +437,9 @@ static void report_device(char *device, int quiet) 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) { @@ -446,15 +449,22 @@ static void report_device(char *device, int quiet) } 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); |