Message ID | 20201023100754.20924-1-ludo@gnu.org |
---|---|
State | Accepted |
Headers | show |
Series | Referring to swap with UUIDs and labels | expand |
Context | Check | Description |
---|---|---|
cbaines/issue | success | View issue |
cbaines/comparison | success | View comparision |
cbaines/git branch | success | View Git branch |
cbaines/applying patch | success | View Laminar job |
cbaines/issue | success | View issue |
cbaines/comparison | success | View comparision |
cbaines/git branch | success | View Git branch |
cbaines/applying patch | success | View Laminar job |
Hey Ludo, Thanks for this patchset, nice addition! > +;; Like 'PAGE_SIZE' in Linux, arch/x86/include/asm/page.h. > +(define %page-size 4096) Page size is not necessarily 4096, it can be larger, which will break the magic detection. I guess we need to use the system current page size for a portable detection. Thanks, Mathieu
Hi, Mathieu Othacehe <othacehe@gnu.org> skribis: >> +;; Like 'PAGE_SIZE' in Linux, arch/x86/include/asm/page.h. >> +(define %page-size 4096) > > Page size is not necessarily 4096, it can be larger, which will break > the magic detection. I guess we need to use the system current page size > for a portable detection. It’s really the PAGE_SIZE constant, not the sysconf value. We should check its value on the other arches we can about though. Ludo’.
Hey,
> We should check its value on the other arches we can about though.
On arm64, PAGE_SIZE is 1 << CONFIG_ARM64_PAGE_SHIFT which can be 12, 14
or 16 depending on the kernel config.
On arm and x86_64 it is fixed to 1 << 12 which makes things easier.
Mathieu
Hi, Mathieu Othacehe <othacehe@gnu.org> skribis: >> We should check its value on the other arches we can about though. > > On arm64, PAGE_SIZE is 1 << CONFIG_ARM64_PAGE_SHIFT which can be 12, 14 > or 16 depending on the kernel config. Oh, so IOW we cannot get it right here? Or should we try all three page sizes on that architecture? Do people actually configure with a different page size? > On arm and x86_64 it is fixed to 1 << 12 which makes things easier. Phew. I do think that 4K is pretty entrenched in people’s minds. :-) Ludo’.
Hey hey, > Oh, so IOW we cannot get it right here? Or should we try all three page > sizes on that architecture? Do people actually configure with a > different page size? Default is 12 on ARM64 and our kernel configuration does not change it. So I think it would be fine to proceed with the current patch, maybe with an extra comment. Thanks, Mathieu
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))) + +;;; +;;; 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))) + ;;; ;;; 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