]> git.ipfire.org Git - thirdparty/systemd.git/blob - man/sd-id128.xml
grypt-util: drop two emacs modelines
[thirdparty/systemd.git] / man / sd-id128.xml
1 <?xml version='1.0'?> <!--*-nxml-*-->
2 <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
3 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
4
5 <!--
6 SPDX-License-Identifier: LGPL-2.1+
7
8 Copyright 2012 Lennart Poettering
9 -->
10
11 <refentry id="sd-id128"
12 xmlns:xi="http://www.w3.org/2001/XInclude">
13
14 <refentryinfo>
15 <title>sd-id128</title>
16 <productname>systemd</productname>
17
18 <authorgroup>
19 <author>
20 <contrib>Developer</contrib>
21 <firstname>Lennart</firstname>
22 <surname>Poettering</surname>
23 <email>lennart@poettering.net</email>
24 </author>
25 </authorgroup>
26 </refentryinfo>
27
28 <refmeta>
29 <refentrytitle>sd-id128</refentrytitle>
30 <manvolnum>3</manvolnum>
31 </refmeta>
32
33 <refnamediv>
34 <refname>sd-id128</refname>
35 <refname>sd_id128_t</refname>
36 <refname>SD_ID128_MAKE</refname>
37 <refname>SD_ID128_MAKE_STR</refname>
38 <refname>SD_ID128_NULL</refname>
39 <refname>SD_ID128_CONST_STR</refname>
40 <refname>SD_ID128_FORMAT_STR</refname>
41 <refname>SD_ID128_FORMAT_VAL</refname>
42 <refname>sd_id128_equal</refname>
43 <refname>sd_id128_is_null</refname>
44 <refpurpose>APIs for processing 128-bit IDs</refpurpose>
45 </refnamediv>
46
47 <refsynopsisdiv>
48 <funcsynopsis>
49 <funcsynopsisinfo>#include &lt;systemd/sd-id128.h&gt;</funcsynopsisinfo>
50 </funcsynopsis>
51
52 <cmdsynopsis>
53 <command>pkg-config --cflags --libs libsystemd</command>
54 </cmdsynopsis>
55
56 </refsynopsisdiv>
57
58 <refsect1>
59 <title>Description</title>
60
61 <para><filename>sd-id128.h</filename> provides APIs to process and
62 generate 128-bit ID values. The 128-bit ID values processed and
63 generated by these APIs are a generalization of OSF UUIDs as
64 defined by <ulink url="https://tools.ietf.org/html/rfc4122">RFC
65 4122</ulink> but use a simpler string format. These functions
66 impose no structure on the used IDs, much unlike OSF UUIDs or
67 Microsoft GUIDs, but are fully compatible with those types of IDs.
68 </para>
69
70 <para>See
71 <citerefentry><refentrytitle>sd_id128_to_string</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
72 <citerefentry><refentrytitle>sd_id128_randomize</refentrytitle><manvolnum>3</manvolnum></citerefentry>
73 and
74 <citerefentry><refentrytitle>sd_id128_get_machine</refentrytitle><manvolnum>3</manvolnum></citerefentry>
75 for more information about the implemented functions.</para>
76
77 <para>A 128-bit ID is implemented as the following
78 union type:</para>
79
80 <programlisting>typedef union sd_id128 {
81 uint8_t bytes[16];
82 uint64_t qwords[2];
83 } sd_id128_t;</programlisting>
84
85 <para>This union type allows accessing the 128-bit ID as 16
86 separate bytes or two 64-bit words. It is generally safer to
87 access the ID components by their 8-bit array to avoid endianness
88 issues. This union is intended to be passed call-by-value (as
89 opposed to call-by-reference) and may be directly manipulated by
90 clients.</para>
91
92 <para>A couple of macros are defined to denote and decode 128-bit
93 IDs:</para>
94
95 <para><function>SD_ID128_MAKE()</function> may be used to denote a
96 constant 128-bit ID in source code. A commonly used idiom is to
97 assign a name to a 128-bit ID using this macro:</para>
98
99 <programlisting>#define SD_MESSAGE_COREDUMP SD_ID128_MAKE(fc,2e,22,bc,6e,e6,47,b6,b9,07,29,ab,34,a2,50,b1)</programlisting>
100
101 <para><function>SD_ID128_NULL</function> may be used to refer to the 128bit ID consisting of only NUL
102 bytes.</para>
103
104 <para><function>SD_ID128_MAKE_STR()</function> is similar to <function>SD_ID128_MAKE()</function>, but creates a
105 <type>const char*</type> expression that can be conveniently used in message formats and such:</para>
106
107 <programlisting>#include &lt;stdio.h&gt;
108 #define SD_MESSAGE_COREDUMP_STR SD_ID128_MAKE_STR(fc,2e,22,bc,6e,e6,47,b6,b9,07,29,ab,34,a2,50,b1)
109
110 int main(int argc, char **argv) {
111 puts("Match for coredumps: MESSAGE_ID=" SD_MESSAGE_COREDUMP_STR);
112 }
113 </programlisting>
114
115 <para><function>SD_ID128_CONST_STR()</function> may be used to
116 convert constant 128-bit IDs into constant strings for output. The
117 following example code will output the string
118 "fc2e22bc6ee647b6b90729ab34a250b1":</para>
119 <programlisting>int main(int argc, char *argv[]) {
120 puts("Match for coredumps: %s", SD_ID128_CONST_STR(SD_MESSAGE_COREDUMP));
121 }</programlisting>
122
123 <para><function>SD_ID128_FORMAT_STR()</function> and
124 <function>SD_ID128_FORMAT_VAL()</function> may be used to format a
125 128-bit ID in a
126 <citerefentry project='man-pages'><refentrytitle>printf</refentrytitle><manvolnum>3</manvolnum></citerefentry>
127 format string, as shown in the following example:</para>
128
129 <programlisting>int main(int argc, char *argv[]) {
130 sd_id128_t id;
131 id = SD_ID128_MAKE(ee,89,be,71,bd,6e,43,d6,91,e6,c5,5d,eb,03,02,07);
132 printf("The ID encoded in this C file is " SD_ID128_FORMAT_STR ".\n", SD_ID128_FORMAT_VAL(id));
133 return 0;
134 }</programlisting>
135
136 <para>Use <function>sd_id128_equal()</function> to compare two 128-bit IDs:</para>
137
138 <programlisting>int main(int argc, char *argv[]) {
139 sd_id128_t a, b, c;
140 a = SD_ID128_MAKE(ee,89,be,71,bd,6e,43,d6,91,e6,c5,5d,eb,03,02,07);
141 b = SD_ID128_MAKE(f2,28,88,9c,5f,09,44,15,9d,d7,04,77,58,cb,e7,3e);
142 c = a;
143 assert(sd_id128_equal(a, c));
144 assert(!sd_id128_equal(a, b));
145 return 0;
146 }</programlisting>
147
148 <para>Use <function>sd_id128_is_null()</function> to check if an 128bit ID consists of only NUL bytes:</para>
149
150 <programlisting>int main(int argc, char *argv[]) {
151 assert(sd_id128_is_null(SD_ID128_NULL));
152 }</programlisting>
153
154 <para>Note that new, randomized IDs may be generated with
155 <citerefentry><refentrytitle>journalctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>'s
156 <option>--new-id128</option> option.</para>
157 </refsect1>
158
159 <xi:include href="libsystemd-pkgconfig.xml" />
160
161 <refsect1>
162 <title>See Also</title>
163 <para>
164 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
165 <citerefentry><refentrytitle>sd_id128_to_string</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
166 <citerefentry><refentrytitle>sd_id128_randomize</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
167 <citerefentry><refentrytitle>sd_id128_get_machine</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
168 <citerefentry project='man-pages'><refentrytitle>printf</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
169 <citerefentry><refentrytitle>journalctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
170 <citerefentry><refentrytitle>sd-journal</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
171 <citerefentry project='die-net'><refentrytitle>pkg-config</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
172 <citerefentry><refentrytitle>machine-id</refentrytitle><manvolnum>5</manvolnum></citerefentry>
173 </para>
174 </refsect1>
175
176 </refentry>