util-linux.vger.kernel.org archive mirror
 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 1/2] blkdev: add is_blkdev function
Date: Thu, 05 Jan 2012 00:02:06 +0100	[thread overview]
Message-ID: <1325718126.7056.5.camel@offbook> (raw)

From: Davidlohr Bueso <dave@gnu.org>

We should have the most basic of checks in this library to see whether or not a block device is being used.

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

diff --git a/include/blkdev.h b/include/blkdev.h
index 1a9119d..6b18879 100644
--- a/include/blkdev.h
+++ b/include/blkdev.h
@@ -86,6 +86,9 @@ struct hd_geometry {
 };
 #endif
 
+/* are we working with block device? */
+int is_blkdev(int fd);
+
 /* Determine size in bytes */
 off_t blkdev_find_size (int fd);
 
diff --git a/lib/blkdev.c b/lib/blkdev.c
index 9138b0d..c59386d 100644
--- a/lib/blkdev.c
+++ b/lib/blkdev.c
@@ -35,6 +35,12 @@ blkdev_valid_offset (int fd, off_t offset) {
 	return 1;
 }
 
+int is_blkdev(int fd)
+{
+	struct stat st;
+	return (fstat(fd, &st) == 0 && S_ISBLK(st.st_mode));
+}
+
 off_t
 blkdev_find_size (int fd) {
 	uintmax_t high, low = 0;
-- 
1.7.4.1





         reply	other threads:[~2012-01-04 23:02 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-04 23:02 [PATCH 2/2] sfdisk: use is_blkdev Davidlohr Bueso
2012-01-04 23:02 ` Davidlohr Bueso [this message]
2012-01-04 22:28   ` [PATCH] lscpu: fix compiler warnings Davidlohr Bueso
     [not found]     ` <1324994959-24298-1-git-send-email-gaowanlong@cn.fujitsu.com>
2011-12-20 13:42       ` [PATCH 4/5] fdisk: remove packed definitions Davidlohr Bueso
2011-12-20 13:42         ` [PATCH 3/5] sfdisk: do not depend on arch for packed attribute Davidlohr Bueso
2012-01-05 16:29           ` Karel Zak
2011-12-22  2:33         ` [PATCH 4/5] fdisk: remove packed definitions Guillem Jover
2012-01-05 16:30     ` [PATCH] lscpu: fix compiler warnings Karel Zak
2012-01-05 16:31   ` [PATCH 1/2] blkdev: add is_blkdev function Karel Zak
2012-01-05 16:31 ` [PATCH 2/2] sfdisk: use is_blkdev 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=1325718126.7056.5.camel@offbook \
    --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;
as well as URLs for NNTP newsgroup(s).