summaryrefslogtreecommitdiff
path: root/lib/wholedisk.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/wholedisk.c')
-rw-r--r--lib/wholedisk.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/lib/wholedisk.c b/lib/wholedisk.c
new file mode 100644
index 00000000..eb6d432c
--- /dev/null
+++ b/lib/wholedisk.c
@@ -0,0 +1,31 @@
+
+#include <ctype.h>
+
+#include "blkdev.h"
+#include "wholedisk.h"
+
+int is_whole_disk(const char *name)
+{
+#ifdef HDIO_GETGEO
+ struct hd_geometry geometry;
+ int fd, i = 0;
+
+ fd = open(name, O_RDONLY);
+ if (fd >= 0) {
+ i = ioctl(fd, HDIO_GETGEO, &geometry);
+ close(fd);
+ }
+ if (i==0)
+ return (fd >= 0 && geometry.start == 0);
+#endif
+ /*
+ * The "silly heuristic" is still sexy for us, because
+ * for example Xen doesn't implement HDIO_GETGEO for virtual
+ * block devices (/dev/xvda).
+ *
+ * -- kzak@redhat.com (23-Feb-2006)
+ */
+ while (*name)
+ name++;
+ return !isdigit(name[-1]);
+}