summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--fdisk/Makefile.am2
-rw-r--r--fdisk/common.h1
-rw-r--r--fdisk/fdisk.c3
-rw-r--r--fdisk/partname.c29
-rw-r--r--fdisk/sfdisk.c4
-rw-r--r--include/blkdev.h2
-rw-r--r--include/wholedisk.h7
-rw-r--r--lib/wholedisk.c31
8 files changed, 46 insertions, 33 deletions
diff --git a/fdisk/Makefile.am b/fdisk/Makefile.am
index b3b5d7e9b..20906b52f 100644
--- a/fdisk/Makefile.am
+++ b/fdisk/Makefile.am
@@ -3,7 +3,7 @@ include $(top_srcdir)/config/include-Makefile.am
EXTRA_DIST = README.fdisk README.cfdisk sfdisk.examples partitiontype.c
fdisk_common = i386_sys_types.c common.h gpt.c gpt.h \
- ../lib/blkdev.c
+ ../lib/blkdev.c ../lib/wholedisk.c
if LINUX
fdisk_common += ../lib/linux_version.c
diff --git a/fdisk/common.h b/fdisk/common.h
index 674e65f4a..352b9a597 100644
--- a/fdisk/common.h
+++ b/fdisk/common.h
@@ -11,6 +11,5 @@ 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);
#endif /* FDISK_COMMON_H */
diff --git a/fdisk/fdisk.c b/fdisk/fdisk.c
index 5593503b9..e3b6857f8 100644
--- a/fdisk/fdisk.c
+++ b/fdisk/fdisk.c
@@ -26,6 +26,7 @@
#include "blkdev.h"
#include "common.h"
#include "fdisk.h"
+#include "wholedisk.h"
#include "fdisksunlabel.h"
#include "fdisksgilabel.h"
@@ -2568,7 +2569,7 @@ tryprocpt(void) {
&ma, &mi, &sz, ptname) != 4)
continue;
snprintf(devname, sizeof(devname), "/dev/%s", ptname);
- if (is_probably_full_disk(devname))
+ if (is_whole_disk(devname))
try(devname, 0);
}
fclose(procpt);
diff --git a/fdisk/partname.c b/fdisk/partname.c
index 889e7f0b2..1fe3087b4 100644
--- a/fdisk/partname.c
+++ b/fdisk/partname.c
@@ -1,9 +1,7 @@
#include <ctype.h>
#include <stdio.h>
#include <string.h>
-#include <sys/types.h>
-#include <fcntl.h>
-#include <unistd.h>
+
#include "blkdev.h"
#include "pathnames.h"
#include "common.h"
@@ -48,28 +46,3 @@ partname(char *dev, int pno, int lth) {
return bufp;
}
-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/sfdisk.c b/fdisk/sfdisk.c
index 533e729ac..2cda03ceb 100644
--- a/fdisk/sfdisk.c
+++ b/fdisk/sfdisk.c
@@ -50,7 +50,7 @@
#include "blkdev.h"
#include "linux_version.h"
#include "common.h"
-
+#include "wholedisk.h"
#include "gpt.h"
#define SIZE(a) (sizeof(a)/sizeof(a[0]))
@@ -2443,7 +2443,7 @@ nextproc(FILE *procf) {
&ma, &mi, &sz, ptname) != 4)
continue;
snprintf(devname, sizeof(devname), "/dev/%s", ptname);
- if (!is_probably_full_disk(devname))
+ if (!is_whole_disk(devname))
continue;
return devname;
}
diff --git a/include/blkdev.h b/include/blkdev.h
index 3cca79b94..9d9453bc7 100644
--- a/include/blkdev.h
+++ b/include/blkdev.h
@@ -3,6 +3,8 @@
#include <sys/types.h>
#include <sys/ioctl.h>
+#include <fcntl.h>
+#include <unistd.h>
#define DEFAULT_SECTOR_SIZE 512
diff --git a/include/wholedisk.h b/include/wholedisk.h
new file mode 100644
index 000000000..f367e4010
--- /dev/null
+++ b/include/wholedisk.h
@@ -0,0 +1,7 @@
+#ifndef WHOLEDISK_H
+#define WHOLEDISK_H
+
+extern int is_whole_disk(const char *name);
+
+#endif /* WHOLEDISK_H */
+
diff --git a/lib/wholedisk.c b/lib/wholedisk.c
new file mode 100644
index 000000000..eb6d432ce
--- /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]);
+}