diff options
author | Sami Kerola | 2014-11-02 21:26:29 +0100 |
---|---|---|
committer | Karel Zak | 2014-11-07 13:21:06 +0100 |
commit | 6af18227525923e5f2c5dc32da996ec165607891 (patch) | |
tree | 479c0c5149b3ef49f2f4371b3bfb1e1a2aeed32d /disk-utils/mkswap.c | |
parent | mkswap: add struct mkswap_control to remove global variables (diff) | |
download | kernel-qcow2-util-linux-6af18227525923e5f2c5dc32da996ec165607891.tar.gz kernel-qcow2-util-linux-6af18227525923e5f2c5dc32da996ec165607891.tar.xz kernel-qcow2-util-linux-6af18227525923e5f2c5dc32da996ec165607891.zip |
mkswap: make remaining functions to take control structure as argument
The wipe_device() and new_prober().
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Diffstat (limited to 'disk-utils/mkswap.c')
-rw-r--r-- | disk-utils/mkswap.c | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/disk-utils/mkswap.c b/disk-utils/mkswap.c index 7f4142844..7f600137d 100644 --- a/disk-utils/mkswap.c +++ b/disk-utils/mkswap.c @@ -225,31 +225,31 @@ get_size(const struct mkswap_control *ctl) #ifdef HAVE_LIBBLKID static blkid_probe -new_prober(int fd) +new_prober(const struct mkswap_control *ctl) { 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)) + if (blkid_probe_set_device(pr, ctl->fd, 0, 0)) errx(EXIT_FAILURE, _("unable to assign device to libblkid probe")); return pr; } #endif static void -wipe_device(int fd, const char *devname, int force) +wipe_device(struct mkswap_control *ctl) { char *type = NULL; int zap = 1; #ifdef HAVE_LIBBLKID blkid_probe pr = NULL; #endif - if (!force) { - if (lseek(fd, 0, SEEK_SET) != 0) + if (!ctl->force) { + if (lseek(ctl->fd, 0, SEEK_SET) != 0) errx(EXIT_FAILURE, _("unable to rewind swap-device")); #ifdef HAVE_LIBBLKID - pr = new_prober(fd); + pr = new_prober(ctl); blkid_probe_enable_partitions(pr, 1); blkid_probe_enable_superblocks(pr, 0); @@ -271,18 +271,18 @@ wipe_device(int fd, const char *devname, int force) */ char buf[1024]; - if (lseek(fd, 0, SEEK_SET) != 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(fd, buf, sizeof(buf))) + if (write_all(ctl->fd, buf, sizeof(buf))) errx(EXIT_FAILURE, _("unable to erase bootbits sectors")); #ifdef HAVE_LIBBLKID /* * Wipe rest of the device */ if (!pr) - pr = new_prober(fd); + pr = new_prober(ctl); blkid_probe_enable_superblocks(pr, 1); blkid_probe_enable_partitions(pr, 0); @@ -292,13 +292,13 @@ wipe_device(int fd, const char *devname, int force) const char *data = NULL; if (blkid_probe_lookup_value(pr, "TYPE", &data, NULL) == 0 && data) - warnx(_("%s: warning: wiping old %s signature."), devname, data); + warnx(_("%s: warning: wiping old %s signature."), ctl->device_name, data); blkid_do_wipe(pr, 0); } #endif } else { warnx(_("%s: warning: don't erase bootbits sectors"), - devname); + ctl->device_name); if (type) fprintf(stderr, _(" (%s partition table detected). "), type); else @@ -450,7 +450,7 @@ main(int argc, char **argv) { if (ctl.check) check_blocks(&ctl); - wipe_device(ctl.fd, ctl.device_name, ctl.force); + wipe_device(&ctl); ctl.hdr = (struct swap_header_v1_2 *) ctl.signature_page; ctl.hdr->version = version; |