+#ifndef FDISK_COMMON_H
+#define FDISK_COMMON_H
+
/* common stuff for fdisk, cfdisk, sfdisk */
/* including <linux/fs.h> fails */
#define HDIO_GETGEO 0x0301 /* get device geometry */
-
struct systypes {
unsigned char type;
char *name;
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 */
+#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"
*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]);
+}
+
#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;
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;