guix_mirror_bot pushed a commit to branch master
in repository guix.
commit ec135370533b1fe3771bfc9c199f734863893e7f
Author: Jean-Baptiste Note <[email protected]>
AuthorDate: Thu Sep 11 21:10:22 2025 +0200
file-systems: Add support for hibernation swap detection.
* gnu/build/file-systems.scm (%linux-swsuspend-magic): New variable.
(linux-swsuspend-superblock?, read-linux-swsuspend-superblock): New
procedures.
(%partition-label-readers, %partition-uuid-readers): Add readers for
linux-swsuspend superblocks.
Change-Id: If77ca9b4ae1f72c4e9ce52149b10d331566b0030
Signed-off-by: Ludovic Courtès <[email protected]>
---
gnu/build/file-systems.scm | 37 +++++++++++++++++++++++++++++++++++++
1 file changed, 37 insertions(+)
diff --git a/gnu/build/file-systems.scm b/gnu/build/file-systems.scm
index e884fcb220..1d919c90ce 100644
--- a/gnu/build/file-systems.scm
+++ b/gnu/build/file-systems.scm
@@ -337,6 +337,39 @@ negative, defaulting to 0.~%") p)
(logior prio-flag delayed-flag))
+;;;
+;;; Linux swap, after hibernation.
+;;;
+
+;; Linux swap space header is rewritten with a swsusp_header on
+;; hibernate, which takes the HIBERNATE_SIG signature, which is this
+;; string; see function mark_swapfiles in kernel/power/swap.c. In the
+;; linux kernel the comparison is always done on 10 bytes, which
+;; include the trailing zero in the case of HIBERNATE_SIG while not
+;; including it for %linux-swap-magic.
+(define %linux-swsuspend-magic
+ (string->utf8 "S1SUSPEND\0"))
+
+;; The kernel structure swsusp_header is duplicated from the swap header, in
+;; kernel/power/swap.c.
+(define (linux-swsuspend-superblock? sblock)
+ "Return #t when SBLOCK is a linux-swap superblock we can resume from."
+ (and (= (bytevector-length sblock) %page-size)
+ (bytevector=? (sub-bytevector sblock (- %page-size 10) 10)
+ %linux-swsuspend-magic)))
+
+;; If we want to resume through UUID and/or LABEL from swap partitions, we
+;; need to fetch UUID/LABEL from partitions with such magics.
+(define (read-linux-swsuspend-superblock device)
+ "Return the raw contents of DEVICE's linux-swsuspend superblock as a
+bytevector, or #f if DEVICE does not contain an linux-swap file system with an
+hibernation image from which we can resume."
+ (read-superblock device 0 %page-size linux-swsuspend-superblock?))
+
+;; Label and UUID information are otherwise left untouched, therefore, swap
+;; functions are reused.
+
+
;;;
;;; Bcachefs file systems.
@@ -1052,6 +1085,8 @@ partition field reader that returned a value."
ext2-superblock-volume-name)
(partition-field-reader read-linux-swap-superblock
linux-swap-superblock-volume-name)
+ (partition-field-reader read-linux-swsuspend-superblock
+ linux-swap-superblock-volume-name)
(partition-field-reader read-bcachefs-superblock
bcachefs-superblock-volume-name)
(partition-field-reader read-btrfs-superblock
@@ -1076,6 +1111,8 @@ partition field reader that returned a value."
ext2-superblock-uuid)
(partition-field-reader read-linux-swap-superblock
linux-swap-superblock-uuid)
+ (partition-field-reader read-linux-swsuspend-superblock
+ linux-swap-superblock-uuid)
(partition-field-reader read-bcachefs-superblock
bcachefs-superblock-external-uuid)
(partition-field-reader read-btrfs-superblock