]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/mini-os.git/commitdiff
minios: add xenbus_read_uuid
authorMatthew Fioravante <matthew.fioravante@jhuapl.edu>
Tue, 13 Nov 2012 10:46:57 +0000 (10:46 +0000)
committerMatthew Fioravante <matthew.fioravante@jhuapl.edu>
Tue, 13 Nov 2012 10:46:57 +0000 (10:46 +0000)
Similar to xenbus_read_integer, this function reads a xenstore path
and parses it as a uuid. See include/xenbus.h for details.

Signed-off-by: Matthew Fioravante <matthew.fioravante@jhuapl.edu>
Acked-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Committed-by: Ian Campbell <ian.campbell@citrix.com>
include/xenbus.h
xenbus/xenbus.c

index cd6316ebafad7d1c182f0dd90a27de57dffe4dfe..d3bb7afeab4d5ae958968c910bafb2c56cce4650 100644 (file)
@@ -95,6 +95,10 @@ char *xenbus_transaction_end(xenbus_transaction_t, int abort,
 /* Read path and parse it as an integer.  Returns -1 on error. */
 int xenbus_read_integer(const char *path);
 
+/* Read path and parse it as 16 byte uuid. Returns 1 if
+ * read and parsing were successful, 0 if not */
+int xenbus_read_uuid(const char* path, unsigned char uuid[16]);
+
 /* Contraction of snprintf and xenbus_write(path/node). */
 char* xenbus_printf(xenbus_transaction_t xbt,
                                   const char* node, const char* path,
index 8c899f3a405960b0429142e613dfedcba6012efd..ee1691b85815cddfac758a686d70a6ea1b50b370 100644 (file)
@@ -719,6 +719,33 @@ int xenbus_read_integer(const char *path)
     return t;
 }
 
+int xenbus_read_uuid(const char* path, unsigned char uuid[16]) {
+   char * res, *buf;
+   res = xenbus_read(XBT_NIL, path, &buf);
+   if(res) {
+      printk("Failed to read %s.\n", path);
+      free(res);
+      return 0;
+   }
+   if(strlen(buf) != ((2*16)+4) /* 16 hex bytes and 4 hyphens */
+         || sscanf(buf,
+            "%2hhx%2hhx%2hhx%2hhx-"
+            "%2hhx%2hhx-"
+            "%2hhx%2hhx-"
+            "%2hhx%2hhx-"
+            "%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx",
+            uuid, uuid + 1, uuid + 2, uuid + 3,
+            uuid + 4, uuid + 5, uuid + 6, uuid + 7,
+            uuid + 8, uuid + 9, uuid + 10, uuid + 11,
+            uuid + 12, uuid + 13, uuid + 14, uuid + 15) != 16) {
+      printk("Xenbus path %s value %s is not a uuid!\n", path, buf);
+      free(buf);
+      return 0;
+   }
+   free(buf);
+   return 1;
+}
+
 char* xenbus_printf(xenbus_transaction_t xbt,
                                   const char* node, const char* path,
                                   const char* fmt, ...)