From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id eBx1AIV4mV+eRgAA0tVLHw (envelope-from ) for ; Wed, 28 Oct 2020 13:56:21 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id OBjcN4R4mV94BQAAB5/wlQ (envelope-from ) for ; Wed, 28 Oct 2020 13:56:20 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 6C7B5940149 for ; Wed, 28 Oct 2020 13:56:20 +0000 (UTC) Received: from localhost ([::1]:40594 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kXlw3-0000gm-Aq for larch@yhetil.org; Wed, 28 Oct 2020 09:56:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52082) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kXlvn-0000fz-IC for guix-patches@gnu.org; Wed, 28 Oct 2020 09:56:04 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:38432) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kXlvm-0003XW-4i for guix-patches@gnu.org; Wed, 28 Oct 2020 09:56:03 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kXlvl-0006gO-Pa for guix-patches@gnu.org; Wed, 28 Oct 2020 09:56:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#44169] [PATCH v2 1/3] file-systems: Allow swap space lookup by UUID/label. Resent-From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Wed, 28 Oct 2020 13:56:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 44169 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 44169@debbugs.gnu.org Cc: Ludovic =?UTF-8?Q?Court=C3=A8s?= Received: via spool by 44169-submit@debbugs.gnu.org id=B44169.160389334525659 (code B ref 44169); Wed, 28 Oct 2020 13:56:01 +0000 Received: (at 44169) by debbugs.gnu.org; 28 Oct 2020 13:55:45 +0000 Received: from localhost ([127.0.0.1]:49972 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kXlvU-0006fm-To for submit@debbugs.gnu.org; Wed, 28 Oct 2020 09:55:45 -0400 Received: from eggs.gnu.org ([209.51.188.92]:51906) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kXlvT-0006dq-VN for 44169@debbugs.gnu.org; Wed, 28 Oct 2020 09:55:44 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:44162) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kXlvO-0003UP-04; Wed, 28 Oct 2020 09:55:38 -0400 Received: from vpn-0-27.aquilenet.fr ([2a0c:e300:4:27::]:38634 helo=gnu.org) by fencepost.gnu.org with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1kXlvN-0001bF-Hw; Wed, 28 Oct 2020 09:55:37 -0400 From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Date: Wed, 28 Oct 2020 14:54:55 +0100 Message-Id: <20201028135457.23335-1-ludo@gnu.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <87imaxdwv5.fsf@gnu.org> References: <87imaxdwv5.fsf@gnu.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-Spam-Score: -3.3 (---) X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: "Guix-patches" X-Scanner: scn0 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Spam-Score: -0.51 X-TUID: y0YWsBcvGyoq * 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 | 46 +++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/gnu/build/file-systems.scm b/gnu/build/file-systems.scm index 734d648575..8ec8eac896 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 +;;; Copyright © 2014, 2015, 2016, 2017, 2018, 2020 Ludovic Courtès ;;; Copyright © 2016, 2017 David Craven ;;; Copyright © 2017 Mathieu Othacehe ;;; Copyright © 2019 Guillaume Le Vaillant @@ -179,6 +179,46 @@ 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. +;; XXX: This is always 4K on x86_64, i386, and ARMv7. However, on AArch64, +;; this is determined by 'CONFIG_ARM64_PAGE_SHIFT' in the kernel, which is 12 +;; by default (4K) but can be 14 or 16. +(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 +636,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 +654,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