Add an option to byteswap fields when writing v1 swap header. Useful for building a TiVo swap header on an i386. millert@courtesan.com --- util-linux-2.12/disk-utils/mkswap.c.DIST 2002-10-31 18:52:29.000000000 -0700 +++ util-linux-2.12/disk-utils/mkswap.c 2003-09-27 21:55:36.000000000 -0600 @@ -13,6 +13,7 @@ * -c for readability checking. (Use it unless you are SURE!) * -vN for swap areas version N. (Only N=0,1 known today.) * -f for forcing swap creation even if it would smash partition table. + * -S for doing byteswapping on int-length fields * * The device may be a block device or an image of one, but this isn't * enforced (but it's not much fun on a character device :-). @@ -26,7 +27,7 @@ * V1_MAX_PAGES fixes, jj, 990325. * sparc64 fixes, jj, 000219. * - * 1999-02-22 Arkadiusz Mi)B¶kiewicz + * 1999-02-22 Arkadiusz Mi)B¶kiewicz * - added Native Language Support * */ @@ -70,6 +71,12 @@ #define MAKE_VERSION(p,q,r) (65536*(p) + 256*(q) + (r)) +#ifndef __bswap_32 +#define __bswap_32(x) \ + ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \ + (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24)) +#endif + static int linux_version_code(void) { struct utsname my_utsname; @@ -323,7 +330,7 @@ static void usage(void) { fprintf(stderr, - _("Usage: %s [-c] [-v0|-v1] [-pPAGESZ] /dev/name [blocks]\n"), + _("Usage: %s [-c] [-v0|-v1] [-pPAGESZ] [-S] /dev/name [blocks]\n"), program_name); exit(1); } @@ -445,6 +452,7 @@ long goodpages; off_t offset; int force = 0; + int byteswap = 0; char *block_count = 0; char *pp; @@ -483,6 +491,9 @@ case 'v': version = atoi(argv[i]+2); break; + case 'S': + byteswap = 1; + break; default: usage(); } @@ -605,9 +616,15 @@ if (version == 0 && !bit_test_and_clear(signature_page,0)) die(_("fatal: first page unreadable")); if (version == 1) { - p->version = version; - p->last_page = PAGES-1; - p->nr_badpages = badpages; + if (byteswap) { + p->version = __bswap_32(version); + p->last_page = __bswap_32(PAGES-1); + p->nr_badpages = __bswap_32(badpages); + } else { + p->version = version; + p->last_page = PAGES-1; + p->nr_badpages = badpages; + } } goodpages = PAGES - badpages - 1;