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