}
static void
-page_bad(struct mkswap_control *ctl, int page)
+page_bad(struct mkswap_control *ctl, unsigned int page)
{
struct swap_header_v1_2 *p = (struct swap_header_v1_2 *)ctl->signature_page;
const unsigned long max_badpages = (ctl->pagesize - 1024 - 128 * sizeof(int) - 10) / sizeof(int);
if (ctl->badpages == max_badpages)
- errx(EXIT_FAILURE, _("too many bad pages"));
+ errx(EXIT_FAILURE, _("too many bad pages: %lu"), max_badpages);
p->badpages[ctl->badpages] = page;
ctl->badpages++;
}
static void
check_blocks(struct mkswap_control *ctl)
{
- unsigned int current_page;
+ unsigned int current_page = 0;
int do_seek = 1;
char *buffer;
buffer = xmalloc(ctl->pagesize);
- current_page = 0;
while (current_page < ctl->nr_pages) {
ssize_t rc;
if (zap) {
/*
- * Wipe boodbits
+ * Wipe bootbits
*/
- char buf[1024];
+ char buf[1024] = { '\0' };
if (lseek(ctl->fd, 0, SEEK_SET) != 0)
errx(EXIT_FAILURE, _("unable to rewind swap-device"));
- memset(buf, 0, sizeof(buf));
if (write_all(ctl->fd, buf, sizeof(buf)))
errx(EXIT_FAILURE, _("unable to erase bootbits sectors"));
#ifdef HAVE_LIBBLKID
unsigned long long sz;
off_t offset;
int version = SWAP_VERSION;
- char *block_count = 0;
+ char *block_count = NULL;
#ifdef HAVE_LIBUUID
const char *opt_uuid = NULL;
uuid_t uuid_dat;
err(EXIT_FAILURE, _("stat failed %s"), ctl.device_name);
if (S_ISBLK(statbuf.st_mode))
ctl.fd = open(ctl.device_name, O_RDWR | O_EXCL);
- else
+ else {
+ if (ctl.check) {
+ ctl.check = 0;
+ warnx(_("warning: checking bad blocks from swap file is not supported: %s"),
+ ctl.device_name);
+ }
ctl.fd = open(ctl.device_name, O_RDWR);
+ }
if (ctl.fd < 0)
err(EXIT_FAILURE, _("cannot open %s"), ctl.device_name);
-
- if (!S_ISBLK(statbuf.st_mode))
- ctl.check = 0;
- else if (blkdev_is_misaligned(ctl.fd))
- warnx(_("warning: %s is misaligned"), ctl.device_name);
-
+ if (S_ISBLK(statbuf.st_mode))
+ if (blkdev_is_misaligned(ctl.fd))
+ warnx(_("warning: %s is misaligned"), ctl.device_name);
if (ctl.check)
check_blocks(&ctl);
err(EXIT_FAILURE,
_("%s: unable to write signature page"),
ctl.device_name);
-
+ free(ctl.signature_page);
#ifdef HAVE_LIBSELINUX
if (S_ISREG(statbuf.st_mode) && is_selinux_enabled() > 0) {
security_context_t context_string;