Whamcloud - gitweb
ChangeLog, uuidgen.1.in, uuidgen.c:
authorTheodore Ts'o <tytso@mit.edu>
Sat, 3 Jul 1999 06:16:06 +0000 (06:16 +0000)
committerTheodore Ts'o <tytso@mit.edu>
Sat, 3 Jul 1999 06:16:06 +0000 (06:16 +0000)
  uuidgen.c: Add option parsing so that user can ask for either a
   time-based UUID or a random-based UUID.

misc/ChangeLog
misc/uuidgen.1.in
misc/uuidgen.c

index 9d7f372..c526993 100644 (file)
@@ -1,3 +1,8 @@
+1999-07-03    <tytso@rsts-11.mit.edu>
+
+       * uuidgen.c: Add option parsing so that user can ask for either a
+               time-based UUID or a random-based UUID.
+
 1999-07-02    <tytso@rsts-11.mit.edu>
 
        * fsck.c: Added support for LABEL= and UUID= specifications for
index 049b663..9c0e4f1 100644 (file)
@@ -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)
index 2b467e9..da402c8 100644 (file)
@@ -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
  */
 
 #include <stdio.h>
+#ifdef HAVE_GETOPT_H
+#include <getopt.h>
+#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;
 }