xref: /netbsd-src/lib/libc/sys/uuidgen.2 (revision c3b035f199de4d8a5ca72312d15f9f7423fec8ac)
1.\" $NetBSD: uuidgen.2,v 1.5 2019/07/24 06:11:57 riastradh 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 randomly generated according to UUID version 4.
51.Pp
52Universally unique identifiers, also known as globally unique identifiers
53(GUIDs), have a binary representation of 128-bits.
54The grouping and meaning of these bits is based on historical methods
55of generation from on timestamps and IEEE 802 MAC addresses, and is
56described by the following structure and its description of the fields
57that follow it:
58.Bd -literal
59struct uuid {
60	uint32_t	time_low;
61	uint16_t	time_mid;
62	uint16_t	time_hi_and_version;
63	uint8_t		clock_seq_hi_and_reserved;
64	uint8_t		clock_seq_low;
65	uint8_t		node[_UUID_NODE_LEN];
66};
67.Ed
68.Bl -tag -width ".Va clock_seq_hi_and_reserved"
69.It Va time_low
70The least significant 32 bits of a 60-bit timestamp.
71This field is stored in the native byte-order.
72.It Va time_mid
73The least significant 16 bits of the most significant 28 bits of the 60-bit
74timestamp.
75This field is stored in the native byte-order.
76.It Va time_hi_and_version
77The most significant 12 bits of the 60-bit timestamp multiplexed with a 4-bit
78version number.
79The version number is stored in the most significant 4 bits of the 16-bit
80field.
81This field is stored in the native byte-order.
82.It Va clock_seq_hi_and_reserved
83The most significant 6 bits of a 14-bit sequence number multiplexed with a
842-bit variant value.
85Note that the width of the variant value is determined by the variant itself.
86Identifiers generated by the
87.Fn uuidgen
88system call have variant value 10b.
89the variant value is stored in the most significant bits of the field.
90.It Va clock_seq_low
91The least significant 8 bits of a 14-bit sequence number.
92.It Va node
93The 6-byte IEEE 802 (MAC) address of one of the interfaces of the node.
94If no such interface exists, a random multi-cast address is used instead.
95.El
96.Pp
97The binary representation is sensitive to byte ordering.
98Any multi-byte field is to be stored in the local or native byte-order and
99identifiers must be converted when transmitted to hosts that do not agree
100on the byte-order.
101The specification does not however document what this means in concrete
102terms and is otherwise beyond the scope of this system call.
103.Sh RETURN VALUES
104.Rv -std
105.Sh ERRORS
106The
107.Fn uuidgen
108system call can fail with:
109.Bl -tag -width Er
110.It Bq Er EFAULT
111The buffer pointed to by
112.Fa store
113could not be written to for any or all identifiers.
114.It Bq Er EINVAL
115The
116.Fa count
117argument is less than 1 or larger than the hard upper limit of 2048.
118.El
119.Sh SEE ALSO
120.Xr uuidgen 1 ,
121.Xr uuid 3
122.Rs
123.%A P. Leach
124.%A M. Mealling
125.%A R. Salz
126.%T A Universally Unique IDentifier (UUID) URN Namespace
127.%R RFC 4122
128.%I IETF
129.%D July 2005
130.Re
131.Sh STANDARDS
132The identifiers are represented and generated in conformance with IETF
133RFC 4122, based on the historic DCE 1.1 RPC specification of the Open
134Software Foundation (now the Open Group).
135The
136.Fn uuidgen
137system call is itself not part of the specification.
138.Sh HISTORY
139The
140.Fn uuidgen
141system call first appeared in
142.Fx 5.0
143and was subsequently added to
144.Nx 2.0 .
145It was changed to use version 4 UUIDs, i.e. randomly generated UUIDs,
146in
147.Nx 8.0 .
148