include $(top_srcdir)/config/include-Makefile.am
-noinst_PROGRAMS = test_blkdev test_ismounted test_pttype
+AM_CPPFLAGS += -DTEST_PROGRAM
+
+noinst_PROGRAMS = test_blkdev test_ismounted test_pttype test_wholedisk
test_blkdev_SOURCES = blkdev.c
test_ismounted_SOURCES = ismounted.c
test_pttype_SOURCES = pttype.c
+test_wholedisk_SOURCES = wholedisk.c
if LINUX
test_blkdev_SOURCES += linux_version.c
endif
-test_blkdev_CFLAGS = -DTEST_PROGRAM
-test_ismounted_CFLAGS = -DTEST_PROGRAM
-test_pttype_CFLAGS = -DTEST_PROGRAM
-
+#include <stdio.h>
+#include <stdlib.h>
#include <ctype.h>
#include "blkdev.h"
#include "wholedisk.h"
-int is_whole_disk(const char *name)
+int is_whole_disk_fd(int fd, const char *name)
{
#ifdef HDIO_GETGEO
struct hd_geometry geometry;
- int fd, i = 0;
+ int i = 0;
- fd = open(name, O_RDONLY);
- if (fd >= 0) {
+ if (fd != -1)
i = ioctl(fd, HDIO_GETGEO, &geometry);
- close(fd);
- }
- if (i==0)
- return (fd >= 0 && geometry.start == 0);
+ if (i == 0)
+ return geometry.start == 0;
#endif
/*
* The "silly heuristic" is still sexy for us, because
name++;
return !isdigit(name[-1]);
}
+
+int is_whole_disk(const char *name)
+{
+ int fd = -1, res = 0;
+#ifdef HDIO_GETGEO
+ fd = open(name, O_RDONLY);
+ if (fd != -1)
+#endif
+ res = is_whole_disk_fd(fd, name);
+
+ if (fd != -1)
+ close(fd);
+ return res;
+}
+
+#ifdef TEST_PROGRAM
+int main(int argc, char **argv)
+{
+ if (argc < 2) {
+ fprintf(stderr, "usage: %s <device>\n", argv[0]);
+ exit(EXIT_FAILURE);
+ }
+
+ printf("%s: is%s whole disk\n", argv[1],
+ is_whole_disk(argv[1]) ? "" : " NOT");
+ exit(EXIT_SUCCESS);
+}
+#endif