From: Karel Zak Date: Thu, 23 Sep 2021 09:53:26 +0000 (+0200) Subject: mkswap: support -U {clear,random,time,uuid} X-Git-Tag: v2.38-rc1~246 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=54ef08ed37acce099035cc6da7a3bdce63b00e3a;p=thirdparty%2Futil-linux.git mkswap: support -U {clear,random,time,uuid} Let's follow -U from mkfs.ext4 and make it easy to fully control UUIDs for the swap area. Fixes: https://github.com/karelzak/util-linux/issues/1453 Signed-off-by: Karel Zak --- diff --git a/disk-utils/mkswap.8.adoc b/disk-utils/mkswap.8.adoc index 8a305a2e4d..3a6029f2c2 100644 --- a/disk-utils/mkswap.8.adoc +++ b/disk-utils/mkswap.8.adoc @@ -56,7 +56,16 @@ Use exclusive BSD lock for device or file it operates. The optional argument _mo Specify the page _size_ (in bytes) to use. This option is usually unnecessary; *mkswap* reads the size from the kernel. *-U*, *--uuid* _UUID_:: -Specify the _UUID_ to use. The default is to generate a UUID. +Specify the _UUID_ to use. The default is to generate a UUID. The format of the UUID is a series of +hex digits separated by hyphens, like this: "c1b9d5a2-f162-11cf-9ece-0020afc76f16". The UUID parameter +may also be one of the following: ++ +*clear*;; +clear the filesystem UUID +*random*;; +generate a new randomly-generated UUID +*time*;; +generate a new time-based UUID *-v*, *--swapversion 1*:: Specify the swap-space version. (This option is currently pointless, as the old *-v 0* option has become obsolete and now only *-v 1* is supported. The kernel has not supported v0 swap-space format since 2.5.22 (June 2002). The new version v1 is supported since 2.1.117 (August 1998).) diff --git a/disk-utils/mkswap.c b/disk-utils/mkswap.c index c45a3a317e..6221499e04 100644 --- a/disk-utils/mkswap.c +++ b/disk-utils/mkswap.c @@ -172,6 +172,7 @@ static void __attribute__((__noreturn__)) usage(void) fprintf(out, _(" --lock[=] use exclusive device lock (%s, %s or %s)\n"), "yes", "no", "nonblock"); + printf(USAGE_HELP_OPTIONS(27)); printf(USAGE_MAN_TAIL("mkswap(8)")); @@ -541,7 +542,13 @@ int main(int argc, char **argv) #ifdef HAVE_LIBUUID if(opt_uuid) { - if (uuid_parse(opt_uuid, uuid_dat) != 0) + if (strcmp(opt_uuid, "clear") == 0) + uuid_clear(uuid_dat); + else if (strcmp(opt_uuid, "random") == 0) + uuid_generate_random(uuid_dat); + else if (strcmp(opt_uuid, "time") == 0) + uuid_generate_time(uuid_dat); + else if (uuid_parse(opt_uuid, uuid_dat) != 0) errx(EXIT_FAILURE, _("error: parsing UUID failed")); } else uuid_generate(uuid_dat);