All of lore.kernel.org
 help / color / mirror / Atom feed
From: Venkatraman S <venkat@linaro.org>
To: <kzak@redhat.com>
Cc: <util-linux@vger.kernel.org>, <arnd.bergmann@linaro.org>,
	Venkatraman S <venkat@linaro.org>
Subject: [RFC PATCH 2/4] mkswap: refactor header preparation
Date: Mon, 22 Oct 2012 22:27:25 +0530	[thread overview]
Message-ID: <1350925048-31084-3-git-send-email-venkat@linaro.org> (raw)
In-Reply-To: <1350925048-31084-1-git-send-email-venkat@linaro.org>

Move opencoded swap header populating code to a separate
function. No functional changes.

Signed-off-by: Venkatraman S <venkat@linaro.org>
---
 disk-utils/mkswap.c | 42 +++++++++++++++++++++++++++---------------
 1 file changed, 27 insertions(+), 15 deletions(-)

diff --git a/disk-utils/mkswap.c b/disk-utils/mkswap.c
index 0144921..f090121 100644
--- a/disk-utils/mkswap.c
+++ b/disk-utils/mkswap.c
@@ -75,6 +75,8 @@ static unsigned long badpages = 0;
 static int check = 0;
 
 #define SELINUX_SWAPFILE_TYPE	"swapfile_t"
+#define MAX_BADPAGES	((pagesize-1024-128*sizeof(int)-10)/sizeof(int))
+#define MIN_GOODPAGES	10
 
 #ifdef __sparc__
 # ifdef __arch64__
@@ -271,8 +273,6 @@ It is roughly 2GB on i386, PPC, m68k, ARM, 1GB on sparc, 512MB on mips,
 128GB on alpha and 3TB on sparc64.
 */
 
-#define MAX_BADPAGES	((pagesize-1024-128*sizeof(int)-10)/sizeof(int))
-#define MIN_GOODPAGES	10
 
 static void __attribute__ ((__noreturn__)) usage(FILE *out)
 {
@@ -362,6 +362,29 @@ new_prober(int fd)
 }
 #endif
 
+static void prepare_header(struct swap_header_v1_2 *hdr,
+	unsigned char *uuid, char *volume_name)
+{
+	unsigned long long goodpages;
+
+	hdr->version = 1;
+	hdr->last_page = PAGES - 1;
+	hdr->nr_badpages = badpages;
+
+	if (badpages > PAGES - MIN_GOODPAGES)
+		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);
+
+	write_signature("SWAPSPACE2");
+	write_uuid_and_label(uuid, volume_name);
+
+}
+
+
+
 static void
 wipe_device(int fd, const char *devname, int force)
 {
@@ -441,7 +464,7 @@ main(int argc, char **argv) {
 	struct swap_header_v1_2 *hdr;
 	int c;
 	unsigned long long maxpages;
-	unsigned long long goodpages;
+
 	unsigned long long sz;
 	off_t offset;
 	int force = 0;
@@ -599,19 +622,8 @@ main(int argc, char **argv) {
 	wipe_device(DEV, device_name, force);
 
 	hdr = (struct swap_header_v1_2 *) signature_page;
-	hdr->version = 1;
-	hdr->last_page = PAGES - 1;
-	hdr->nr_badpages = badpages;
 
-	if (badpages > PAGES - MIN_GOODPAGES)
-		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);
-
-	write_signature("SWAPSPACE2");
-	write_uuid_and_label(uuid, opt_label);
+	prepare_header(hdr, uuid, opt_label);
 
 	offset = 1024;
 	if (lseek(DEV, offset, SEEK_SET) != offset)
-- 
1.7.11.1.25.g0e18bef


  parent reply	other threads:[~2012-10-22 16:58 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-22 16:57 [RFC PATCH 0/4] Adding useful information into swap partition header Venkatraman S
2012-10-22 16:57 ` [RFC PATCH 1/4] libblkid/topology: add preferred_erase_size to topology probe Venkatraman S
2012-10-22 16:57 ` Venkatraman S [this message]
2012-10-22 16:57 ` [RFC PATCH 3/4] mkswap: Add additional fields in swapheader Venkatraman S
2012-10-22 16:57 ` [PATCH 4/4] mkswap: Probe and embed useful block device info into swapheader Venkatraman S
2012-10-22 17:04 ` [RFC PATCH 0/4] Adding useful information into swap partition header Venkatraman S
2012-10-23 12:16 ` Karel Zak
2012-10-23 13:37   ` Venkatraman S
2012-11-08  9:44     ` 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=1350925048-31084-3-git-send-email-venkat@linaro.org \
    --to=venkat@linaro.org \
    --cc=arnd.bergmann@linaro.org \
    --cc=kzak@redhat.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.