From 8a7d81a5e23c4d59fbabf2550db32d4ba5572e4b Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Fri, 22 Sep 2017 18:25:21 +0200 Subject: uuid: Add a parser for FAT32 UUIDs. * gnu/system/uuid.scm (%fat32-uuid-rx): New variable. (string->fat32-uuid): New procedure. (%uuid-parsers): Add it. * tests/uuid.scm ("uuid, FAT32, format preserved"): New test. --- gnu/system/uuid.scm | 18 ++++++++++++++++++ tests/uuid.scm | 4 ++++ 2 files changed, 22 insertions(+) diff --git a/gnu/system/uuid.scm b/gnu/system/uuid.scm index 1dd6a11339..6470abb8cc 100644 --- a/gnu/system/uuid.scm +++ b/gnu/system/uuid.scm @@ -41,6 +41,7 @@ (define-module (gnu system uuid) string->ext3-uuid string->ext4-uuid string->btrfs-uuid + string->fat32-uuid iso9660-uuid->string ;; XXX: For lack of a better place. @@ -175,6 +176,22 @@ (define (fat32-uuid->string uuid) (low (bytevector-uint-ref uuid 2 %fat32-endianness 2))) (format #f "~:@(~x-~x~)" low high))) +(define %fat32-uuid-rx + (make-regexp "^([[:xdigit:]]{4})-([[:xdigit:]]{4})$")) + +(define (string->fat32-uuid str) + "Parse STR, which is in FAT32 format, and return a bytevector or #f." + (match (regexp-exec %fat32-uuid-rx str) + (#f + #f) + (rx-match + (uint-list->bytevector (list (string->number + (match:substring rx-match 2) 16) + (string->number + (match:substring rx-match 1) 16)) + %fat32-endianness + 2)))) + ;;; ;;; Generic interface. @@ -198,6 +215,7 @@ (define-syntax vhashq (define %uuid-parsers (vhashq ('dce 'ext2 'ext3 'ext4 'btrfs 'luks => string->dce-uuid) + ('fat32 'fat => string->fat32-uuid) ('iso9660 => string->iso9660-uuid))) (define %uuid-printers diff --git a/tests/uuid.scm b/tests/uuid.scm index c2f15de996..aacce77233 100644 --- a/tests/uuid.scm +++ b/tests/uuid.scm @@ -53,4 +53,8 @@ (define-module (test-uuid) "1970-01-01-17-14-42-99" (uuid->string (uuid "1970-01-01-17-14-42-99" 'iso9660))) +(test-equal "uuid, FAT32, format preserved" + "1234-ABCD" + (uuid->string (uuid "1234-abcd" 'fat32))) + (test-end) -- cgit v1.2.3