diff options
author | Karel Zak | 2009-09-25 16:27:27 +0200 |
---|---|---|
committer | Karel Zak | 2009-09-29 13:30:36 +0200 |
commit | 566f35bc81d992bfec0a41485eea073854f54b0e (patch) | |
tree | b587b887fea8fae4c8b0dfa58cd1945062037b7a /disk-utils/mkswap.c | |
parent | docs: update TODO (diff) | |
download | kernel-qcow2-util-linux-566f35bc81d992bfec0a41485eea073854f54b0e.tar.gz kernel-qcow2-util-linux-566f35bc81d992bfec0a41485eea073854f54b0e.tar.xz kernel-qcow2-util-linux-566f35bc81d992bfec0a41485eea073854f54b0e.zip |
mkswap: use libblkid to detect PT
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'disk-utils/mkswap.c')
-rw-r--r-- | disk-utils/mkswap.c | 45 |
1 files changed, 36 insertions, 9 deletions
diff --git a/disk-utils/mkswap.c b/disk-utils/mkswap.c index 9feb2111d..1205acdb8 100644 --- a/disk-utils/mkswap.c +++ b/disk-utils/mkswap.c @@ -53,17 +53,20 @@ #include "nls.h" #include "blkdev.h" #include "pathnames.h" -#include "pttype.h" #include "wholedisk.h" #ifdef HAVE_LIBUUID # ifdef HAVE_UUID_UUID_H # include <uuid/uuid.h> -#else -# include <uuid.h> +# else +# include <uuid.h> # endif #endif +#ifdef HAVE_BLKID_PROBE_ENABLE_PARTITIONS +# include <blkid.h> +#endif + static char * program_name = "mkswap"; static char * device_name = NULL; static int DEV = -1; @@ -391,21 +394,43 @@ write_all(int fd, const void *buf, size_t count) { static void zap_bootbits(int fd, const char *devname, int force) { - const char *type = NULL; + char *type = NULL; + int whole = 0; int zap = 1; if (!force) { if (lseek(fd, 0, SEEK_SET) != 0) die(_("unable to rewind swap-device")); - if (is_whole_disk_fd(fd, devname)) + if (is_whole_disk_fd(fd, devname)) { /* don't zap bootbits on whole disk -- we know nothing * about bootloaders on the device */ + whole = 1; zap = 0; - - else if ((type = get_pt_type_fd(fd))) - /* don't zap partition table */ + } else { +#ifdef HAVE_BLKID_PROBE_ENABLE_PARTITIONS + blkid_probe pr = blkid_new_probe(); + if (!pr) + die(_("unable to alloc new libblkid probe")); + if (blkid_probe_set_device(pr, fd, 0, 0)) + die(_("unable to assign device to liblkid probe")); + + blkid_probe_enable_partitions(pr, 1); + blkid_probe_enable_superblocks(pr, 0); + + if (blkid_do_fullprobe(pr) == 0) + blkid_probe_lookup_value(pr, "PTTYPE", + (const char **) &type, NULL); + if (type) { + type = strdup(type); + zap = 0; + } + blkid_free_probe(pr); +#else + /* don't zap if compiled without libblkid */ zap = 0; +#endif + } } if (zap) { @@ -424,8 +449,10 @@ zap_bootbits(int fd, const char *devname, int force) program_name, devname); if (type) fprintf(stderr, _(" (%s partition table detected). "), type); - else + else if (whole) fprintf(stderr, _(" on whole disk. ")); + else + fprintf(stderr, _(" (compiled without libblkid). ")); fprintf(stderr, "Use -f to force.\n"); } |