]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
mkswap, swaplabel: move version number to header
authorSami Kerola <kerolasa@iki.fi>
Fri, 25 Apr 2014 20:37:58 +0000 (21:37 +0100)
committerSami Kerola <kerolasa@iki.fi>
Sun, 4 May 2014 10:42:03 +0000 (11:42 +0100)
Corrently only the swap version 1 is supported, which is a magic value so
move it to header.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
disk-utils/mkswap.c
disk-utils/swaplabel.c
include/swapheader.h
sys-utils/swapon.c

index ae73f80a3acb9d234e23f011b5fd0aab10362d59..cd96ad575c2920c01f2a5821f0872be63d68ada1 100644 (file)
@@ -449,7 +449,7 @@ main(int argc, char **argv) {
        unsigned long long sz;
        off_t offset;
        int force = 0;
-       int version = 1;
+       int version = SWAP_VERSION;
        char *block_count = 0;
        char *opt_label = NULL;
        unsigned char *uuid = NULL;
@@ -517,7 +517,7 @@ main(int argc, char **argv) {
                usage(stderr);
        }
 
-       if (version != 1)
+       if (version != SWAP_VERSION)
                errx(EXIT_FAILURE,
                        _("swapspace version %d is not supported"), version);
 
@@ -601,7 +601,7 @@ main(int argc, char **argv) {
        wipe_device(DEV, device_name, force);
 
        hdr = (struct swap_header_v1_2 *) signature_page;
-       hdr->version = 1;
+       hdr->version = version;
        hdr->last_page = PAGES - 1;
        hdr->nr_badpages = badpages;
 
@@ -609,8 +609,8 @@ main(int argc, char **argv) {
                errx(EXIT_FAILURE, _("Unable to set up swap-space: unreadable"));
 
        goodpages = PAGES - badpages - 1;
-       printf(_("Setting up swapspace version 1, size = %llu KiB\n"),
-               goodpages * pagesize / 1024);
+       printf(_("Setting up swapspace version %d, size = %llu KiB\n"),
+               version, goodpages * pagesize / 1024);
 
        write_signature("SWAPSPACE2");
        write_uuid_and_label(uuid, opt_label);
index 5d048aabbe07b3de6f49568aabaa95b4d18b1008..8d5b260c595c6050c982083c9ac3ed4c519e529f 100644 (file)
@@ -67,10 +67,10 @@ static blkid_probe get_swap_prober(const char *devname)
                warnx(_("%s: not a valid swap partition"), devname);
 
        if (rc == 0) {
-               /* supported is SWAPSPACE2 only */
+               /* Only the SWAPSPACE2 is supported. */
                if (blkid_probe_lookup_value(pr, "VERSION", &version, NULL) == 0
                    && version
-                   && strcmp(version, "1"))
+                   && strcmp(version, stringify_value(SWAP_VERSION)))
                        warnx(_("%s: unsupported swap version '%s'"),
                                                devname, version);
                else
index 42d521a490e0ad094e8a088b4beb33fd26923f64..80fa36b88e5b5951a7abe79e1eea422595fb9d90 100644 (file)
@@ -11,6 +11,7 @@ struct swap_header_v1 {
 };
 
 
+#define SWAP_VERSION 1
 #define SWAP_UUID_LENGTH 16
 #define SWAP_LABEL_LENGTH 16
 
index 3866ee70dab2b8714c06af994ef4312aea43f44c..6c422ce41e7c2a38efd5870addda3dfd3a00f547 100644 (file)
@@ -402,21 +402,19 @@ static unsigned long long swap_get_size(const char *hdr, const char *devname,
                                        unsigned int pagesize)
 {
        unsigned int last_page = 0;
-       int swap_version = 0;
+       const unsigned int swap_version = SWAP_VERSION;
        int flip = 0;
        struct swap_header_v1_2 *s;
 
        s = (struct swap_header_v1_2 *) hdr;
-       if (s->version == 1) {
-               swap_version = 1;
+       if (s->version == swap_version) {
                last_page = s->last_page;
-       } else if (swab32(s->version) == 1) {
+       } else if (swab32(s->version) == swap_version) {
                flip = 1;
-               swap_version = 1;
                last_page = swab32(s->last_page);
        }
        if (verbose)
-               warnx(_("%s: found swap signature: version %d, "
+               warnx(_("%s: found swap signature: version %ud, "
                        "page-size %d, %s byte order"),
                        devname,
                        swap_version,