Skip to contentSkip to conversation

blkdev: add is_blkdev function

PATCH Applied Davidlohr Bueso 2 participants 2 messages Jan 4, 2012 – Jan 5, 2012

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 blkdev: add is_blkdev function

From: Davidlohr Bueso <[email protected]>

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

---
 include/blkdev.h |    3 +++
 lib/blkdev.c     |    6 ++++++
 2 files changed, 9 insertions(+), 0 deletions(-)
include/blkdev.h +3 -0
index 1a9119d..6b18879 100644
@@ -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);
 
lib/blkdev.c +6 -0
index 9138b0d..c59386d 100644
@@ -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;
Signature · 1 line
1.7.4.1
maintainer Applied
#1 lore raw
Quoted 3 lines · Davidlohr Bueso
 include/blkdev.h |    3 +++
 lib/blkdev.c     |    6 ++++++
 2 files changed, 9 insertions(+), 0 deletions(-)

Applied, thanks.

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com