unofficial mirror of bug-guix@gnu.org 
 help / color / mirror / code / Atom feed
From: Maxim Cournoyer <maxim.cournoyer@gmail.com>
To: 40998@debbugs.gnu.org
Cc: Maxim Cournoyer <maxim.cournoyer@gmail.com>
Subject: bug#40998: [PATCH 1/4] system: Add a version field to the <boot-parameters> record.
Date: Mon, 28 Feb 2022 17:50:43 -0500	[thread overview]
Message-ID: <20220228225047.11105-1-maxim.cournoyer@gmail.com> (raw)
In-Reply-To: <handler.40998.B40998.164608474925197@debbugs.gnu.org>

This version field exposes the (already present) version information of a boot
parameters file.

* gnu/system.scm (%boot-parameters-version): New variable.
(<boot-parameters>)[version]: New field.
(read-boot-parameters): Use it.
(operating-system-boot-parameters-file): Likewise.
* tests/boot-parameters.scm (test-read-boot-parameters): Use
%boot-parameters-version as the default version value in the template.
---
 gnu/system.scm            | 20 ++++++++++++++++----
 tests/boot-parameters.scm |  2 +-
 2 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/gnu/system.scm b/gnu/system.scm
index cc925de16f..9ae158dea6 100644
--- a/gnu/system.scm
+++ b/gnu/system.scm
@@ -9,7 +9,7 @@
 ;;; Copyright © 2020 Danny Milosavljevic <dannym@scratchpost.org>
 ;;; Copyright © 2020, 2021 Brice Waegeneire <brice@waegenei.re>
 ;;; Copyright © 2020 Florian Pelz <pelzflorian@pelzflorian.de>
-;;; Copyright © 2020 Maxim Cournoyer <maxim.cournoyer@gmail.com>
+;;; Copyright © 2020, 2022 Maxim Cournoyer <maxim.cournoyer@gmail.com>
 ;;; Copyright © 2020 Jan (janneke) Nieuwenhuizen <jannek@gnu.org>
 ;;; Copyright © 2020 Efraim Flashner <efraim@flashner.co.il>
 ;;; Copyright © 2021 Maxime Devos <maximedevos@telenet.be>
@@ -161,6 +161,8 @@ (define-module (gnu system)
             boot-parameters-kernel-arguments
             boot-parameters-initrd
             boot-parameters-multiboot-modules
+            boot-parameters-version
+            %boot-parameters-version
             read-boot-parameters
             read-boot-parameters-file
             boot-parameters->menu-entry
@@ -295,6 +297,8 @@ (define (operating-system-kernel-arguments os root-device)
 ;;; Boot parameters
 ;;;
 
+(define %boot-parameters-version 0)
+
 (define-record-type* <boot-parameters>
   boot-parameters make-boot-parameters boot-parameters?
   (label            boot-parameters-label)
@@ -322,7 +326,9 @@ (define-record-type* <boot-parameters>
   (kernel           boot-parameters-kernel)
   (kernel-arguments boot-parameters-kernel-arguments)
   (initrd           boot-parameters-initrd)
-  (multiboot-modules boot-parameters-multiboot-modules))
+  (multiboot-modules boot-parameters-multiboot-modules)
+  (version          boot-parameters-version  ;positive integer
+                    (default %boot-parameters-version)))
 
 (define (ensure-not-/dev device)
   "If DEVICE starts with a slash, return #f.  This is meant to filter out
@@ -359,12 +365,18 @@ (define uuid-sexp->uuid
        (warning (G_ "unrecognized uuid ~a at '~a'~%") x (port-filename port))
        #f)))
 
+  ;; New versions are not backward-compatible, so only accept past and current
+  ;; versions, not future ones.
+  (define (version? n)
+    (member n (iota (1+ %boot-parameters-version))))
+
   (match (read port)
-    (('boot-parameters ('version 0)
+    (('boot-parameters ('version (? version? version))
                        ('label label) ('root-device root)
                        ('kernel kernel)
                        rest ...)
      (boot-parameters
+      (version version)
       (label label)
       (root-device (device-sexp->device root))
 
@@ -1500,7 +1512,7 @@ (define* (operating-system-boot-parameters-file os
                    system-kernel-arguments?)))
      (scheme-file "parameters"
                   #~(boot-parameters
-                     (version 0)
+                     (version #$(boot-parameters-version params))
                      (label #$(boot-parameters-label params))
                      (root-device
                       #$(device->sexp
diff --git a/tests/boot-parameters.scm b/tests/boot-parameters.scm
index b2799d0596..d4b680df2e 100644
--- a/tests/boot-parameters.scm
+++ b/tests/boot-parameters.scm
@@ -101,7 +101,7 @@ (define (quote-uuid uuid)
 ;; Call read-boot-parameters with the desired string as input.
 (define* (test-read-boot-parameters
           #:key
-          (version 0)
+          (version %boot-parameters-version)
           (bootloader-name 'grub)
           (bootloader-menu-entries '())
           (label %default-label)
-- 
2.34.0





       reply	other threads:[~2022-02-28 22:52 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <handler.40998.B40998.164608474925197@debbugs.gnu.org>
2022-02-28 22:50 ` Maxim Cournoyer [this message]
2022-02-28 22:50   ` bug#40998: [PATCH 2/4] system: Streamline operating-system-boot-parameters-file a bit Maxim Cournoyer
2022-03-01  9:17     ` Ludovic Courtès
2022-02-28 22:50   ` bug#40998: [PATCH 3/4] initrd: Use non-hyphenated kernel command-line parameter names Maxim Cournoyer
2022-02-28 22:50   ` bug#40998: [PATCH 4/4] initrd: Honor rootfstype and rootflags command-line parameters Maxim Cournoyer
2022-03-01  9:16   ` bug#40998: [PATCH 1/4] system: Add a version field to the <boot-parameters> record Ludovic Courtès
2022-03-01 14:40     ` Maxim Cournoyer
2022-03-01 18:32       ` Maxim Cournoyer

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

  List information: https://guix.gnu.org/

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

  git send-email \
    --in-reply-to=20220228225047.11105-1-maxim.cournoyer@gmail.com \
    --to=maxim.cournoyer@gmail.com \
    --cc=40998@debbugs.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 public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).