From: Richard W.M. Jones <rjones@redhat.com>
Date: Mon, 13 Jun 2011 17:58:53 +0000 (+0100)
Subject: generator: Rewrite UUIDs that begin with zero byte.
X-Git-Tag: 1.8.9~9
X-Git-Url: http://git.annexia.org/?a=commitdiff_plain;h=ef9f07095f3f4b26dcc36305bfb348ecebc5e735;p=libguestfs.git

generator: Rewrite UUIDs that begin with zero byte.

In util-linux <= 2.19, mkswap -U cannot handle the first byte of the
UUID being zero, so we artificially rewrite such UUIDs.

See: http://article.gmane.org/gmane.linux.utilities.util-linux-ng/4273
(cherry picked from commit 4ee190628bc05f0c8fad1f6d9c3e85619a91e8b8)
---

diff --git a/generator/generator_utils.ml b/generator/generator_utils.ml
index f62b195..4180c0d 100644
--- a/generator/generator_utils.ml
+++ b/generator/generator_utils.ml
@@ -55,6 +55,14 @@ let string_of_errcode = function
  *)
 let uuidgen () =
   let s = Digest.to_hex (Digest.file "generator/generator_actions.ml") in
+
+  (* In util-linux <= 2.19, mkswap -U cannot handle the first byte of
+   * the UUID being zero, so we artificially rewrite such UUIDs.
+   * http://article.gmane.org/gmane.linux.utilities.util-linux-ng/4273
+   *)
+  if s.[0] = '0' && s.[1] = '0' then
+    s.[0] <- '1';
+
   String.sub s 0 8 ^ "-"
   ^ String.sub s 8 4 ^ "-"
   ^ String.sub s 12 4 ^ "-"