summaryrefslogtreecommitdiffstats
path: root/libblkid/wholedisk.c
diff options
context:
space:
mode:
authorbigbiff bigbiff <bigbiff@teamw.in>2013-02-23 02:55:50 +0100
committerbigbiff bigbiff <bigbiff@teamw.in>2013-02-25 15:06:46 +0100
commite60683a0d553b6488c564863f4e48954944fb0f8 (patch)
tree9364f97cb88b7c1359f5f06dfb32150a78168c31 /libblkid/wholedisk.c
parentFix building of updater for 4.2 environment (diff)
downloadandroid_bootable_recovery-e60683a0d553b6488c564863f4e48954944fb0f8.tar
android_bootable_recovery-e60683a0d553b6488c564863f4e48954944fb0f8.tar.gz
android_bootable_recovery-e60683a0d553b6488c564863f4e48954944fb0f8.tar.bz2
android_bootable_recovery-e60683a0d553b6488c564863f4e48954944fb0f8.tar.lz
android_bootable_recovery-e60683a0d553b6488c564863f4e48954944fb0f8.tar.xz
android_bootable_recovery-e60683a0d553b6488c564863f4e48954944fb0f8.tar.zst
android_bootable_recovery-e60683a0d553b6488c564863f4e48954944fb0f8.zip
Diffstat (limited to 'libblkid/wholedisk.c')
-rw-r--r--libblkid/wholedisk.c62
1 files changed, 62 insertions, 0 deletions
diff --git a/libblkid/wholedisk.c b/libblkid/wholedisk.c
new file mode 100644
index 000000000..1dbb90c5c
--- /dev/null
+++ b/libblkid/wholedisk.c
@@ -0,0 +1,62 @@
+/*
+ * No copyright is claimed. This code is in the public domain; do with
+ * it what you wish.
+ *
+ * Written by Karel Zak <kzak@redhat.com>
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <ctype.h>
+
+#include "blkdev.h"
+#include "wholedisk.h"
+
+int is_whole_disk_fd(int fd, const char *name)
+{
+#ifdef HDIO_GETGEO
+ if (fd != -1) {
+ struct hd_geometry geometry;
+ int i = ioctl(fd, HDIO_GETGEO, &geometry);
+ if (i == 0)
+ return 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]);
+}
+
+int is_whole_disk(const char *name)
+{
+ int fd = -1, res = 0;
+#ifdef HDIO_GETGEO
+ fd = open(name, O_RDONLY);
+ if (fd != -1)
+#endif
+ res = is_whole_disk_fd(fd, name);
+
+ if (fd != -1)
+ close(fd);
+ return res;
+}
+
+#ifdef TEST_PROGRAM
+int main(int argc, char **argv)
+{
+ if (argc < 2) {
+ fprintf(stderr, "usage: %s <device>\n", argv[0]);
+ exit(EXIT_FAILURE);
+ }
+
+ printf("%s: is%s whole disk\n", argv[1],
+ is_whole_disk(argv[1]) ? "" : " NOT");
+ exit(EXIT_SUCCESS);
+}
+#endif