ia64/xen-unstable

view tools/blktap2/include/blk_uuid.h @ 19833:f3a909c8e8e6

blktap2: A final few NetBSD fixes

Signed-off-by: Christoph Egger <Christoph.Egger@amd.com>
author Keir Fraser <keir.fraser@citrix.com>
date Wed Jun 24 15:24:53 2009 +0100 (2009-06-24)
parents f1fec38c8228
children
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, size_t size)
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>
77 #include <stdlib.h>
79 typedef uuid_t blk_uuid_t;
81 static inline int blk_uuid_is_nil(blk_uuid_t *uuid)
82 {
83 uint32_t status;
84 return uuid_is_nil((uuid_t *)uuid, &status);
85 }
87 static inline void blk_uuid_generate(blk_uuid_t *uuid)
88 {
89 uint32_t status;
90 uuid_create((uuid_t *)uuid, &status);
91 }
93 static inline void blk_uuid_to_string(blk_uuid_t *uuid, char *out, size_t size)
94 {
95 uint32_t status;
96 char *_out = NULL;
97 uuid_to_string((uuid_t *)uuid, &_out, &status);
98 strlcpy(out, _out, size);
99 free(_out);
100 }
102 static inline void blk_uuid_from_string(blk_uuid_t *uuid, const char *in)
103 {
104 uint32_t status;
105 uuid_from_string(in, (uuid_t *)uuid, &status);
106 }
108 static inline void blk_uuid_copy(blk_uuid_t *dst, blk_uuid_t *src)
109 {
110 memcpy((uuid_t *)dst, (uuid_t *)src, sizeof(uuid_t));
111 }
113 static inline void blk_uuid_clear(blk_uuid_t *uuid)
114 {
115 memset((uuid_t *)uuid, 0, sizeof(uuid_t));
116 }
118 static inline int blk_uuid_compare(blk_uuid_t *uuid1, blk_uuid_t *uuid2)
119 {
120 uint32_t status;
121 return uuid_compare((uuid_t *)uuid1, (uuid_t *)uuid2, &status);
122 }
124 #else
126 #error "Please update blk_uuid.h for your OS"
128 #endif
130 #endif /* __BLKTAP2_UUID_H__ */