ia64/xen-unstable

view tools/blktap2/include/blk_uuid.h @ 19832:f1fec38c8228

blktap2: Further netbsd build fixes.

Signed-off-by: Christoph Egger <Christoph.Egger@amd.com>
Signed-off-by: Keir Fraser <keir.fraser@citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Wed Jun 24 14:03:20 2009 +0100 (2009-06-24)
parents
children f3a909c8e8e6
line source
1 /* Copyright (c) 2008, XenSource Inc.
2 * All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 * * Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above copyright
9 * notice, this list of conditions and the following disclaimer in the
10 * documentation and/or other materials provided with the distribution.
11 * * Neither the name of XenSource Inc. nor the names of its contributors
12 * may be used to endorse or promote products derived from this software
13 * without specific prior written permission.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
19 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27 #ifndef __BLKTAP2_UUID_H__
28 #define __BLKTAP2_UUID_H__
30 #if defined(__linux__) || defined(__Linux__)
32 #include <uuid/uuid.h>
34 typedef struct {
35 uuid_t uuid;
36 } blk_uuid_t;
38 static inline int blk_uuid_is_nil(blk_uuid_t *uuid)
39 {
40 return uuid_is_null(uuid->uuid);
41 }
43 static inline void blk_uuid_generate(blk_uuid_t *uuid)
44 {
45 uuid_generate(uuid->uuid);
46 }
48 static inline void blk_uuid_to_string(blk_uuid_t *uuid, char *out)
49 {
50 uuid_unparse(uuid->uuid, out);
51 }
53 static inline void blk_uuid_from_string(blk_uuid_t *uuid, const char *in)
54 {
55 uuid_parse(in, uuid->uuid);
56 }
58 static inline void blk_uuid_copy(blk_uuid_t *dst, blk_uuid_t *src)
59 {
60 uuid_copy(dst->uuid, src->uuid);
61 }
63 static inline void blk_uuid_clear(blk_uuid_t *uuid)
64 {
65 uuid_clear(uuid->uuid);
66 }
68 static inline int blk_uuid_compare(blk_uuid_t *uuid1, blk_uuid_t *uuid2)
69 {
70 return uuid_compare(uuid1->uuid, uuid2->uuid);
71 }
73 #elif defined(__NetBSD__)
75 #include <uuid.h>
76 #include <string.h>
78 typedef uuid_t blk_uuid_t;
80 static inline int blk_uuid_is_nil(blk_uuid_t *uuid)
81 {
82 uint32_t status;
83 return uuid_is_nil((uuid_t *)uuid, &status);
84 }
86 static inline void blk_uuid_generate(blk_uuid_t *uuid)
87 {
88 uint32_t status;
89 uuid_create((uuid_t *)uuid, &status);
90 }
92 static inline void blk_uuid_to_string(blk_uuid_t *uuid, char *out)
93 {
94 uint32_t status;
95 uuid_to_string((uuid_t *)uuid, &out, &status);
96 }
98 static inline void blk_uuid_from_string(blk_uuid_t *uuid, const char *in)
99 {
100 uint32_t status;
101 uuid_from_string(in, (uuid_t *)uuid, &status);
102 }
104 static inline void blk_uuid_copy(blk_uuid_t *dst, blk_uuid_t *src)
105 {
106 memcpy((uuid_t *)dst, (uuid_t *)src, sizeof(uuid_t));
107 }
109 static inline void blk_uuid_clear(blk_uuid_t *uuid)
110 {
111 memset((uuid_t *)uuid, 0, sizeof(uuid_t));
112 }
114 static inline int blk_uuid_compare(blk_uuid_t *uuid1, blk_uuid_t *uuid2)
115 {
116 uint32_t status;
117 return uuid_compare((uuid_t *)uuid1, (uuid_t *)uuid2, &status);
118 }
120 #else
122 #error "Please update blk_uuid.h for your OS"
124 #endif
126 #endif /* __BLKTAP2_UUID_H__ */