unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
From: "Ludovic Courtès" <ludo@gnu.org>
To: 44169@debbugs.gnu.org
Cc: "Ludovic Courtès" <ludo@gnu.org>
Subject: [bug#44169] [PATCH 1/3] file-systems: Allow swap space lookup by UUID/label.
Date: Fri, 23 Oct 2020 12:07:52 +0200	[thread overview]
Message-ID: <20201023100754.20924-1-ludo@gnu.org> (raw)
In-Reply-To: <20201023095822.20528-1-ludo@gnu.org>

* gnu/build/file-systems.scm (%linux-swap-magic, %page-size): New
variables.
(linux-swap-superblock?, read-linux-swap-superblock)
(linux-swap-superblock-uuid, linux-swap-superblock-volume-name): New
procedures.
(%partition-label-readers, %partition-uuid-readers): Add them.
---
 gnu/build/file-systems.scm | 43 +++++++++++++++++++++++++++++++++++++-
 1 file changed, 42 insertions(+), 1 deletion(-)

diff --git a/gnu/build/file-systems.scm b/gnu/build/file-systems.scm
index 734d648575..54a24e8d18 100644
--- a/gnu/build/file-systems.scm
+++ b/gnu/build/file-systems.scm
@@ -1,5 +1,5 @@
 ;;; GNU Guix --- Functional package management for GNU
-;;; Copyright © 2014, 2015, 2016, 2017, 2018 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2014, 2015, 2016, 2017, 2018, 2020 Ludovic Courtès <ludo@gnu.org>
 ;;; Copyright © 2016, 2017 David Craven <david@craven.ch>
 ;;; Copyright © 2017 Mathieu Othacehe <m.othacehe@gmail.com>
 ;;; Copyright © 2019 Guillaume Le Vaillant <glv@posteo.net>
@@ -179,6 +179,43 @@ if DEVICE does not contain an ext2 file system."
     (2 'reboot-required)
     (_ 'fatal-error)))
 
+\f
+;;;
+;;; Linux swap.
+;;;
+
+;; Linux "swap space" is not a file system but it has a UUID and volume name,
+;; like actual file systems, and we want to be able to look up swap partitions
+;; by UUID and by label.
+
+(define %linux-swap-magic
+  (string->utf8 "SWAPSPACE2"))
+
+;; Like 'PAGE_SIZE' in Linux, arch/x86/include/asm/page.h.
+(define %page-size 4096)
+
+(define (linux-swap-superblock? sblock)
+  "Return #t when SBLOCK is an linux-swap superblock."
+  (and (= (bytevector-length sblock) %page-size)
+       (bytevector=? (sub-bytevector sblock (- %page-size 10) 10)
+                     %linux-swap-magic)))
+
+(define (read-linux-swap-superblock device)
+  "Return the raw contents of DEVICE's linux-swap superblock as a bytevector, or #f
+if DEVICE does not contain an linux-swap file system."
+  (read-superblock device 0 %page-size linux-swap-superblock?))
+
+;; See 'union swap_header' in 'include/linux/swap.h'.
+
+(define (linux-swap-superblock-uuid sblock)
+  "Return the UUID of Linux-swap superblock SBLOCK as a 16-byte bytevector."
+  (sub-bytevector sblock (+ 1024 4 4 4) 16))
+
+(define (linux-swap-superblock-volume-name sblock)
+  "Return the label of Linux-swap superblock SBLOCK as a string."
+  (null-terminated-latin1->string
+   (sub-bytevector sblock (+ 1024 4 4 4 16) 16)))
+
 \f
 ;;;
 ;;; Btrfs file systems.
@@ -596,6 +633,8 @@ partition field reader that returned a value."
                                 iso9660-superblock-volume-name)
         (partition-field-reader read-ext2-superblock
                                 ext2-superblock-volume-name)
+        (partition-field-reader read-linux-swap-superblock
+                                linux-swap-superblock-volume-name)
         (partition-field-reader read-btrfs-superblock
                                 btrfs-superblock-volume-name)
         (partition-field-reader read-fat32-superblock
@@ -612,6 +651,8 @@ partition field reader that returned a value."
                                 iso9660-superblock-uuid)
         (partition-field-reader read-ext2-superblock
                                 ext2-superblock-uuid)
+        (partition-field-reader read-linux-swap-superblock
+                                linux-swap-superblock-uuid)
         (partition-field-reader read-btrfs-superblock
                                 btrfs-superblock-uuid)
         (partition-field-reader read-fat32-superblock
-- 
2.28.0





  reply	other threads:[~2020-10-23 10:09 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-23  9:58 [bug#44169] [PATCH 0/3] Referring to swap with UUIDs and labels Ludovic Courtès
2020-10-23 10:07 ` Ludovic Courtès [this message]
2020-10-23 10:07   ` [bug#44169] [PATCH 2/3] services: swap: Allow for UUIDs and file system labels Ludovic Courtès
2020-10-23 10:07   ` [bug#44169] [PATCH 3/3] installer: Use UUIDs in the 'swap-devices' field Ludovic Courtès
2020-10-23 11:50     ` Mathieu Othacehe
2020-10-26 10:18       ` Ludovic Courtès
2020-10-26 12:06         ` Mathieu Othacehe
2020-10-28 13:58           ` Ludovic Courtès
2020-10-30  0:17             ` bug#44169: " Ludovic Courtès
2020-11-01 18:18               ` [bug#44169] " Mathieu Othacehe
2020-10-23 11:43   ` [bug#44169] [PATCH 1/3] file-systems: Allow swap space lookup by UUID/label Mathieu Othacehe
2020-10-23 16:31     ` Ludovic Courtès
2020-10-23 17:02       ` Mathieu Othacehe
2020-10-24 15:07         ` Ludovic Courtès
2020-10-26 11:56           ` Mathieu Othacehe
2020-10-28 13:54             ` [bug#44169] [PATCH v2 " Ludovic Courtès
2020-10-28 13:54               ` [bug#44169] [PATCH v2 2/3] services: swap: Allow for UUIDs and file system labels Ludovic Courtès
2020-10-28 13:54               ` [bug#44169] [PATCH v2 3/3] installer: Use UUIDs in the 'swap-devices' field Ludovic Courtès

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=20201023100754.20924-1-ludo@gnu.org \
    --to=ludo@gnu.org \
    --cc=44169@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).