From: Phillip Susi <psusi@ubuntu.com>
To: util-linux@vger.kernel.org
Subject: [PATCH] blockdev: don't use HDIO_GETGEO
Date: Fri, 1 Nov 2013 13:37:05 -0400 [thread overview]
Message-ID: <1383327425-2694-1-git-send-email-psusi@ubuntu.com> (raw)
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.
Signed-off-by: Phillip Susi <psusi@ubuntu.com>
---
disk-utils/blockdev.c | 17 ++++++++++++-----
1 file changed, 12 insertions(+), 5 deletions(-)
diff --git a/disk-utils/blockdev.c b/disk-utils/blockdev.c
index d030217..2ebe0e1 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;
+ unsigned long long start = 0;
+ struct sysfs_cxt cxt;
+ struct stat st;
fd = open(device, O_RDONLY | O_NONBLOCK);
if (fd < 0) {
@@ -446,15 +449,19 @@ static void report_device(char *device, int quiet)
}
ro = ssz = bsz = 0;
- g.start = ra = 0;
+ ra = 0;
+ if (fstat(fd, &st) == 0) {
+ sysfs_init(&cxt, st.st_rdev, NULL);
+ 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 %10lld %15lld %s\n",
+ ro ? "ro" : "rw", ra, ssz, bsz, start, bytes, device);
} else {
if (!quiet)
warnx(_("ioctl error on %s"), device);
--
1.8.1.2
next reply other threads:[~2013-11-01 17:44 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-01 17:37 Phillip Susi [this message]
2013-11-04 14:11 ` [PATCH] blockdev: don't use HDIO_GETGEO Karel Zak
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1383327425-2694-1-git-send-email-psusi@ubuntu.com \
--to=psusi@ubuntu.com \
--cc=util-linux@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox