qemu/include/qemu/uuid.h
<<
>>
Prefs
   1/*
   2 *  QEMU UUID functions
   3 *
   4 *  Copyright 2016 Red Hat, Inc.
   5 *
   6 *  Authors:
   7 *   Fam Zheng <famz@redhat.com>
   8 *
   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.
  13 *
  14 */
  15
  16#ifndef QEMU_UUID_H
  17#define QEMU_UUID_H
  18
  19
  20/* Version 4 UUID (pseudo random numbers), RFC4122 4.4. */
  21
  22typedef 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;
  34    };
  35} QemuUUID;
  36
  37/**
  38 * UUID_LE - converts the fields of UUID to little-endian array,
  39 * each of parameters is the filed of UUID.
  40 *
  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
  54 */
  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) }
  63
  64#define UUID_FMT "%02hhx%02hhx%02hhx%02hhx-" \
  65                 "%02hhx%02hhx-%02hhx%02hhx-" \
  66                 "%02hhx%02hhx-" \
  67                 "%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx"
  68
  69#define UUID_FMT_LEN 36
  70
  71#define UUID_NONE "00000000-0000-0000-0000-000000000000"
  72
  73void qemu_uuid_generate(QemuUUID *out);
  74
  75int qemu_uuid_is_null(const QemuUUID *uu);
  76
  77int qemu_uuid_is_equal(const QemuUUID *lhv, const QemuUUID *rhv);
  78
  79void qemu_uuid_unparse(const QemuUUID *uuid, char *out);
  80
  81char *qemu_uuid_unparse_strdup(const QemuUUID *uuid);
  82
  83int qemu_uuid_parse(const char *str, QemuUUID *uuid);
  84
  85QemuUUID qemu_uuid_bswap(QemuUUID uuid);
  86
  87#endif
  88