From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48048) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dpif2-0002En-5L for guix-patches@gnu.org; Wed, 06 Sep 2017 18:19:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dpif1-0000TM-2O for guix-patches@gnu.org; Wed, 06 Sep 2017 18:19:04 -0400 Received: from debbugs.gnu.org ([208.118.235.43]:44861) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dpif0-0000TI-W5 for guix-patches@gnu.org; Wed, 06 Sep 2017 18:19:03 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1dpif0-0005lg-QA for guix-patches@gnu.org; Wed, 06 Sep 2017 18:19:02 -0400 Subject: [bug#28377] [PATCH 02/10] file-systems: Add UUID type dictionaries. Resent-Message-ID: From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Date: Thu, 7 Sep 2017 00:17:48 +0200 Message-Id: <20170906221756.17024-2-ludo@gnu.org> In-Reply-To: <20170906221756.17024-1-ludo@gnu.org> References: <20170906221756.17024-1-ludo@gnu.org> List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+kyle=kyleam.com@gnu.org Sender: "Guix-patches" To: 28377@debbugs.gnu.org * gnu/build/file-systems.scm (uuid->string): Rename to... (dce-uuid->string): ... this. (string->uuid): Rename to... (string->dce-uuid): ... this. (vhashq): New macro. (%uuid-parsers, %uuid-printers): New variables. (uuid->string, string->uuid): New procedures. --- gnu/build/file-systems.scm | 49 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 43 insertions(+), 6 deletions(-) diff --git a/gnu/build/file-systems.scm b/gnu/build/file-systems.scm index 203fbdfff..fbaf15895 100644 --- a/gnu/build/file-systems.scm +++ b/gnu/build/file-systems.scm @@ -28,6 +28,7 @@ #:use-module (ice-9 rdelim) #:use-module (ice-9 format) #:use-module (ice-9 regex) + #:use-module (ice-9 vlist) #:use-module (system foreign) #:autoload (system repl repl) (start-repl) #:use-module (srfi srfi-1) @@ -42,7 +43,9 @@ canonicalize-device-spec uuid->string + dce-uuid->string string->uuid + string->dce-uuid string->iso9660-uuid string->ext2-uuid string->ext3-uuid @@ -516,7 +519,7 @@ were found." (define-syntax %network-byte-order (identifier-syntax (endianness big))) -(define (uuid->string uuid) +(define (dce-uuid->string uuid) "Convert UUID, a 16-byte bytevector, to its string representation, something like \"6b700d61-5550-48a1-874c-a3d86998990e\"." ;; See . @@ -532,7 +535,7 @@ like \"6b700d61-5550-48a1-874c-a3d86998990e\"." ;; The regexp of a UUID. (make-regexp "^([[:xdigit:]]{8})-([[:xdigit:]]{4})-([[:xdigit:]]{4})-([[:xdigit:]]{4})-([[:xdigit:]]{12})$")) -(define (string->uuid str) +(define (string->dce-uuid str) "Parse STR as a DCE UUID (see ) and return its contents as a 16-byte bytevector. Return #f if STR is not a valid UUID representation." @@ -562,10 +565,44 @@ UUID representation." (time-low 4) (time-mid 2) (time-hi 2) (clock-seq 2) (node 6))))))) -(define string->ext2-uuid string->uuid) -(define string->ext3-uuid string->uuid) -(define string->ext4-uuid string->uuid) -(define string->btrfs-uuid string->uuid) +(define string->ext2-uuid string->dce-uuid) +(define string->ext3-uuid string->dce-uuid) +(define string->ext4-uuid string->dce-uuid) +(define string->btrfs-uuid string->dce-uuid) + +(define-syntax vhashq + (syntax-rules (=>) + ((_) + vlist-null) + ((_ (key others ... => value) rest ...) + (vhash-consq key value + (vhashq (others ... => value) rest ...))) + ((_ (=> value) rest ...) + (vhashq rest ...)))) + +(define %uuid-parsers + (vhashq + ('dce 'ext2 'ext3 'ext4 'btrfs 'luks => string->dce-uuid) + ('iso9660 => string->iso9660-uuid))) + +(define %uuid-printers + (vhashq + ('dce 'ext2 'ext3 'ext4 'btrfs 'luks => dce-uuid->string) + ('iso9660 => iso9660-uuid->string) + ('fat32 'fat => fat32-uuid->string))) + +(define* (string->uuid str #:key (type 'dce)) + "Parse STR as a UUID of the given TYPE. On success, return the +corresponding bytevector; otherwise return #f." + (match (vhash-assq type %uuid-parsers) + (#f #f) + ((_ . (? procedure? parse)) (parse str)))) + +(define* (uuid->string bv #:key (type 'dce)) + "Convert BV, a bytevector, to the UUID string representation for TYPE." + (match (vhash-assq type %uuid-printers) + (#f #f) + ((_ . (? procedure? unparse)) (unparse bv)))) (define* (canonicalize-device-spec spec #:optional (title 'any)) -- 2.14.1