Util-Linux package development
 help / color / mirror / Atom feed
From: Davidlohr Bueso <dave@gnu.org>
To: Karel Zak <kzak@redhat.com>
Cc: util-linux <util-linux@vger.kernel.org>
Subject: [PATCH] blkdev: add blkdev_get_physector_size()
Date: Mon, 20 Jun 2011 22:58:24 -0400	[thread overview]
Message-ID: <1308625104.3690.1.camel@offworld> (raw)

From: Davidlohr Bueso <dave@gnu.org>
Date: Mon, 20 Jun 2011 22:51:47 -0400

This function uses the BLKPBSZGET ioctl to get the physical block size of the device.

Signed-off-by: Davidlohr Bueso <dave@gnu.org>
---
 include/blkdev.h |    3 +++
 lib/blkdev.c     |   14 ++++++++++++++
 2 files changed, 17 insertions(+), 0 deletions(-)

diff --git a/include/blkdev.h b/include/blkdev.h
index 6a64172..0024897 100644
--- a/include/blkdev.h
+++ b/include/blkdev.h
@@ -95,4 +95,7 @@ int blkdev_get_sector_size(int fd, int *sector_size);
 /* specifies whether or not the device is misaligned */
 int blkdev_is_misaligned(int fd);
 
+/* get physical block device size */
+int blkdev_get_physector_size(int fd);
+
 #endif /* BLKDEV_H */
diff --git a/lib/blkdev.c b/lib/blkdev.c
index 5cb6554..94df803 100644
--- a/lib/blkdev.c
+++ b/lib/blkdev.c
@@ -221,6 +221,20 @@ int blkdev_is_misaligned(int fd)
 #endif
 }
 
+/* get physical block device size */
+int blkdev_get_physector_size(int fd)
+{
+#ifdef BLKPBSZGET
+	int bsz;
+
+	if (ioctl(fd, BLKPBSZGET, &bsz) < 0)
+		return 0;
+	return bsz;
+#else
+	return 0;
+#endif
+}
+
 #ifdef TEST_PROGRAM
 #include <stdio.h>
 #include <stdlib.h>
-- 
1.7.5.4

             reply	other threads:[~2011-06-21  2:58 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-21  2:58 Davidlohr Bueso [this message]
2011-06-27 14:22 ` [PATCH] blkdev: add blkdev_get_physector_size() 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=1308625104.3690.1.camel@offworld \
    --to=dave@gnu.org \
    --cc=kzak@redhat.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