summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--disk-utils/Makefile.am2
-rw-r--r--disk-utils/mkswap.c45
2 files changed, 46 insertions, 1 deletions
diff --git a/disk-utils/Makefile.am b/disk-utils/Makefile.am
index 9e9db95be..4854d5f61 100644
--- a/disk-utils/Makefile.am
+++ b/disk-utils/Makefile.am
@@ -12,7 +12,7 @@ sbin_PROGRAMS = mkfs mkswap fsck.minix mkfs.minix mkfs.bfs
fsck_minix_SOURCES = fsck.minix.c minix.h
mkfs_minix_SOURCES = mkfs.minix.c minix.h $(utils_common)
mkfs_bfs_SOURCES = mkfs.bfs.c $(utils_common)
-mkswap_SOURCES = mkswap.c $(utils_common)
+mkswap_SOURCES = mkswap.c $(utils_common) ../lib/wholedisk.c ../lib/pttype.c
usrbinexec_PROGRAMS = isosize
usrsbinexec_PROGRAMS =
diff --git a/disk-utils/mkswap.c b/disk-utils/mkswap.c
index 6e151af38..4acc73b23 100644
--- a/disk-utils/mkswap.c
+++ b/disk-utils/mkswap.c
@@ -53,6 +53,8 @@
#include "nls.h"
#include "blkdev.h"
#include "pathnames.h"
+#include "pttype.h"
+#include "wholedisk.h"
#ifdef HAVE_LIBUUID
#include <uuid/uuid.h>
@@ -379,6 +381,47 @@ write_all(int fd, const void *buf, size_t count) {
return 0;
}
+static void
+zap_bootbits(int fd, const char *devname, int force)
+{
+ const char *type = NULL;
+ 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))
+ /* don't zap bootbits on whole disk -- we know nothing
+ * about bootloaders on the device */
+ zap = 0;
+
+ else if ((type = get_pt_type_fd(fd)))
+ /* don't zap partition table */
+ zap = 0;
+ }
+
+ if (zap) {
+ char buf[1024];
+
+ if (lseek(fd, 0, SEEK_SET) != 0)
+ die(_("unable to rewind swap-device"));
+
+ memset(buf, 0, sizeof(buf));
+ if (write_all(fd, buf, sizeof(buf)))
+ die(_("unable to erase bootbits sectors"));
+ return;
+ }
+
+ fprintf(stderr, _("%s: %s: warning: don't erase bootbits sectors\n"),
+ program_name, devname);
+ if (type)
+ fprintf(stderr, _(" (%s partition table detected). "), type);
+ else
+ fprintf(stderr, _(" on whole disk. "));
+ fprintf(stderr, "Use -f to force.\n");
+}
+
int
main(int argc, char ** argv) {
struct stat statbuf;
@@ -561,6 +604,8 @@ main(int argc, char ** argv) {
if (check)
check_blocks();
+ zap_bootbits(DEV, device_name, force);
+
p->version = 1;
p->last_page = PAGES-1;
p->nr_badpages = badpages;