lib: wholedisk - extend API, add test program
Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
parent
17c0248447
commit
dfbc185e53
|
@ -2,6 +2,7 @@
|
||||||
#define WHOLEDISK_H
|
#define WHOLEDISK_H
|
||||||
|
|
||||||
extern int is_whole_disk(const char *name);
|
extern int is_whole_disk(const char *name);
|
||||||
|
extern int is_whole_disk_fd(int fd, const char *name);
|
||||||
|
|
||||||
#endif /* WHOLEDISK_H */
|
#endif /* WHOLEDISK_H */
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1 @@
|
||||||
test_blkdev
|
test_*
|
||||||
test_ismounted
|
|
||||||
test_pttype
|
|
||||||
|
|
|
@ -1,16 +1,15 @@
|
||||||
include $(top_srcdir)/config/include-Makefile.am
|
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_blkdev_SOURCES = blkdev.c
|
||||||
test_ismounted_SOURCES = ismounted.c
|
test_ismounted_SOURCES = ismounted.c
|
||||||
test_pttype_SOURCES = pttype.c
|
test_pttype_SOURCES = pttype.c
|
||||||
|
test_wholedisk_SOURCES = wholedisk.c
|
||||||
|
|
||||||
if LINUX
|
if LINUX
|
||||||
test_blkdev_SOURCES += linux_version.c
|
test_blkdev_SOURCES += linux_version.c
|
||||||
endif
|
endif
|
||||||
|
|
||||||
test_blkdev_CFLAGS = -DTEST_PROGRAM
|
|
||||||
test_ismounted_CFLAGS = -DTEST_PROGRAM
|
|
||||||
test_pttype_CFLAGS = -DTEST_PROGRAM
|
|
||||||
|
|
||||||
|
|
|
@ -1,22 +1,21 @@
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
#include "blkdev.h"
|
#include "blkdev.h"
|
||||||
#include "wholedisk.h"
|
#include "wholedisk.h"
|
||||||
|
|
||||||
int is_whole_disk(const char *name)
|
int is_whole_disk_fd(int fd, const char *name)
|
||||||
{
|
{
|
||||||
#ifdef HDIO_GETGEO
|
#ifdef HDIO_GETGEO
|
||||||
struct hd_geometry geometry;
|
struct hd_geometry geometry;
|
||||||
int fd, i = 0;
|
int i = 0;
|
||||||
|
|
||||||
fd = open(name, O_RDONLY);
|
if (fd != -1)
|
||||||
if (fd >= 0) {
|
|
||||||
i = ioctl(fd, HDIO_GETGEO, &geometry);
|
i = ioctl(fd, HDIO_GETGEO, &geometry);
|
||||||
close(fd);
|
if (i == 0)
|
||||||
}
|
return geometry.start == 0;
|
||||||
if (i==0)
|
|
||||||
return (fd >= 0 && geometry.start == 0);
|
|
||||||
#endif
|
#endif
|
||||||
/*
|
/*
|
||||||
* The "silly heuristic" is still sexy for us, because
|
* The "silly heuristic" is still sexy for us, because
|
||||||
|
@ -29,3 +28,31 @@ int is_whole_disk(const char *name)
|
||||||
name++;
|
name++;
|
||||||
return !isdigit(name[-1]);
|
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
|
||||||
|
|
Loading…
Reference in New Issue