However,
.B mkswap
refuses to erase the first block on a device with a disk
-label (SUN, BSD, ...) and on a whole disk (e.g. /dev/sda).
+label (SUN, BSD, ...).
.SH OPTIONS
.TP
Also, without this option,
.B mkswap
-will refuse to erase the first block on a device with a partition table and on
-a whole disk (e.g. /dev/sda).
+will refuse to erase the first block on a device with a partition table.
.TP
.BR \-L , " \-\-label " \fIlabel\fR
Specify a \fIlabel\fR for the device, to allow
#endif
static void
-wipe_device(int fd, const char *devname, int force, int is_blkdevice)
+wipe_device(int fd, const char *devname, int force)
{
char *type = NULL;
- int whole = 0;
int zap = 1;
#ifdef HAVE_LIBBLKID
blkid_probe pr = NULL;
if (lseek(fd, 0, SEEK_SET) != 0)
errx(EXIT_FAILURE, _("unable to rewind swap-device"));
- if (is_blkdevice && 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 {
#ifdef HAVE_LIBBLKID
- pr = new_prober(fd);
- 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) == 0 &&
- type) {
- type = xstrdup(type);
- zap = 0;
- }
-#else
- /* don't zap if compiled without libblkid */
+ pr = new_prober(fd);
+ 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) == 0 && type) {
+ type = xstrdup(type);
zap = 0;
-#endif
}
+#else
+ /* don't zap if compiled without libblkid */
+ zap = 0;
+#endif
}
if (zap) {
* Wipe boodbits
*/
char buf[1024];
+ const char *data = NULL;
if (lseek(fd, 0, SEEK_SET) != 0)
errx(EXIT_FAILURE, _("unable to rewind swap-device"));
blkid_probe_enable_superblocks(pr, 1);
blkid_probe_enable_partitions(pr, 0);
- blkid_probe_set_superblocks_flags(pr, BLKID_SUBLKS_MAGIC);
+ blkid_probe_set_superblocks_flags(pr, BLKID_SUBLKS_MAGIC|BLKID_SUBLKS_TYPE);
- while (blkid_do_probe(pr) == 0)
+ while (blkid_do_probe(pr) == 0) {
+ if (blkid_probe_lookup_value(pr, "TYPE", &data, NULL) == 0 && data)
+ warnx(_("%s: warning: wiping old %s signature."), devname, data);
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");
if (check)
check_blocks();
- wipe_device(DEV, device_name, force, S_ISBLK(statbuf.st_mode));
+ wipe_device(DEV, device_name, force);
hdr = (struct swap_header_v1_2 *) signature_page;
hdr->version = 1;