debuggers.hg

view tools/libxl/libxl_uuid.h @ 22855:1d1eec7e1fb4

xl: Perform minimal validation of virtual disk file while parsing config file

This patch performs some very basic validation on the virtual disk
file passed through the config file. This validation ensures that we
don't go too far with the initialization like spawn qemu and more
while there could be some potentially fundamental issues.

[ Patch fixed up to work with PHYSTYPE_EMPTY 22808:6ec61438713a -iwj ]

Signed-off-by: Kamala Narasimhan <kamala.narasimhan@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>
author Kamala Narasimhan <kamala.narasimhan@gmail.com>
date Tue Jan 25 18:09:49 2011 +0000 (2011-01-25)
parents 22366e13f76d
children
line source
1 /*
2 * Copyright (C) 2008,2010 Citrix Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published
6 * by the Free Software Foundation; version 2.1 only. with the special
7 * exception on linking described in file LICENSE.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
13 */
15 #ifndef __LIBXL_UUID_H__
16 #define __LIBXL_UUID_H__
18 #define LIBXL_UUID_FMT "%02hhx%02hhx%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx"
19 #define LIBXL__UUID_BYTES(uuid) uuid[0], uuid[1], uuid[2], uuid[3], \
20 uuid[4], uuid[5], uuid[6], uuid[7], \
21 uuid[8], uuid[9], uuid[10], uuid[11], \
22 uuid[12], uuid[13], uuid[14], uuid[15]
24 #if defined(__linux__)
26 #include <uuid/uuid.h>
28 typedef struct {
29 uuid_t uuid;
30 } libxl_uuid;
32 #define LIBXL_UUID_BYTES(arg) LIBXL__UUID_BYTES(((uint8_t *)arg.uuid))
34 static inline int libxl_uuid_is_nil(libxl_uuid *uuid)
35 {
36 return uuid_is_null(uuid->uuid);
37 }
39 static inline void libxl_uuid_generate(libxl_uuid *uuid)
40 {
41 uuid_generate(uuid->uuid);
42 }
44 static inline int libxl_uuid_from_string(libxl_uuid *uuid, const char *in)
45 {
46 return uuid_parse(in, uuid->uuid);
47 }
49 static inline void libxl_uuid_copy(libxl_uuid *dst, libxl_uuid *src)
50 {
51 uuid_copy(dst->uuid, src->uuid);
52 }
54 static inline void libxl_uuid_clear(libxl_uuid *uuid)
55 {
56 uuid_clear(uuid->uuid);
57 }
59 static inline int libxl_uuid_compare(libxl_uuid *uuid1, libxl_uuid *uuid2)
60 {
61 return uuid_compare(uuid1->uuid, uuid2->uuid);
62 }
64 static inline uint8_t *libxl_uuid_bytearray(libxl_uuid *uuid)
65 {
66 return uuid->uuid;
67 }
69 #elif defined(__NetBSD__)
71 #include <uuid.h>
72 #include <string.h>
73 #include <stdlib.h>
74 #include <stdio.h>
75 #include <assert.h>
77 #define LIBXL_UUID_BYTES(arg) LIBXL__UUID_BYTES(arg.uuid)
79 typedef struct {
80 uint8_t uuid[16];
81 } libxl_uuid;
83 static inline int libxl_uuid_is_nil(libxl_uuid *uuid)
84 {
85 uint32_t status;
86 return uuid_is_nil((uuid_t *)uuid->uuid, &status);
87 }
89 static inline void libxl_uuid_generate(libxl_uuid *uuid)
90 {
91 uint32_t status;
92 uuid_create((uuid_t *)uuid->uuid, &status);
93 assert(status == uuid_s_ok);
94 }
96 #define LIBXL__UUID_PTRS(uuid) &uuid[0], &uuid[1], &uuid[2], &uuid[3], \
97 &uuid[4], &uuid[5], &uuid[6], &uuid[7], \
98 &uuid[8], &uuid[9], &uuid[10],&uuid[11], \
99 &uuid[12],&uuid[13],&uuid[14],&uuid[15]
100 static inline int libxl_uuid_from_string(libxl_uuid *uuid, const char *in)
101 {
102 if ( sscanf(in, LIBXL_UUID_FMT, LIBXL__UUID_PTRS(uuid->uuid)) != sizeof(uuid->uuid) )
103 return -1;
104 return 0;
105 }
106 #undef LIBXL__UUID_PTRS
108 static inline void libxl_uuid_copy(libxl_uuid *dst, libxl_uuid *src)
109 {
110 memcpy(dst->uuid, src->uuid, sizeof(dst->uuid));
111 }
113 static inline void libxl_uuid_clear(libxl_uuid *uuid)
114 {
115 memset(uuid->uuid, 0, sizeof(uuid->uuid));
116 }
118 static inline int libxl_uuid_compare(libxl_uuid *uuid1, libxl_uuid *uuid2)
119 {
120 return memcmp(uuid1->uuid, uuid2->uuid, sizeof(uuid1->uuid));
121 }
123 static inline uint8_t *libxl_uuid_bytearray(libxl_uuid *uuid)
124 {
125 return uuid->uuid;
126 }
128 #else
130 #error "Please update libxl_uuid.h for your OS"
132 #endif
134 #endif /* __LIBXL_UUID_H__ */