From 5dbb072e27bea6f740822590e348da6ae4db2d60 Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Sat, 3 Jul 1999 06:16:06 +0000 Subject: [PATCH] ChangeLog, uuidgen.1.in, uuidgen.c: uuidgen.c: Add option parsing so that user can ask for either a time-based UUID or a random-based UUID. --- misc/ChangeLog | 5 +++++ misc/uuidgen.1.in | 37 +++++++++++++++++++++++++++++++------ misc/uuidgen.c | 51 ++++++++++++++++++++++++++++++++++++++++++++------- 3 files changed, 80 insertions(+), 13 deletions(-) diff --git a/misc/ChangeLog b/misc/ChangeLog index 9d7f372..c526993 100644 --- a/misc/ChangeLog +++ b/misc/ChangeLog @@ -1,3 +1,8 @@ +1999-07-03 + + * uuidgen.c: Add option parsing so that user can ask for either a + time-based UUID or a random-based UUID. + 1999-07-02 * fsck.c: Added support for LABEL= and UUID= specifications for diff --git a/misc/uuidgen.1.in b/misc/uuidgen.1.in index 049b663..9c0e4f1 100644 --- a/misc/uuidgen.1.in +++ b/misc/uuidgen.1.in @@ -9,17 +9,42 @@ .SH NAME uuidgen \- command\-line utility to create a new UUID value .SH SYNOPSIS -.nf -.B uuidgen -.fi +.B uuidgen +[ +.B -r +] [ +.B -t +] .SH DESCRIPTION The .B uuidgen program creates a new universally unique identifier (UUID) using the -.BR libuuid "(3) functions " uuid_generate "(3) and " uuid_unparse "(3)." -The new UUID can reasonably be considered unique among all UUIDs created -on the local system, and among UUIDs created on other systems in the past +.BR libuuid (3) +library. The new UUID can reasonably be considered unique among +all UUIDs created on the local system, +and among UUIDs created on other systems in the past and in the future. +.PP +There are two types of UUID's which +.B uuidgen +can generate: time-based UUID's and random-based UUID's. By +default +.B uuidgen +will generatea random-based UUID if a high-quality random number +generator is present. Otherwise, it will chose a time-based UUID. It +is possible to force the generation of one of these two +UUID types by using the +.IR -r " or " -t " options." +.SH "OPTIONS" +.TP +.I -r +Generate a random-based UUID. This method creates a UUID consisting mostly +of random bits. It requires that the operating system have a high +quality random number generator, such as /dev/random. +.TP +.I -t +Generate a time-based UUID. This method creates a UUID based on the system +clock plus the system's ethernet hardware address, if present. .SH RETURN VALUE The UUID of the form 1b4e28ba\-2fa1\-11d2\-883f\-b9a761bde3fb (in .BR printf (3) diff --git a/misc/uuidgen.c b/misc/uuidgen.c index 2b467e9..da402c8 100644 --- a/misc/uuidgen.c +++ b/misc/uuidgen.c @@ -1,7 +1,7 @@ /* * gen_uuid.c --- generate a DCE-compatible uuid * - * Copyright (C) 1999, Andreas Dilger + * Copyright (C) 1999, Andreas Dilger and Theodore Ts'o * * %Begin-Header% * This file may be redistributed under the terms of the GNU Public @@ -10,18 +10,55 @@ */ #include +#ifdef HAVE_GETOPT_H +#include +#endif #include "uuid/uuid.h" +#define DO_TYPE_TIME 1 +#define DO_TYPE_RANDOM 2 + +void usage(const char *progname) +{ + fprintf(stderr, "Usage: %s [-r] [-t]\n", progname); + exit(1); +} + int main (int argc, char *argv[]) { - char str[37]; - uuid_t uu; + int c; + int do_type = 0; + char str[37]; + uuid_t uu; - uuid_generate(uu); - uuid_unparse(uu, str); + while ((c = getopt (argc, argv, "tr")) != EOF) + switch (c) { + case 't': + do_type = DO_TYPE_TIME; + break; + case 'r': + do_type = DO_TYPE_RANDOM; + break; + default: + usage(argv[0]); + } + + switch (do_type) { + case DO_TYPE_TIME: + uuid_generate_time(uu); + break; + case DO_TYPE_RANDOM: + uuid_generate_random(uu); + break; + default: + uuid_generate(uu); + break; + } + + uuid_unparse(uu, str); - printf("%s\n", str); + printf("%s\n", str); - return 0; + return 0; } -- 1.8.3.1