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">
6 This file is part of systemd.
8 Copyright 2012 Lennart Poettering
10 systemd is free software; you can redistribute it and/or modify it
11 under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
15 systemd is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Lesser General Public License for more details.
20 You should have received a copy of the GNU Lesser General Public License
21 along with systemd; If not, see <http://www.gnu.org/licenses/>.
24 <refentry id="sd-id128">
27 <title>sd-id128</title>
28 <productname>systemd</productname>
32 <contrib>Developer</contrib>
33 <firstname>Lennart</firstname>
34 <surname>Poettering</surname>
35 <email>lennart@poettering.net</email>
41 <refentrytitle>sd-id128</refentrytitle>
42 <manvolnum>3</manvolnum>
46 <refname>sd-id128</refname>
47 <refname>sd_id128_t</refname>
48 <refname>SD_ID128_MAKE</refname>
49 <refname>SD_ID128_CONST_STR</refname>
50 <refname>SD_ID128_FORMAT_STR</refname>
51 <refname>SD_ID128_FORMAT_VAL</refname>
52 <refname>sd_id128_equal</refname>
53 <refpurpose>APIs for processing 128-bit IDs</refpurpose>
58 <funcsynopsisinfo>#include <systemd/sd-id128.h></funcsynopsisinfo>
62 <command>pkg-config --cflags --libs libsystemd-id128</command>
68 <title>Description</title>
70 <para><filename>sd-id128.h</filename> provides APIs to
71 process and generate 128-bit ID values. The 128-bit ID
72 values processed and generated by these APIs are a
73 generalization of OSF UUIDs as defined by <ulink
74 url="https://tools.ietf.org/html/rfc4122">RFC
75 4122</ulink> but use a simpler string
76 format. These functions impose no structure on the
77 used IDs, much unlike OSF UUIDs or Microsoft GUIDs,
78 but are fully compatible with those types of IDs.
82 <citerefentry><refentrytitle>sd_id128_to_string</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
83 <citerefentry><refentrytitle>sd_id128_randomize</refentrytitle><manvolnum>3</manvolnum></citerefentry> and
84 <citerefentry><refentrytitle>sd_id128_get_machine</refentrytitle><manvolnum>3</manvolnum></citerefentry>
85 for more information about the implemented
88 <para>A 128-bit ID is implemented as the following
91 <programlisting>typedef union sd_id128 {
94 } sd_id128_t;</programlisting>
96 <para>This union type allows accessing the 128-bit ID
97 as 16 separate bytes or two 64-bit words. It is generally
98 safer to access the ID components by their 8-bit array
99 to avoid endianness issues. This union is intended to
100 be passed call-by-value (as opposed to
101 call-by-reference) and may be directly manipulated by
104 <para>A couple of macros are defined to denote and
105 decode 128-bit IDs:</para>
107 <para><function>SD_ID128_MAKE()</function> may be used
108 to denote a constant 128-bit ID in source code. A
109 commonly used idiom is to assign a name to a 128-bit
110 ID using this macro:</para>
112 <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>
114 <para><function>SD_ID128_CONST_STR()</function> may be
115 used to convert constant 128-bit IDs into constant
116 strings for output. The following example code will
118 "fc2e22bc6ee647b6b90729ab34a250b1":</para>
119 <programlisting>int main(int argc, char *argv[]) {
120 puts(SD_ID128_CONST_STR(SD_MESSAGE_COREDUMP));
123 <para><function>SD_ID128_FORMAT_STR</function> and
124 <function>SD_ID128_FORMAT_VAL()</function> may be used
125 to format a 128-bit ID in a
126 <citerefentry><refentrytitle>printf</refentrytitle><manvolnum>3</manvolnum></citerefentry>
127 format string, as shown in the following
130 <programlisting>int main(int argc, char *argv[]) {
132 id = SD_ID128_MAKE(ee,89,be,71,bd,6e,43,d6,91,e6,c5,5d,eb,03,02,07);
133 printf("The ID encoded in this C file is " SD_ID128_FORMAT_STR ".\n", SD_ID128_FORMAT_VAL(id));
137 <para>Use <function>sd_id128_equal()</function> to compare two 128-bit IDs:</para>
139 <programlisting>int main(int argc, char *argv[]) {
141 a = SD_ID128_MAKE(ee,89,be,71,bd,6e,43,d6,91,e6,c5,5d,eb,03,02,07);
142 b = SD_ID128_MAKE(f2,28,88,9c,5f,09,44,15,9d,d7,04,77,58,cb,e7,3e);
144 assert(sd_id128_equal(a, c));
145 assert(!sd_id128_equal(a, b));
149 <para>Note that new, randomized IDs may be generated
151 <citerefentry><refentrytitle>journalctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>'s
152 <option>--new-id</option> option.</para>
158 <para>These APIs are implemented as a shared library,
159 which can be compiled and linked to with the
160 <literal>libsystemd-id128</literal> <citerefentry><refentrytitle>pkg-config</refentrytitle><manvolnum>1</manvolnum></citerefentry>
166 <title>See Also</title>
168 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
169 <citerefentry><refentrytitle>sd_id128_to_string</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
170 <citerefentry><refentrytitle>sd_id128_randomize</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
171 <citerefentry><refentrytitle>sd_id128_get_machine</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
172 <citerefentry><refentrytitle>printf</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
173 <citerefentry><refentrytitle>journalctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
174 <citerefentry><refentrytitle>sd-journal</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
175 <citerefentry><refentrytitle>pkg-config</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
176 <citerefentry><refentrytitle>machine-id</refentrytitle><manvolnum>5</manvolnum></citerefentry>