]> err.no Git - util-linux/commitdiff
lib: add is_whole_disk() from fdisk code
authorKarel Zak <kzak@redhat.com>
Wed, 11 Mar 2009 13:00:21 +0000 (14:00 +0100)
committerKarel Zak <kzak@redhat.com>
Wed, 11 Mar 2009 13:00:21 +0000 (14:00 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
fdisk/Makefile.am
fdisk/common.h
fdisk/fdisk.c
fdisk/partname.c
fdisk/sfdisk.c
include/blkdev.h
include/wholedisk.h [new file with mode: 0644]
lib/wholedisk.c [new file with mode: 0644]

index b3b5d7e9b09597b619c661220ba0b1994ee23393..20906b52fbf828d55c335a87e3fe42639e8e43da 100644 (file)
@@ -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
index 674e65f4a853c1ade4e11526e819f565f6517f69..352b9a597b58255ebd1ba836d4e1daa050a0b887 100644 (file)
@@ -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 */
index 5593503b97956060f1ae388662ff65900ead5ad3..e3b6857f82d5e9f2537c3a072b4927c4eddacb06 100644 (file)
@@ -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);
index 889e7f0b2940da84f8c307c6b9a5b8d025ecbcda..1fe3087b444ebf93098edc9b42b6985922422a3e 100644 (file)
@@ -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]);
-}
index 533e729ac2bfbffee21fb9f9efe1f41e100bd638..2cda03ceb9d225ae53e95c6f5b6dbbe3bce53fbb 100644 (file)
@@ -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;
        }
index 3cca79b941fdaf15c5cc7b8936741383327f88fd..9d9453bc7d60112436410dbc1d3690b5556f31cf 100644 (file)
@@ -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 (file)
index 0000000..f367e40
--- /dev/null
@@ -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 (file)
index 0000000..eb6d432
--- /dev/null
@@ -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]);
+}