| 1 |
'\" t |
| 2 |
.TH "SD\-ID128" "3" "" "systemd 261~rc3" "sd-id128" |
| 3 |
.\" ----------------------------------------------------------------- |
| 4 |
.\" * Define some portability stuff |
| 5 |
.\" ----------------------------------------------------------------- |
| 6 |
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 7 |
.\" http://bugs.debian.org/507673 |
| 8 |
.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html |
| 9 |
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 10 |
.ie \n(.g .ds Aq \(aq |
| 11 |
.el .ds Aq ' |
| 12 |
.\" ----------------------------------------------------------------- |
| 13 |
.\" * set default formatting |
| 14 |
.\" ----------------------------------------------------------------- |
| 15 |
.\" disable hyphenation |
| 16 |
.nh |
| 17 |
.\" disable justification (adjust text to left margin only) |
| 18 |
.ad l |
| 19 |
.\" ----------------------------------------------------------------- |
| 20 |
.\" * MAIN CONTENT STARTS HERE * |
| 21 |
.\" ----------------------------------------------------------------- |
| 22 |
.SH "NAME" |
| 23 |
sd-id128, SD_ID128_ALLF, SD_ID128_CONST_STR, SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL, SD_ID128_MAKE, SD_ID128_MAKE_STR, SD_ID128_MAKE_UUID_STR, SD_ID128_NULL, SD_ID128_UUID_FORMAT_STR, sd_id128_equal, sd_id128_string_equal, sd_id128_in_set, sd_id128_in_set_sentinel, sd_id128_in_setv, sd_id128_is_allf, sd_id128_is_null, sd_id128_t \- APIs for processing 128\-bit IDs |
| 24 |
.SH "SYNOPSIS" |
| 25 |
.sp |
| 26 |
.ft B |
| 27 |
.nf |
| 28 |
#include <systemd/sd\-id128\&.h> |
| 29 |
.fi |
| 30 |
.ft |
| 31 |
.PP |
| 32 |
\fBSD_ID128_ALLF\fR |
| 33 |
.PP |
| 34 |
\fB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fB, \fR\fB\fIv3\fR\fR\fB, \fR\fB\fIv4\fR\fR\fB, \fR\fB\fIv5\fR\fR\fB, \fR\fB\fIv6\fR\fR\fB, \fR\fB\fIv7\fR\fR\fB, \fR\fB\fIv8\fR\fR\fB, \fR\fB\fIv9\fR\fR\fB, \fR\fB\fIvA\fR\fR\fB, \fR\fB\fIvB\fR\fR\fB, \fR\fB\fIvC\fR\fR\fB, \fR\fB\fIvD\fR\fR\fB, \fR\fB\fIvE\fR\fR\fB, \fR\fB\fIvF\fR\fR\fB)\fR |
| 47 |
.PP |
| 48 |
\fBSD_ID128_UUID_FORMAT_STR\fR |
| 49 |
.HP \w'int\ sd_id128_equal('u |
| 50 |
.BI "int sd_id128_equal(sd_id128_t\ " "a" ", sd_id128_t\ " "b" ");" |
| 51 |
.HP \w'int\ sd_id128_string_equal('u |
| 52 |
.BI "int sd_id128_string_equal(const\ char\ *" "a" ", sd_id128_t\ " "b" ");" |
| 53 |
.HP \w'int\ sd_id128_is_null('u |
| 54 |
.BI "int sd_id128_is_null(sd_id128_t\ " "id" ");" |
| 55 |
.HP \w'int\ sd_id128_is_allf('u |
| 56 |
.BI "int sd_id128_is_allf(sd_id128_t\ " "id" ");" |
| 57 |
.HP \w'int\ sd_id128_in_setv('u |
| 58 |
.BI "int sd_id128_in_setv(sd_id128_t\ " "id" ", va_list\ " "ap" ");" |
| 59 |
.HP \w'int\ sd_id128_in_set_sentinel('u |
| 60 |
.BI "int sd_id128_in_set_sentinel(sd_id128_t\ " "id" ", \&..., " "\fBSD_ID128_NULL\fR" ");" |
| 61 |
.HP \w'int\ sd_id128_in_set('u |
| 62 |
.BI "int sd_id128_in_set(sd_id128_t\ " "id" ", \&...);" |
| 63 |
.HP \w'\fBpkg\-config\ \-\-cflags\ \-\-libs\ libsystemd\fR\ 'u |
| 64 |
\fBpkg\-config \-\-cflags \-\-libs libsystemd\fR |
| 65 |
.SH "DESCRIPTION" |
| 66 |
.PP |
| 67 |
sd\-id128\&.h |
| 68 |
is part of |
| 69 |
\fBlibsystemd\fR(3) |
| 70 |
and provides APIs to generate, convert, and compare 128\-bit ID values\&. The 128\-bit ID values processed and generated by these APIs are a generalization of OSF UUIDs as defined by |
| 71 |
\m[blue]\fBRFC 4122\fR\m[]\&\s-2\u[1]\d\s+2 |
| 72 |
but use a simpler string format\&. These functions impose no structure on the used IDs, much unlike OSF UUIDs or Microsoft GUIDs, but are mostly compatible with those types of IDs\&. |
| 73 |
.PP |
| 74 |
A 128\-bit ID is implemented as the following union type: |
| 75 |
.sp |
| 76 |
.if n \{\ |
| 77 |
.RS 4 |
| 78 |
.\} |
| 79 |
.nf |
| 80 |
typedef union sd_id128 { |
| 81 |
uint8_t bytes[16]; |
| 82 |
uint64_t qwords[2]; |
| 83 |
} sd_id128_t; |
| 84 |
.fi |
| 85 |
.if n \{\ |
| 86 |
.RE |
| 87 |
.\} |
| 88 |
.PP |
| 89 |
This union type allows accessing the 128\-bit ID as 16 separate bytes or two 64\-bit words\&. It is generally safer to access the ID components by their 8\-bit array to avoid endianness issues\&. This union is intended to be passed by value (as opposed to pass\-by\-reference) and may be directly manipulated by clients\&. |
| 90 |
.PP |
| 91 |
A couple of macros are defined to denote and decode 128\-bit IDs: |
| 92 |
.PP |
| 93 |
\fBSD_ID128_MAKE()\fR |
| 94 |
is used to write a constant ID in source code\&. A commonly used idiom is to assign a name to an ID using this macro: |
| 95 |
.sp |
| 96 |
.if n \{\ |
| 97 |
.RS 4 |
| 98 |
.\} |
| 99 |
.nf |
| 100 |
#define SD_MESSAGE_COREDUMP SD_ID128_MAKE(fc,2e,22,bc,6e,e6,47,b6,b9,07,29,ab,34,a2,50,b1) |
| 101 |
.fi |
| 102 |
.if n \{\ |
| 103 |
.RE |
| 104 |
.\} |
| 105 |
.PP |
| 106 |
\fBSD_ID128_NULL\fR |
| 107 |
defines an ID consisting of only |
| 108 |
\fBNUL\fR |
| 109 |
bytes (i\&.e\&. all bits off)\&. |
| 110 |
.PP |
| 111 |
\fBSD_ID128_ALLF\fR |
| 112 |
defines an ID consisting of only |
| 113 |
\fB0xFF\fR |
| 114 |
bytes (i\&.e\&. all bits on)\&. |
| 115 |
.PP |
| 116 |
\fBSD_ID128_MAKE_STR()\fR |
| 117 |
is similar to |
| 118 |
\fBSD_ID128_MAKE()\fR, but creates a |
| 119 |
\fBconst char*\fR |
| 120 |
expression that can be conveniently used in message formats and such: |
| 121 |
.sp |
| 122 |
.if n \{\ |
| 123 |
.RS 4 |
| 124 |
.\} |
| 125 |
.nf |
| 126 |
#include <stdio\&.h> |
| 127 |
#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) |
| 128 |
|
| 129 |
int main(int argc, char **argv) { |
| 130 |
puts("Match for coredumps: MESSAGE_ID=" SD_MESSAGE_COREDUMP_STR); |
| 131 |
} |
| 132 |
.fi |
| 133 |
.if n \{\ |
| 134 |
.RE |
| 135 |
.\} |
| 136 |
.PP |
| 137 |
\fBSD_ID128_CONST_STR()\fR |
| 138 |
converts constant IDs into constant strings for output\&. The following example code will output the string "fc2e22bc6ee647b6b90729ab34a250b1": |
| 139 |
.sp |
| 140 |
.if n \{\ |
| 141 |
.RS 4 |
| 142 |
.\} |
| 143 |
.nf |
| 144 |
int main(int argc, char *argv[]) { |
| 145 |
puts("Match for coredumps: %s", SD_ID128_CONST_STR(SD_MESSAGE_COREDUMP)); |
| 146 |
} |
| 147 |
.fi |
| 148 |
.if n \{\ |
| 149 |
.RE |
| 150 |
.\} |
| 151 |
.PP |
| 152 |
\fBSD_ID128_FORMAT_STR\fR |
| 153 |
and |
| 154 |
\fBSD_ID128_FORMAT_VAL()\fR |
| 155 |
is used to format an ID in a |
| 156 |
\fBprintf\fR(3) |
| 157 |
format string, as shown in the following example: |
| 158 |
.sp |
| 159 |
.if n \{\ |
| 160 |
.RS 4 |
| 161 |
.\} |
| 162 |
.nf |
| 163 |
int main(int argc, char *argv[]) { |
| 164 |
sd_id128_t id; |
| 165 |
id = SD_ID128_MAKE(ee,89,be,71,bd,6e,43,d6,91,e6,c5,5d,eb,03,02,07); |
| 166 |
printf("The ID encoded in this C file is " SD_ID128_FORMAT_STR "\&.\en", SD_ID128_FORMAT_VAL(id)); |
| 167 |
return 0; |
| 168 |
} |
| 169 |
.fi |
| 170 |
.if n \{\ |
| 171 |
.RE |
| 172 |
.\} |
| 173 |
.PP |
| 174 |
\fBSD_ID128_UUID_FORMAT_STR\fR |
| 175 |
and |
| 176 |
\fBSD_ID128_MAKE_UUID_STR()\fR |
| 177 |
are similar to |
| 178 |
\fBSD_ID128_FORMAT_STR\fR |
| 179 |
and |
| 180 |
\fBSD_ID128_MAKE_STR()\fR, but include separating hyphens to conform to the "\m[blue]\fBUUID canonical representation\fR\m[]\&\s-2\u[2]\d\s+2"\&. They format the string based on |
| 181 |
\m[blue]\fBRFC4122\fR\m[]\&\s-2\u[1]\d\s+2 |
| 182 |
Variant 1 rules, i\&.e\&. converting from Big Endian byte order\&. This matches behaviour of most other Linux userspace infrastructure\&. It\*(Aqs probably best to avoid UUIDs of other variants, in order to avoid unnecessary ambiguities\&. All 128\-bit IDs generated by the sd\-id128 APIs strictly conform to Variant 1 Version 4 UUIDs, as per RFC 4122\&. |
| 183 |
.PP |
| 184 |
\fBsd_id128_equal()\fR |
| 185 |
compares two 128\-bit IDs: |
| 186 |
.sp |
| 187 |
.if n \{\ |
| 188 |
.RS 4 |
| 189 |
.\} |
| 190 |
.nf |
| 191 |
int main(int argc, char *argv[]) { |
| 192 |
sd_id128_t a, b, c; |
| 193 |
a = SD_ID128_MAKE(ee,89,be,71,bd,6e,43,d6,91,e6,c5,5d,eb,03,02,07); |
| 194 |
b = SD_ID128_MAKE(f2,28,88,9c,5f,09,44,15,9d,d7,04,77,58,cb,e7,3e); |
| 195 |
c = a; |
| 196 |
assert(sd_id128_equal(a, c)); |
| 197 |
assert(!sd_id128_equal(a, b)); |
| 198 |
return 0; |
| 199 |
} |
| 200 |
.fi |
| 201 |
.if n \{\ |
| 202 |
.RE |
| 203 |
.\} |
| 204 |
.PP |
| 205 |
\fBsd_id128_string_equal()\fR |
| 206 |
is similar to |
| 207 |
\fBsd_id128_equal()\fR, but the first ID is formatted as |
| 208 |
\fBconst char*\fR\&. The same restrictions apply as to the first argument of |
| 209 |
\fBsd_id128_from_string()\fR\&. |
| 210 |
.PP |
| 211 |
\fBsd_id128_is_null()\fR |
| 212 |
checks if an ID consists of only |
| 213 |
\fBNUL\fR |
| 214 |
bytes: |
| 215 |
.sp |
| 216 |
.if n \{\ |
| 217 |
.RS 4 |
| 218 |
.\} |
| 219 |
.nf |
| 220 |
assert(sd_id128_is_null(SD_ID128_NULL)); |
| 221 |
.fi |
| 222 |
.if n \{\ |
| 223 |
.RE |
| 224 |
.\} |
| 225 |
.PP |
| 226 |
Similarly, |
| 227 |
\fBsd_id128_is_allf()\fR |
| 228 |
checks if an ID consists of only |
| 229 |
\fB0xFF\fR |
| 230 |
bytes (all bits on): |
| 231 |
.sp |
| 232 |
.if n \{\ |
| 233 |
.RS 4 |
| 234 |
.\} |
| 235 |
.nf |
| 236 |
assert(sd_id128_is_allf(SD_ID128_ALLF)); |
| 237 |
.fi |
| 238 |
.if n \{\ |
| 239 |
.RE |
| 240 |
.\} |
| 241 |
.PP |
| 242 |
\fBsd_id128_in_set_sentinel()\fR |
| 243 |
takes a list of IDs and returns true if the first argument is equal to any of the subsequent arguments\&. The argument list is terminated by an |
| 244 |
\fBSD_ID128_NULL\fR |
| 245 |
sentinel, which must be present\&. |
| 246 |
.PP |
| 247 |
\fBsd_id128_in_set()\fR |
| 248 |
is a convenience function that takes a list of IDs and returns true if the first argument is equal to any of the subsequent arguments: |
| 249 |
.sp |
| 250 |
.if n \{\ |
| 251 |
.RS 4 |
| 252 |
.\} |
| 253 |
.nf |
| 254 |
int main(int argc, char *argv[]) { |
| 255 |
sd_id12_t a = SD_ID128_MAKE(ee,89,be,71,bd,6e,43,d6,91,e6,c5,5d,eb,03,02,07); |
| 256 |
assert(sd_id128_in_set(a, a)); |
| 257 |
assert(sd_id128_in_set(a, a, a)); |
| 258 |
assert(!sd_id128_in_set(a)); |
| 259 |
assert(!sd_id128_in_set(a, |
| 260 |
SD_ID128_MAKE(f2,28,88,9c,5f,09,44,15,9d,d7,04,77,58,cb,e7,3e) |
| 261 |
SD_ID128_MAKE(2f,88,28,5f,9c,44,09,9d,d7,15,77,04,bc,85,7e,e3) |
| 262 |
SD_ID128_ALLF)); |
| 263 |
return 0; |
| 264 |
} |
| 265 |
.fi |
| 266 |
.if n \{\ |
| 267 |
.RE |
| 268 |
.\} |
| 269 |
.PP |
| 270 |
\fBsd_id128_in_set()\fR |
| 271 |
is defined as a macro over |
| 272 |
\fBsd_id128_in_set_sentinel()\fR, adding the |
| 273 |
\fBSD_ID128_NULL\fR |
| 274 |
sentinel automatically\&. Since |
| 275 |
\fBsd_id128_in_set_sentinel()\fR |
| 276 |
uses |
| 277 |
\fBSD_ID128_NULL\fR |
| 278 |
as the sentinel, |
| 279 |
\fBSD_ID128_NULL\fR |
| 280 |
cannot be otherwise placed in the argument list\&. |
| 281 |
.PP |
| 282 |
\fBsd_id128_in_setv()\fR |
| 283 |
is similar to |
| 284 |
\fBsd_id128_in_set_sentinel()\fR, but takes a |
| 285 |
struct varargs |
| 286 |
argument\&. |
| 287 |
.PP |
| 288 |
New randomized IDs may be generated with |
| 289 |
\fBsystemd-id128\fR(1)\*(Aqs |
| 290 |
\fBnew\fR |
| 291 |
command\&. |
| 292 |
.PP |
| 293 |
See |
| 294 |
\fBsd_id128_to_string\fR(3), |
| 295 |
\fBsd_id128_randomize\fR(3) |
| 296 |
and |
| 297 |
\fBsd_id128_get_machine\fR(3) |
| 298 |
for information about other implemented functions\&. |
| 299 |
.SH "NOTES" |
| 300 |
.PP |
| 301 |
Functions described here are available as a shared library, which can be compiled against and linked to with the |
| 302 |
\fBlibsystemd\fR\ \&\fBpkg-config\fR(1) |
| 303 |
file\&. |
| 304 |
.PP |
| 305 |
The code described here uses |
| 306 |
\fBgetenv\fR(3), which is declared to be not multi\-thread\-safe\&. This means that the code calling the functions described here must not call |
| 307 |
\fBsetenv\fR(3) |
| 308 |
from a parallel thread\&. It is recommended to only do calls to |
| 309 |
\fBsetenv()\fR |
| 310 |
from an early phase of the program when no other threads have been started\&. |
| 311 |
.SH "HISTORY" |
| 312 |
.PP |
| 313 |
\fBsd_id128_equal()\fR, |
| 314 |
\fBsd_id128_string_equal()\fR, |
| 315 |
\fBsd_id128_is_null()\fR, |
| 316 |
\fBsd_id128_is_allf()\fR, |
| 317 |
\fBsd_id128_in_setv()\fR, |
| 318 |
\fBsd_id128_in_set_sentinel()\fR, and |
| 319 |
\fBsd_id128_in_set()\fR |
| 320 |
were added in version 252\&. |
| 321 |
.SH "SEE ALSO" |
| 322 |
.PP |
| 323 |
\fBsystemd\fR(1), \fBsd_id128_to_string\fR(3), \fBsd_id128_randomize\fR(3), \fBsd_id128_get_machine\fR(3), \fBprintf\fR(3), \fBjournalctl\fR(1), \fBsd-journal\fR(3), \fBpkg-config\fR(1), \fBmachine-id\fR(5) |
| 324 |
.SH "NOTES" |
| 325 |
.IP " 1." 4 |
| 326 |
RFC 4122 |
| 327 |
.RS 4 |
| 328 |
\%https://tools.ietf.org/html/rfc4122 |
| 329 |
.RE |
| 330 |
.IP " 2." 4 |
| 331 |
UUID canonical representation |
| 332 |
.RS 4 |
| 333 |
\%https://en.wikipedia.org/wiki/Universally_unique_identifier#Format |
| 334 |
.RE |