diff options
author | Karel Zak | 2011-11-11 13:33:51 +0100 |
---|---|---|
committer | Karel Zak | 2011-11-11 13:33:51 +0100 |
commit | 979f1dd5fe8cc27ade759af4a6e6abb6cfa45767 (patch) | |
tree | 10de87d53b7aeff8fac187dc42080eed9797302e /disk-utils/mkswap.c | |
parent | docs: update TODO file (diff) | |
download | kernel-qcow2-util-linux-979f1dd5fe8cc27ade759af4a6e6abb6cfa45767.tar.gz kernel-qcow2-util-linux-979f1dd5fe8cc27ade759af4a6e6abb6cfa45767.tar.xz kernel-qcow2-util-linux-979f1dd5fe8cc27ade759af4a6e6abb6cfa45767.zip |
mkswap: wipe all old signatures
mkswap(8) zaps the begin of the device (1024 bytes) only. This is not
enough, because for example ReiserFS superblock is outside this area.
This patch add blkid_do_wipe() call to mkswap(8) and all block device
is scanned and all signature are removed.
Reported-by: Martin Pitt <martin.pitt@ubuntu.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'disk-utils/mkswap.c')
-rw-r--r-- | disk-utils/mkswap.c | 67 |
1 files changed, 47 insertions, 20 deletions
diff --git a/disk-utils/mkswap.c b/disk-utils/mkswap.c index ab16d130b..5c2869772 100644 --- a/disk-utils/mkswap.c +++ b/disk-utils/mkswap.c @@ -370,12 +370,26 @@ check_mount(void) return 1; } +#ifdef HAVE_LIBBLKID +static blkid_probe +new_prober(int fd) +{ + blkid_probe pr = blkid_new_probe(); + if (!pr) + errx(EXIT_FAILURE, _("unable to alloc new libblkid probe")); + if (blkid_probe_set_device(pr, fd, 0, 0)) + errx(EXIT_FAILURE, _("unable to assign device to libblkid probe")); + return pr; +} +#endif + static void -zap_bootbits(int fd, const char *devname, int force, int is_blkdev) +wipe_device(int fd, const char *devname, int force, int is_blkdev) { char *type = NULL; int whole = 0; int zap = 1; + blkid_probe pr = NULL; if (!force) { if (lseek(fd, 0, SEEK_SET) != 0) @@ -388,12 +402,7 @@ zap_bootbits(int fd, const char *devname, int force, int is_blkdev) zap = 0; } else { #ifdef HAVE_LIBBLKID - blkid_probe pr = blkid_new_probe(); - if (!pr) - errx(EXIT_FAILURE, _("unable to alloc new libblkid probe")); - if (blkid_probe_set_device(pr, fd, 0, 0)) - errx(EXIT_FAILURE, _("unable to assign device to libblkid probe")); - + pr = new_prober(fd); blkid_probe_enable_partitions(pr, 1); blkid_probe_enable_superblocks(pr, 0); @@ -404,7 +413,6 @@ zap_bootbits(int fd, const char *devname, int force, int is_blkdev) type = xstrdup(type); zap = 0; } - blkid_free_probe(pr); #else /* don't zap if compiled without libblkid */ zap = 0; @@ -413,6 +421,9 @@ zap_bootbits(int fd, const char *devname, int force, int is_blkdev) } if (zap) { + /* + * Wipe boodbits + */ char buf[1024]; if (lseek(fd, 0, SEEK_SET) != 0) @@ -421,18 +432,34 @@ zap_bootbits(int fd, const char *devname, int force, int is_blkdev) memset(buf, 0, sizeof(buf)); if (write_all(fd, buf, sizeof(buf))) errx(EXIT_FAILURE, _("unable to erase bootbits sectors")); - return; +#ifdef HAVE_LIBBLKID + /* + * Wipe rest of the device + */ + if (!pr) + pr = new_prober(fd); + + blkid_probe_enable_superblocks(pr, 1); + blkid_probe_enable_partitions(pr, 0); + blkid_probe_set_superblocks_flags(pr, BLKID_SUBLKS_MAGIC); + + while (blkid_do_probe(pr) == 0) + blkid_do_wipe(pr, 0); +#endif + } else { + warnx(_("%s: warning: don't erase bootbits sectors"), + devname); + if (type) + fprintf(stderr, _(" (%s partition table detected). "), type); + else if (whole) + fprintf(stderr, _(" on whole disk. ")); + else + fprintf(stderr, _(" (compiled without libblkid). ")); + fprintf(stderr, "Use -f to force.\n"); } - - warnx(_("%s: warning: don't erase bootbits sectors"), - devname); - if (type) - fprintf(stderr, _(" (%s partition table detected). "), type); - else if (whole) - fprintf(stderr, _(" on whole disk. ")); - else - fprintf(stderr, _(" (compiled without libblkid). ")); - fprintf(stderr, "Use -f to force.\n"); +#ifdef HAVE_LIBBLKID + blkid_free_probe(pr); +#endif } int @@ -605,7 +632,7 @@ main(int argc, char **argv) { if (check) check_blocks(); - zap_bootbits(DEV, device_name, force, S_ISBLK(statbuf.st_mode)); + wipe_device(DEV, device_name, force, S_ISBLK(statbuf.st_mode)); hdr = (struct swap_header_v1_2 *) signature_page; hdr->version = 1; |