From patchwork Thu Nov 23 14:56:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felix Lechner X-Patchwork-Id: 56759 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id C891427BBEA; Thu, 23 Nov 2023 15:00:04 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,SPF_HELO_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 917C027BBE2 for ; Thu, 23 Nov 2023 15:00:03 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r6BBQ-0007yZ-0j; Thu, 23 Nov 2023 10:00:00 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r6BBO-0007xr-M8 for guix-patches@gnu.org; Thu, 23 Nov 2023 09:59:58 -0500 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r6BBO-0003k9-De for guix-patches@gnu.org; Thu, 23 Nov 2023 09:59:58 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1r6BBS-0007iV-7a for guix-patches@gnu.org; Thu, 23 Nov 2023 10:00:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#64259] [PATCH v2 1/2] Offer an mdadm variant of uuids. References: In-Reply-To: Resent-From: Felix Lechner Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Thu, 23 Nov 2023 15:00:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 64259 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 64259@debbugs.gnu.org Cc: Ludovic =?utf-8?q?Court=C3=A8s?= , Felix Lechner Received: via spool by 64259-submit@debbugs.gnu.org id=B64259.170075155129559 (code B ref 64259); Thu, 23 Nov 2023 15:00:02 +0000 Received: (at 64259) by debbugs.gnu.org; 23 Nov 2023 14:59:11 +0000 Received: from localhost ([127.0.0.1]:34583 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r6BAd-0007gh-1T for submit@debbugs.gnu.org; Thu, 23 Nov 2023 09:59:11 -0500 Received: from sail-ipv4.us-core.com ([208.82.101.137]:34494) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r6BAa-0007gY-4G for 64259@debbugs.gnu.org; Thu, 23 Nov 2023 09:59:09 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; s=2017; bh=eAdH9YAxLlQDx43 nOb2mHRSAJ6iwa27eVqrldvINybo=; h=date:subject:cc:to:from; d=lease-up.com; b=lbrpZWlWWTk3Sp3GrLyOYpBuStDXrEEKmp/HAEL8B7ebT7pZmPY8 JScvGnhPZn/dr6DIV7wrgyr3Xm/s8L1lYYPXttATv9rIasm3i7kn22X0LA1uT6sVEnLPrL jgDt+a4x1tJsoxQXTezsbng4WJJxTbt6XQ8wsm0jfDkM7gnPw= Received: by sail-ipv4.us-core.com (OpenSMTPD) with ESMTPSA id a8ea84f7 (TLSv1.3:TLS_CHACHA20_POLY1305_SHA256:256:NO); Thu, 23 Nov 2023 14:59:02 +0000 (UTC) Received: from localhost (localhost [local]) by localhost (OpenSMTPD) with ESMTPA id 16c8b611; Thu, 23 Nov 2023 14:59:02 +0000 (UTC) Date: Thu, 23 Nov 2023 06:56:59 -0800 Message-ID: <9b4c88707c00531fa2a43e5172d1fc0c4f4af3d9.1700751420.git.felix.lechner@lease-up.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Felix Lechner X-ACL-Warn: , Felix Lechner via Guix-patches X-Patchwork-Original-From: Felix Lechner via Guix-patches via From: Felix Lechner Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches --- gnu/system/uuid.scm | 46 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-) base-commit: 5283d24062be62f59ff9f14fa7095ebcfcb7a9a4 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 +), which looks something like +\"6b700d61-5550-48a1-874c-a3d86998990e\"." ;; See . (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 ) 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) "-")))) + +;;; +;;; 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 . + (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)))) + ;;; ;;; 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))