xref: /freebsd/lib/libsys/uuidgen.2 (revision 95eb4b873b6a8b527c5bd78d7191975dfca38998)
1.\" Copyright (c) 2002 Marcel Moolenaar
2.\" All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\"
8.\" 1. Redistributions of source code must retain the above copyright
9.\"    notice, this list of conditions and the following disclaimer.
10.\" 2. Redistributions in binary form must reproduce the above copyright
11.\"    notice, this list of conditions and the following disclaimer in the
12.\"    documentation and/or other materials provided with the distribution.
13.\"
14.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24.\"
25.Dd May 26, 2002
26.Dt UUIDGEN 2
27.Os
28.Sh NAME
29.Nm uuidgen
30.Nd generate universally unique identifiers
31.Sh LIBRARY
32.Lb libc
33.Sh SYNOPSIS
34.In sys/uuid.h
35.Ft int
36.Fn uuidgen "struct uuid *store" "int count"
37.Sh DESCRIPTION
38The
39.Fn uuidgen
40system call generates
41.Fa count
42universally unique identifiers (UUIDs) and writes them to the buffer
43pointed to by
44.Fa store .
45The identifiers are generated according to the syntax and semantics of the
46DCE version 1 variant of universally unique identifiers.
47See below for a more in-depth description of the identifiers.
48When no IEEE 802
49address is available for the node field, a random multicast address is
50generated for each invocation of the system call.
51According to the algorithm of generating time-based UUIDs, this will also
52force a new random clock sequence, thereby increasing the likelihood for
53the identifier to be unique.
54.Pp
55When multiple identifiers are to be generated, the
56.Fn uuidgen
57system call will generate a set of identifiers that is dense in such a way
58that there is no identifier that is larger than the smallest identifier in the
59set and smaller than the largest identifier in the set and that is not already
60in the set.
61.Pp
62Universally unique identifiers, also known as globally unique identifiers
63(GUIDs), have a binary representation of 128-bits.
64The grouping and meaning of these bits is described by the following
65structure and its description of the fields that follow it:
66.Bd -literal
67struct uuid {
68	uint32_t	time_low;
69	uint16_t	time_mid;
70	uint16_t	time_hi_and_version;
71	uint8_t		clock_seq_hi_and_reserved;
72	uint8_t		clock_seq_low;
73	uint8_t		node[_UUID_NODE_LEN];
74};
75.Ed
76.Bl -tag -width ".Va clock_seq_hi_and_reserved"
77.It Va time_low
78The least significant 32 bits of a 60-bit timestamp.
79This field is stored in the native byte-order.
80.It Va time_mid
81The least significant 16 bits of the most significant 28 bits of the 60-bit
82timestamp.
83This field is stored in the native byte-order.
84.It Va time_hi_and_version
85The most significant 12 bits of the 60-bit timestamp multiplexed with a 4-bit
86version number.
87The version number is stored in the most significant 4 bits of the 16-bit
88field.
89This field is stored in the native byte-order.
90.It Va clock_seq_hi_and_reserved
91The most significant 6 bits of a 14-bit sequence number multiplexed with a
922-bit variant value.
93Note that the width of the variant value is determined by the variant itself.
94Identifiers generated by the
95.Fn uuidgen
96system call have variant value 10b.
97the variant value is stored in the most significant bits of the field.
98.It Va clock_seq_low
99The least significant 8 bits of a 14-bit sequence number.
100.It Va node
101The 6-byte IEEE 802 (MAC) address of one of the interfaces of the node.
102If no such interface exists, a random multi-cast address is used instead.
103.El
104.Pp
105The binary representation is sensitive to byte ordering.
106Any multi-byte field is to be stored in the local or native byte-order and
107identifiers must be converted when transmitted to hosts that do not agree
108on the byte-order.
109The specification does not however document what this means in concrete
110terms and is otherwise beyond the scope of this system call.
111.Sh RETURN VALUES
112.Rv -std
113.Sh ERRORS
114The
115.Fn uuidgen
116system call can fail with:
117.Bl -tag -width Er
118.It Bq Er EFAULT
119The buffer pointed to by
120.Fa store
121could not be written to for any or all identifiers.
122.It Bq Er EINVAL
123The
124.Fa count
125argument is less than 1 or larger than the hard upper limit of 2048.
126.El
127.Sh SEE ALSO
128.Xr uuidgen 1 ,
129.Xr uuid 3
130.Sh STANDARDS
131The identifiers are represented and generated in conformance with the DCE 1.1
132RPC specification.
133The
134.Fn uuidgen
135system call is itself not part of the specification.
136.Sh HISTORY
137The
138.Fn uuidgen
139system call first appeared in
140.Fx 5.0 .
141