From 121dba8508d67a17623329d4be5f8522757cca79 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Wed, 30 May 2007 17:57:30 +0200 Subject: fdisk: cleanup full disk detection code The full disk (e.g. /dev/hda) detection code is duplicated on two places and the code doesn't work correctly with devices which don't support HDIO_GETGEO. Signed-off-by: Karel Zak --- fdisk/disksize.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'fdisk/disksize.c') diff --git a/fdisk/disksize.c b/fdisk/disksize.c index 28b8df0a..cc00e933 100644 --- a/fdisk/disksize.c +++ b/fdisk/disksize.c @@ -1,3 +1,9 @@ +#include +#include +#include +#include +#include +#include #include #include "common.h" @@ -19,3 +25,30 @@ int disksize(int fd, unsigned long long *sectors) { *sectors = (b >> 9); return 0; } + +int +is_probably_full_disk(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]); +} + -- cgit v1.2.3