all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Felix Lechner via Guix-patches via <guix-patches@gnu.org>
To: 64259@debbugs.gnu.org
Cc: "Ludovic Courtès" <ludo@gnu.org>,
	"Felix Lechner" <felix.lechner@lease-up.com>
Subject: [bug#64259] [PATCH v2 1/2] Offer an mdadm variant of uuids.
Date: Thu, 23 Nov 2023 06:56:59 -0800	[thread overview]
Message-ID: <9b4c88707c00531fa2a43e5172d1fc0c4f4af3d9.1700751420.git.felix.lechner@lease-up.com> (raw)
In-Reply-To: <cover.1687571974.git.felix.lechner@lease-up.com>

---
 gnu/system/uuid.scm | 46 +++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 42 insertions(+), 4 deletions(-)

diff --git a/gnu/system/uuid.scm b/gnu/system/uuid.scm
index 8f967387ad..dc8bb3f7b7 100644
--- a/gnu/system/uuid.scm
+++ b/gnu/system/uuid.scm
@@ -82,8 +82,9 @@ (define-syntax %network-byte-order
   (identifier-syntax (endianness big)))
 
 (define (dce-uuid->string uuid)
-  "Convert UUID, a 16-byte bytevector, to its string representation, something
-like \"6b700d61-5550-48a1-874c-a3d86998990e\"."
+  "Convert UUID, a 16-byte bytevector, to its DCE string representation (see
+<https://tools.ietf.org/html/rfc4122>), which looks something like
+\"6b700d61-5550-48a1-874c-a3d86998990e\"."
   ;; See <https://tools.ietf.org/html/rfc4122>.
   (let ((time-low  (bytevector-uint-ref uuid 0 %network-byte-order 4))
         (time-mid  (bytevector-uint-ref uuid 4 %network-byte-order 2))
@@ -93,7 +94,7 @@ (define (dce-uuid->string uuid)
     (format #f "~8,'0x-~4,'0x-~4,'0x-~4,'0x-~12,'0x"
             time-low time-mid time-hi clock-seq node)))
 
-(define %uuid-rx
+(define %dce-uuid-rx
   ;; The regexp of a UUID.
   (make-regexp "^([[:xdigit:]]{8})-([[:xdigit:]]{4})-([[:xdigit:]]{4})-([[:xdigit:]]{4})-([[:xdigit:]]{12})$"))
 
@@ -101,7 +102,7 @@ (define (string->dce-uuid str)
   "Parse STR as a DCE UUID (see <https://tools.ietf.org/html/rfc4122>) and
 return its contents as a 16-byte bytevector.  Return #f if STR is not a valid
 UUID representation."
-  (and=> (regexp-exec %uuid-rx str)
+  (and=> (regexp-exec %dce-uuid-rx str)
          (lambda (match)
            (letrec-syntax ((hex->number
                             (syntax-rules ()
@@ -167,6 +168,41 @@ (define (digits->string bytes)
          (parts (list year month day hour minute second hundredths)))
     (string-append (string-join (map digits->string parts) "-"))))
 
+\f
+;;;
+;;; Mdadm.
+;;;
+
+(define (mdadm-uuid->string uuid)
+  "Convert UUID, a 16-byte bytevector, to its Mdadm string representation,
+which looks something like \"6b700d61:555048a1:874ca3d8:6998990e\"."
+  ;; See <https://tools.ietf.org/html/rfc4122>.
+  (format #f "~8,'0x:~8,'0x:~8,'0x:~8,'0x"
+          (bytevector-uint-ref uuid 0 %network-byte-order 4)
+          (bytevector-uint-ref uuid 4 %network-byte-order 4)
+          (bytevector-uint-ref uuid 8 %network-byte-order 4)
+          (bytevector-uint-ref uuid 12 %network-byte-order 4)))
+
+(define %mdadm-uuid-rx
+  (make-regexp "^([[:xdigit:]]{8}):([[:xdigit:]]{8}):([[:xdigit:]]{8}):([[:xdigit:]]{8})$"))
+
+(define (string->mdadm-uuid str)
+  "Parse STR, which is in Mdadm format, and return a bytevector or #f."
+  (match (regexp-exec %mdadm-uuid-rx str)
+    (#f
+     #f)
+    (rx-match
+     (uint-list->bytevector (list (string->number
+                                   (match:substring rx-match 1) 16)
+                                  (string->number
+                                   (match:substring rx-match 2) 16)
+                                  (string->number
+                                   (match:substring rx-match 3) 16)
+                                  (string->number
+                                   (match:substring rx-match 4) 16))
+                            %network-byte-order
+                            4))))
+
 \f
 ;;;
 ;;; FAT32/FAT16.
@@ -259,6 +295,7 @@ (define %uuid-parsers
    ('dce 'ext2 'ext3 'ext4 'bcachefs 'btrfs 'f2fs 'jfs 'xfs 'luks
          => string->dce-uuid)
    ('fat32 'fat16 'fat => string->fat-uuid)
+   ('mdadm => string->mdadm-uuid)
    ('ntfs => string->ntfs-uuid)
    ('iso9660 => string->iso9660-uuid)))
 
@@ -268,6 +305,7 @@ (define %uuid-printers
          => dce-uuid->string)
    ('iso9660 => iso9660-uuid->string)
    ('fat32 'fat16 'fat => fat-uuid->string)
+   ('mdadm => mdadm-uuid->string)
    ('ntfs => ntfs-uuid->string)))
 
 (define* (string->uuid str #:optional (type 'dce))

base-commit: 5283d24062be62f59ff9f14fa7095ebcfcb7a9a4
-- 
2.41.0





  parent reply	other threads:[~2023-11-23 15:00 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-24  2:05 [bug#64259] [PATCH 0/2] Allow booting of degraded software RAID/MD arrays Felix Lechner via Guix-patches via
2023-06-24  2:07 ` [bug#64259] [PATCH 1/2] Offer an mdadm variant of uuids Felix Lechner via Guix-patches via
2023-06-24  2:07 ` [bug#64259] [PATCH 2/2] Provide md-array-device-mapping to start MD arrays via UUID or name Felix Lechner via Guix-patches via
2023-10-20 21:55   ` Ludovic Courtès
2023-10-22 17:44     ` Felix Lechner via Guix-patches via
2024-01-18 14:39       ` Andreas Enge
2024-01-18 16:46         ` Felix Lechner via Guix-patches via
2024-01-18 16:51           ` Andreas Enge
2023-11-23 14:56 ` Felix Lechner via Guix-patches via [this message]
2023-11-23 14:57   ` [bug#64259] [PATCH v2 " Felix Lechner via Guix-patches via

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9b4c88707c00531fa2a43e5172d1fc0c4f4af3d9.1700751420.git.felix.lechner@lease-up.com \
    --to=guix-patches@gnu.org \
    --cc=64259@debbugs.gnu.org \
    --cc=felix.lechner@lease-up.com \
    --cc=ludo@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.