uuid.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * Copyright (C) 2014 Samsung Electronics
  4. * Przemyslaw Marczak <p.marczak@samsung.com>
  5. */
  6. #ifndef __UUID_H__
  7. #define __UUID_H__
  8. #include <linux/bitops.h>
  9. /* This is structure is in big-endian */
  10. struct uuid {
  11. unsigned int time_low;
  12. unsigned short time_mid;
  13. unsigned short time_hi_and_version;
  14. unsigned char clock_seq_hi_and_reserved;
  15. unsigned char clock_seq_low;
  16. unsigned char node[6];
  17. } __packed;
  18. /* Bits of a bitmask specifying the output format for GUIDs */
  19. #define UUID_STR_FORMAT_STD 0
  20. #define UUID_STR_FORMAT_GUID BIT(0)
  21. #define UUID_STR_UPPER_CASE BIT(1)
  22. #define UUID_STR_LEN 36
  23. #define UUID_BIN_LEN sizeof(struct uuid)
  24. #define UUID_VERSION_MASK 0xf000
  25. #define UUID_VERSION_SHIFT 12
  26. #define UUID_VERSION 0x4
  27. #define UUID_VARIANT_MASK 0xc0
  28. #define UUID_VARIANT_SHIFT 7
  29. #define UUID_VARIANT 0x1
  30. int uuid_str_valid(const char *uuid);
  31. int uuid_str_to_bin(const char *uuid_str, unsigned char *uuid_bin,
  32. int str_format);
  33. void uuid_bin_to_str(const unsigned char *uuid_bin, char *uuid_str,
  34. int str_format);
  35. #ifdef CONFIG_PARTITION_TYPE_GUID
  36. int uuid_guid_get_bin(const char *guid_str, unsigned char *guid_bin);
  37. int uuid_guid_get_str(const unsigned char *guid_bin, char *guid_str);
  38. #endif
  39. void gen_rand_uuid(unsigned char *uuid_bin);
  40. void gen_rand_uuid_str(char *uuid_str, int str_format);
  41. #endif