libxl: add support for FreeBSD uuid implementation
PATCH v4 1/1 libxl: add support for FreeBSD uuid implementation
Add the FreeBSD specific uuid implementation. Since uuid_t is not defined as an array, but as a struct on FreeBSD, use a union with a array in order to be able to return the uuid as a bytearray.
Also, added a libxl internal compile time assert macro, that is used to assert that the size of uuid_t is the same as the union used in libxl.
---
Changes since v2:
- Unify the FreeBSD and NetBSD uuid implementations as much as possible.
--- tools/libxl/libxl_internal.h | 8 ++++++++ tools/libxl/libxl_uuid.c | 40 ++++++++++++++++++++++++++++++++-------- tools/libxl/libxl_uuid.h | 12 +++++++----- 3 files changed, 47 insertions(+), 13 deletions(-)
tools/libxl/libxl_internal.h +8 -0
@@ -3179,6 +3179,14 @@ int libxl__uint64_parse_json(libxl__gc *gc, const libxl__json_object *o, void *p);int libxl__string_parse_json (libxl__gc *gc,const libxl__json_object *o,char **p); +/* +* Compile time assertion +*/ +#if __GNUC__ >4 || (__GNUC__ ==4 && __GNUC_MINOR__ >=6 ) +#define BUILD_BUG_ON (p) ({ _Static_assert(!(p), "!(" #p ")"); }) +#else +#define BUILD_BUG_ON (p) ((void)sizeof(char[1 - 2 * !!(p)])) +#endif #endif
tools/libxl/libxl_uuid.c +32 -8
@@ -59,21 +59,35 @@ uint8_t *libxl_uuid_bytearray(libxl_uuid *uuid)return uuid->uuid; } -#elif defined(__NetBSD__) +#elif defined(__FreeBSD__) || defined(__NetBSD__)int libxl_uuid_is_nil (const libxl_uuid *uuid) {uint32_t status; -return uuid_is_nil ((uuid_t *)uuid->uuid, &status); + +return uuid_is_nil (&uuid->uuid, &status); }void libxl_uuid_generate (libxl_uuid *uuid) {uint32_t status; -uuid_create ((uuid_t *)uuid->uuid, &status); + +BUILD_BUG_ON (sizeof (libxl_uuid) !=sizeof (uuid_t)); +uuid_create (&uuid->uuid, &status);assert (status == uuid_s_ok); } +#ifdef __FreeBSD__ +int libxl_uuid_from_string (libxl_uuid *uuid,const char *in) +{ +uint32_t status; + +uuid_from_string (in, &uuid->uuid, &status); +if (status != uuid_s_ok) +return -1 ; +return 0 ; +} +#else #define LIBXL__UUID_PTRS (uuid) &uuid[0], &uuid[1], &uuid[2], &uuid[3], \ &uuid[4], &uuid[5], &uuid[6], &uuid[7], \ &uuid[8], &uuid[9], &uuid[10],&uuid[11], \
@@ -85,33 +99,43 @@ int libxl_uuid_from_string(libxl_uuid *uuid, const char *in)return 0 ; }#undef LIBXL__UUID_PTRS +#endif void libxl_uuid_copy (libxl_ctx *ctx_opt,libxl_uuid *dst,const libxl_uuid *src) { -memcpy (dst->uuid, src->uuid,sizeof (dst->uuid)); +memcpy (&dst->uuid, &src->uuid,sizeof (dst->uuid)); }void libxl_uuid_clear (libxl_uuid *uuid) { -memset (uuid->uuid,0 ,sizeof (uuid->uuid)); +memset (&uuid->uuid,0 ,sizeof (uuid->uuid)); } +#ifdef __FreeBSD__ +int libxl_uuid_compare (const libxl_uuid *uuid1,const libxl_uuid *uuid2) +{ + +return uuid_compare (&uuid1->uuid, &uuid2->uuid,NULL ); +} +#else int libxl_uuid_compare (const libxl_uuid *uuid1,const libxl_uuid *uuid2) {return memcmp (uuid1->uuid, uuid2->uuid,sizeof (uuid1->uuid)); } +#endif const uint8_t *libxl_uuid_bytearray_const (const libxl_uuid *uuid) { -return uuid->uuid; + +return uuid->uuid_raw; }uint8_t *libxl_uuid_bytearray (libxl_uuid *uuid) { -return uuid->uuid; -} +return uuid->uuid_raw; +}#else #error "Please update libxl_uuid.c for your OS"
tools/libxl/libxl_uuid.h +7 -5
@@ -33,20 +33,22 @@ typedef struct {#define LIBXL_UUID_BYTES (arg) LIBXL__UUID_BYTES(((uint8_t *)arg.uuid)) -#elif defined(__NetBSD__) +#elif defined(__FreeBSD__) || defined(__NetBSD__)#include <uuid.h> +#include <stdint.h> #include <string.h> #include <stdlib.h> #include <stdio.h> #include <assert.h> -#define LIBXL_UUID_BYTES (arg) LIBXL__UUID_BYTES(arg.uuid) - -typedef struct { -uint8_t uuid[16 ]; +typedef union { +uuid_t uuid; +uint8_t uuid_raw[16 ]; }libxl_uuid ; +#define LIBXL_UUID_BYTES (arg) LIBXL__UUID_BYTES(arg.uuid_raw) +#else #error "Please update libxl_uuid.h for your OS"
Signature · 7 lines
1.7.7.5 (Apple Git-26) _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Quoted 11 lines · Roger Pau Monne
Add the FreeBSD specific uuid implementation. Since
uuid_tis not defined as an array, but as a struct on FreeBSD, use a union with a array in order to be able to return the uuid as a bytearray.Also, added a libxl internal compile time assert macro, that is used to assert that the size of
uuid_tis the same as the union used in libxl.Signed-off-by Roger Pau Monné <[email protected]>Cc Ian Jackson <[email protected]>Cc Ian Campbell <[email protected]>
Acked + applied, thanks.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel