]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
blkdev: add is_blkdev function
authorDavidlohr Bueso <dave@gnu.org>
Wed, 4 Jan 2012 23:02:06 +0000 (00:02 +0100)
committerKarel Zak <kzak@redhat.com>
Thu, 5 Jan 2012 16:09:27 +0000 (17:09 +0100)
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
lib/blkdev.c

index 1a9119d43d9cda1abbbc8aae7b819eca21dc0ef9..6b18879761c3fef1ac924af12f93aa718ebb82f2 100644 (file)
@@ -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);
 
index 9138b0d854b82de0c61d7ee4bfe9845b1eabb904..c59386d9c33db7e5bbfa3c4f524b9bb9f6fd3828 100644 (file)
@@ -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;