qom: Use returned bool to check for failure, Coccinelle part
[qemu/ar7.git] / include / qemu / uuid.h
blob9925febfa54d3d5dc8e81b114a37c3dd19a7613d
1 /*
2 * QEMU UUID functions
4 * Copyright 2016 Red Hat, Inc.
6 * Authors:
7 * Fam Zheng <famz@redhat.com>
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the Free
11 * Software Foundation; either version 2 of the License, or (at your option)
12 * any later version.
16 #ifndef QEMU_UUID_H
17 #define QEMU_UUID_H
20 /* Version 4 UUID (pseudo random numbers), RFC4122 4.4. */
22 typedef struct {
23 union {
24 unsigned char data[16];
25 struct {
26 /* Generated in BE endian, can be swapped with qemu_uuid_bswap. */
27 uint32_t time_low;
28 uint16_t time_mid;
29 uint16_t time_high_and_version;
30 uint8_t clock_seq_and_reserved;
31 uint8_t clock_seq_low;
32 uint8_t node[6];
33 } fields;
35 } QemuUUID;
37 /**
38 * UUID_LE - converts the fields of UUID to little-endian array,
39 * each of parameters is the filed of UUID.
41 * @time_low: The low field of the timestamp
42 * @time_mid: The middle field of the timestamp
43 * @time_hi_and_version: The high field of the timestamp
44 * multiplexed with the version number
45 * @clock_seq_hi_and_reserved: The high field of the clock
46 * sequence multiplexed with the variant
47 * @clock_seq_low: The low field of the clock sequence
48 * @node0: The spatially unique node0 identifier
49 * @node1: The spatially unique node1 identifier
50 * @node2: The spatially unique node2 identifier
51 * @node3: The spatially unique node3 identifier
52 * @node4: The spatially unique node4 identifier
53 * @node5: The spatially unique node5 identifier
55 #define UUID_LE(time_low, time_mid, time_hi_and_version, \
56 clock_seq_hi_and_reserved, clock_seq_low, node0, node1, node2, \
57 node3, node4, node5) \
58 { (time_low) & 0xff, ((time_low) >> 8) & 0xff, ((time_low) >> 16) & 0xff, \
59 ((time_low) >> 24) & 0xff, (time_mid) & 0xff, ((time_mid) >> 8) & 0xff, \
60 (time_hi_and_version) & 0xff, ((time_hi_and_version) >> 8) & 0xff, \
61 (clock_seq_hi_and_reserved), (clock_seq_low), (node0), (node1), (node2),\
62 (node3), (node4), (node5) }
64 #define UUID_FMT "%02hhx%02hhx%02hhx%02hhx-" \
65 "%02hhx%02hhx-%02hhx%02hhx-" \
66 "%02hhx%02hhx-" \
67 "%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx"
69 #define UUID_FMT_LEN 36
71 #define UUID_NONE "00000000-0000-0000-0000-000000000000"
73 void qemu_uuid_generate(QemuUUID *out);
75 int qemu_uuid_is_null(const QemuUUID *uu);
77 int qemu_uuid_is_equal(const QemuUUID *lhv, const QemuUUID *rhv);
79 void qemu_uuid_unparse(const QemuUUID *uuid, char *out);
81 char *qemu_uuid_unparse_strdup(const QemuUUID *uuid);
83 int qemu_uuid_parse(const char *str, QemuUUID *uuid);
85 QemuUUID qemu_uuid_bswap(QemuUUID uuid);
87 #endif