summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavidlohr Bueso2012-01-05 00:02:06 +0100
committerKarel Zak2012-01-05 17:09:27 +0100
commit8150beac7ced4e35fef7a8db71caee72d455f180 (patch)
tree41625537369e230c3b40b8f62d9d8522ff51f171
parentfdisk: remove PACKED macro (diff)
downloadkernel-qcow2-util-linux-8150beac7ced4e35fef7a8db71caee72d455f180.tar.gz
kernel-qcow2-util-linux-8150beac7ced4e35fef7a8db71caee72d455f180.tar.xz
kernel-qcow2-util-linux-8150beac7ced4e35fef7a8db71caee72d455f180.zip
blkdev: add is_blkdev function
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>
-rw-r--r--include/blkdev.h3
-rw-r--r--lib/blkdev.c6
2 files changed, 9 insertions, 0 deletions
diff --git a/include/blkdev.h b/include/blkdev.h
index 1a9119d43..6b1887976 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 9138b0d85..c59386d9c 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;