]>
Commit | Line | Data |
---|---|---|
12355095 LP |
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 | This file is part of systemd. | |
7 | ||
8 | Copyright 2012 Lennart Poettering | |
9 | ||
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. | |
14 | ||
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. | |
19 | ||
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/>. | |
22 | --> | |
23 | ||
6a70f3aa ZJS |
24 | <refentry id="sd-id128" |
25 | xmlns:xi="http://www.w3.org/2001/XInclude"> | |
12355095 LP |
26 | |
27 | <refentryinfo> | |
28 | <title>sd-id128</title> | |
29 | <productname>systemd</productname> | |
30 | ||
31 | <authorgroup> | |
32 | <author> | |
33 | <contrib>Developer</contrib> | |
34 | <firstname>Lennart</firstname> | |
35 | <surname>Poettering</surname> | |
36 | <email>lennart@poettering.net</email> | |
37 | </author> | |
38 | </authorgroup> | |
39 | </refentryinfo> | |
40 | ||
41 | <refmeta> | |
42 | <refentrytitle>sd-id128</refentrytitle> | |
cb07866b | 43 | <manvolnum>3</manvolnum> |
12355095 LP |
44 | </refmeta> |
45 | ||
46 | <refnamediv> | |
47 | <refname>sd-id128</refname> | |
48 | <refname>sd_id128_t</refname> | |
49 | <refname>SD_ID128_MAKE</refname> | |
183de6d7 | 50 | <refname>SD_ID128_CONST_STR</refname> |
12355095 LP |
51 | <refname>SD_ID128_FORMAT_STR</refname> |
52 | <refname>SD_ID128_FORMAT_VAL</refname> | |
53 | <refname>sd_id128_equal</refname> | |
e9dd9f95 | 54 | <refpurpose>APIs for processing 128-bit IDs</refpurpose> |
12355095 LP |
55 | </refnamediv> |
56 | ||
57 | <refsynopsisdiv> | |
58 | <funcsynopsis> | |
59 | <funcsynopsisinfo>#include <systemd/sd-id128.h></funcsynopsisinfo> | |
60 | </funcsynopsis> | |
61 | ||
62 | <cmdsynopsis> | |
14bf8788 | 63 | <command>pkg-config --cflags --libs libsystemd</command> |
12355095 LP |
64 | </cmdsynopsis> |
65 | ||
66 | </refsynopsisdiv> | |
67 | ||
68 | <refsect1> | |
69 | <title>Description</title> | |
70 | ||
71 | <para><filename>sd-id128.h</filename> provides APIs to | |
e9dd9f95 | 72 | process and generate 128-bit ID values. The 128-bit ID |
12355095 LP |
73 | values processed and generated by these APIs are a |
74 | generalization of OSF UUIDs as defined by <ulink | |
6ed80a4e | 75 | url="https://tools.ietf.org/html/rfc4122">RFC |
e9dd9f95 JSJ |
76 | 4122</ulink> but use a simpler string |
77 | format. These functions impose no structure on the | |
12355095 LP |
78 | used IDs, much unlike OSF UUIDs or Microsoft GUIDs, |
79 | but are fully compatible with those types of IDs. | |
80 | </para> | |
81 | ||
82 | <para>See | |
a4023a43 LP |
83 | <citerefentry><refentrytitle>sd_id128_to_string</refentrytitle><manvolnum>3</manvolnum></citerefentry>, |
84 | <citerefentry><refentrytitle>sd_id128_randomize</refentrytitle><manvolnum>3</manvolnum></citerefentry> and | |
85 | <citerefentry><refentrytitle>sd_id128_get_machine</refentrytitle><manvolnum>3</manvolnum></citerefentry> | |
bfc79e34 PM |
86 | for more information about the implemented |
87 | functions.</para> | |
12355095 | 88 | |
e9dd9f95 | 89 | <para>A 128-bit ID is implemented as the following |
12355095 LP |
90 | union type:</para> |
91 | ||
92 | <programlisting>typedef union sd_id128 { | |
93 | uint8_t bytes[16]; | |
94 | uint64_t qwords[2]; | |
95 | } sd_id128_t;</programlisting> | |
96 | ||
e9dd9f95 JSJ |
97 | <para>This union type allows accessing the 128-bit ID |
98 | as 16 separate bytes or two 64-bit words. It is generally | |
99 | safer to access the ID components by their 8-bit array | |
40b90434 | 100 | to avoid endianness issues. This union is intended to |
12355095 LP |
101 | be passed call-by-value (as opposed to |
102 | call-by-reference) and may be directly manipulated by | |
103 | clients.</para> | |
104 | ||
105 | <para>A couple of macros are defined to denote and | |
e9dd9f95 | 106 | decode 128-bit IDs:</para> |
12355095 LP |
107 | |
108 | <para><function>SD_ID128_MAKE()</function> may be used | |
e9dd9f95 JSJ |
109 | to denote a constant 128-bit ID in source code. A |
110 | commonly used idiom is to assign a name to a 128-bit | |
183de6d7 | 111 | ID using this macro:</para> |
12355095 LP |
112 | |
113 | <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 | ||
183de6d7 | 115 | <para><function>SD_ID128_CONST_STR()</function> may be |
e9dd9f95 | 116 | used to convert constant 128-bit IDs into constant |
183de6d7 LP |
117 | strings for output. The following example code will |
118 | output the string | |
119 | "fc2e22bc6ee647b6b90729ab34a250b1":</para> | |
120 | <programlisting>int main(int argc, char *argv[]) { | |
121 | puts(SD_ID128_CONST_STR(SD_MESSAGE_COREDUMP)); | |
122 | }</programlisting> | |
123 | ||
12355095 LP |
124 | <para><function>SD_ID128_FORMAT_STR</function> and |
125 | <function>SD_ID128_FORMAT_VAL()</function> may be used | |
e9dd9f95 | 126 | to format a 128-bit ID in a |
12355095 LP |
127 | <citerefentry><refentrytitle>printf</refentrytitle><manvolnum>3</manvolnum></citerefentry> |
128 | format string, as shown in the following | |
129 | example:</para> | |
130 | ||
131 | <programlisting>int main(int argc, char *argv[]) { | |
132 | sd_id128_t id; | |
133 | id = SD_ID128_MAKE(ee,89,be,71,bd,6e,43,d6,91,e6,c5,5d,eb,03,02,07); | |
134 | printf("The ID encoded in this C file is " SD_ID128_FORMAT_STR ".\n", SD_ID128_FORMAT_VAL(id)); | |
135 | return 0; | |
136 | }</programlisting> | |
137 | ||
e9dd9f95 | 138 | <para>Use <function>sd_id128_equal()</function> to compare two 128-bit IDs:</para> |
12355095 LP |
139 | |
140 | <programlisting>int main(int argc, char *argv[]) { | |
141 | sd_id128_t a, b, c; | |
142 | a = SD_ID128_MAKE(ee,89,be,71,bd,6e,43,d6,91,e6,c5,5d,eb,03,02,07); | |
143 | b = SD_ID128_MAKE(f2,28,88,9c,5f,09,44,15,9d,d7,04,77,58,cb,e7,3e); | |
144 | c = a; | |
145 | assert(sd_id128_equal(a, c)); | |
146 | assert(!sd_id128_equal(a, b)); | |
147 | return 0; | |
148 | }</programlisting> | |
149 | ||
150 | <para>Note that new, randomized IDs may be generated | |
151 | with | |
152 | <citerefentry><refentrytitle>journalctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>'s | |
74d00578 | 153 | <option>--new-id</option> option.</para> |
12355095 LP |
154 | </refsect1> |
155 | ||
6a70f3aa | 156 | <xi:include href="libsystemd-pkgconfig.xml" /> |
12355095 LP |
157 | |
158 | <refsect1> | |
159 | <title>See Also</title> | |
160 | <para> | |
161 | <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>, | |
162 | <citerefentry><refentrytitle>sd_id128_to_string</refentrytitle><manvolnum>3</manvolnum></citerefentry>, | |
163 | <citerefentry><refentrytitle>sd_id128_randomize</refentrytitle><manvolnum>3</manvolnum></citerefentry>, | |
a4023a43 | 164 | <citerefentry><refentrytitle>sd_id128_get_machine</refentrytitle><manvolnum>3</manvolnum></citerefentry>, |
12355095 LP |
165 | <citerefentry><refentrytitle>printf</refentrytitle><manvolnum>3</manvolnum></citerefentry>, |
166 | <citerefentry><refentrytitle>journalctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>, | |
167 | <citerefentry><refentrytitle>sd-journal</refentrytitle><manvolnum>7</manvolnum></citerefentry>, | |
168 | <citerefentry><refentrytitle>pkg-config</refentrytitle><manvolnum>1</manvolnum></citerefentry>, | |
169 | <citerefentry><refentrytitle>machine-id</refentrytitle><manvolnum>5</manvolnum></citerefentry> | |
170 | </para> | |
171 | </refsect1> | |
172 | ||
173 | </refentry> |