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