summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarel Zak <kzak@redhat.com>2007-05-30 17:57:30 +0200
committerKarel Zak <kzak@redhat.com>2007-05-31 15:02:13 +0200
commit121dba8508d67a17623329d4be5f8522757cca79 (patch)
tree2d4c3ea62124fa137f6c2b61ad4cc831973db931
parentbf8df99191b726332b5c2f361cac27fe2fa85df8 (diff)
downloadutil-linux-old-121dba8508d67a17623329d4be5f8522757cca79.tar.gz
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 <kzak@redhat.com>
-rw-r--r--fdisk/common.h7
-rw-r--r--fdisk/disksize.c33
-rw-r--r--fdisk/fdisk.c20
-rw-r--r--fdisk/sfdisk.c13
4 files changed, 39 insertions, 34 deletions
diff --git a/fdisk/common.h b/fdisk/common.h
index 7c1c3cd3..71eecc4e 100644
--- a/fdisk/common.h
+++ b/fdisk/common.h
@@ -1,3 +1,6 @@
+#ifndef FDISK_COMMON_H
+#define FDISK_COMMON_H
+
/* common stuff for fdisk, cfdisk, sfdisk */
/* including <linux/fs.h> fails */
@@ -19,7 +22,6 @@ struct hd_geometry {
#define HDIO_GETGEO 0x0301 /* get device geometry */
-
struct systypes {
unsigned char type;
char *name;
@@ -28,5 +30,8 @@ struct systypes {
extern struct systypes i386_sys_types[];
extern char *partname(char *dev, int pno, int lth);
+extern int is_probably_full_disk(char *name);
int disksize(int fd, unsigned long long *sectors);
+
+#endif /* FDISK_COMMON_H */
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 <stdio.h>
+#include <ctype.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
#include <errno.h>
#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]);
+}
+
diff --git a/fdisk/fdisk.c b/fdisk/fdisk.c
index abc0e110..c4f6458c 100644
--- a/fdisk/fdisk.c
+++ b/fdisk/fdisk.c
@@ -786,26 +786,6 @@ get_kernel_geometry(int fd) {
#endif
}
-static 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);
- }
- return (fd >= 0 && i == 0 && geometry.start == 0);
-#else
- /* silly heuristic */
- while (*name)
- name++;
- return !isdigit(name[-1]);
-#endif
-}
-
static void
get_partition_table_geometry(void) {
unsigned char *bufp = MBRbuffer;
diff --git a/fdisk/sfdisk.c b/fdisk/sfdisk.c
index 6e9e5697..d2155357 100644
--- a/fdisk/sfdisk.c
+++ b/fdisk/sfdisk.c
@@ -2411,19 +2411,6 @@ is_ide_cdrom_or_tape(char *device) {
return is_ide;
}
-static int
-is_probably_full_disk(char *name) {
- struct hd_geometry geometry;
- int fd, i = 0;
-
- fd = open(name, O_RDONLY);
- if (fd >= 0) {
- i = ioctl(fd, HDIO_GETGEO, &geometry);
- close(fd);
- }
- return (fd >= 0 && i == 0 && geometry.start == 0);
-}
-
#define PROC_PARTITIONS "/proc/partitions"
static FILE *procf = NULL;