diff options
| author | Jean-Baptiste Note <jean-baptiste.note@m4x.org> | 2025-09-11 21:10:22 +0200 |
|---|---|---|
| committer | Ludovic Courtès <ludo@gnu.org> | 2025-09-21 19:08:28 +0200 |
| commit | ec135370533b1fe3771bfc9c199f734863893e7f (patch) | |
| tree | 37ec5071a2eddf123d0c0d284651aa11b182e7b2 /gnu/build | |
| parent | f2c3ff8cba6b1cde8edcf1a8f83b325cf5bc9d95 (diff) | |
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 <ludo@gnu.org>
Diffstat (limited to 'gnu/build')
| -rw-r--r-- | gnu/build/file-systems.scm | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/gnu/build/file-systems.scm b/gnu/build/file-systems.scm index e884fcb2204..1d919c90cec 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 |
