public inbox for util-linux@vger.kernel.org
 help / color / mirror / Atom feed
From: Sami Kerola <kerolasa@iki.fi>
To: util-linux@vger.kernel.org
Cc: kerolasa@iki.fi
Subject: [PATCH 05/12] mkswap, swaplabel: move version number to header
Date: Sun, 27 Apr 2014 21:05:31 +0100	[thread overview]
Message-ID: <1398629138-31718-6-git-send-email-kerolasa@iki.fi> (raw)
In-Reply-To: <1398629138-31718-1-git-send-email-kerolasa@iki.fi>

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    | 10 +++++-----
 disk-utils/swaplabel.c |  4 ++--
 include/swapheader.h   |  1 +
 sys-utils/swapon.c     | 10 ++++------
 4 files changed, 12 insertions(+), 13 deletions(-)

diff --git a/disk-utils/mkswap.c b/disk-utils/mkswap.c
index ae73f80..cd96ad5 100644
--- a/disk-utils/mkswap.c
+++ b/disk-utils/mkswap.c
@@ -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);
diff --git a/disk-utils/swaplabel.c b/disk-utils/swaplabel.c
index 5d048aa..8d5b260 100644
--- a/disk-utils/swaplabel.c
+++ b/disk-utils/swaplabel.c
@@ -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
diff --git a/include/swapheader.h b/include/swapheader.h
index 42d521a..80fa36b 100644
--- a/include/swapheader.h
+++ b/include/swapheader.h
@@ -11,6 +11,7 @@ struct swap_header_v1 {
 };
 
 
+#define SWAP_VERSION 1
 #define SWAP_UUID_LENGTH 16
 #define SWAP_LABEL_LENGTH 16
 
diff --git a/sys-utils/swapon.c b/sys-utils/swapon.c
index 3866ee7..6c422ce 100644
--- a/sys-utils/swapon.c
+++ b/sys-utils/swapon.c
@@ -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,
-- 
1.9.2


  parent reply	other threads:[~2014-04-27 20:06 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-04-27 20:05 [PATCH 00/12] pull: mostly swap command clarifications Sami Kerola
2014-04-27 20:05 ` [PATCH 01/12] include/xalloc: ensure arithmetics overflow cannot happen Sami Kerola
2014-04-27 20:45   ` Bernhard Voelker
2014-04-28  6:52   ` Karel Zak
2014-04-28  8:42     ` Sami Kerola
2014-04-27 20:05 ` [PATCH 02/12] dmesg: move get_boot_time() to lib/timeutils Sami Kerola
2014-05-06 10:00   ` Ruediger Meier
2014-05-06 11:20     ` Karel Zak
2014-05-06 13:42       ` Ruediger Meier
2014-05-06 14:40         ` Karel Zak
2014-05-06 16:03           ` Ruediger Meier
2014-05-07  9:52             ` Karel Zak
2014-05-07 14:04               ` Ruediger Meier
2014-04-27 20:05 ` [PATCH 03/12] last: fix is_phantom() detection Sami Kerola
2014-04-27 20:05 ` [PATCH 04/12] include/c.h: add macro to print definitions as string Sami Kerola
2014-04-27 20:05 ` Sami Kerola [this message]
2014-04-27 20:05 ` [PATCH 06/12] mkswap: remove legacy swap structure Sami Kerola
2014-04-27 20:05 ` [PATCH 07/12] include/swapheader.h: ensure type sizes Sami Kerola
2014-04-27 20:05 ` [PATCH 08/12] swapon: swaps with legacy version label are not supported Sami Kerola
2014-04-28  8:37   ` Benno Schulenberg
2014-04-28  8:44     ` Sami Kerola
2014-04-28  9:00       ` Karel Zak
2014-04-27 20:05 ` [PATCH 09/12] swapon, swapheader, mkswap: move swap signature to header Sami Kerola
2014-04-27 20:05 ` [PATCH 10/12] libsmartcols: remove ununsed assignment Sami Kerola
2014-04-28  9:02   ` Karel Zak
2014-04-27 20:05 ` [PATCH 11/12] lib/timeutils: fix memory leak Sami Kerola
2014-04-27 20:05 ` [PATCH 12/12] lib/pager: use names when referring to standard file descriptors Sami Kerola
2014-04-29 21:05 ` [PATCH 00/12] pull: mostly swap command clarifications Sami Kerola
2014-04-29 21:46   ` Bernhard Voelker
2014-05-06  8:36 ` Karel Zak

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1398629138-31718-6-git-send-email-kerolasa@iki.fi \
    --to=kerolasa@iki.fi \
    --cc=util-linux@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox