From 09ce4568f2cc1f87c5a5e0aa1643780c39a73088 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Thu, 22 Apr 2021 22:41:01 +0200 Subject: file-systems: read-partition-{uuid,label} don't swallow ENOENT & co. Previously, (read-partition-uuid "/does/not/exist") would return #f. With this change, a 'system-error exception is raised as expected. * gnu/build/file-systems.scm (ENOENT-safe): Clarify docstring. (partition-field-reader): Remove use of 'ENOENT-safe'. (partition-predicate): Wrap READER in 'ENOENT-safe'. --- gnu/build/file-systems.scm | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) (limited to 'gnu/build/file-systems.scm') diff --git a/gnu/build/file-systems.scm b/gnu/build/file-systems.scm index 304805db62..6111cd747c 100644 --- a/gnu/build/file-systems.scm +++ b/gnu/build/file-systems.scm @@ -644,16 +644,13 @@ if DEVICE does not contain a NTFS file system." (loop parts)))))))))) (define (ENOENT-safe proc) - "Wrap the one-argument PROC such that ENOENT errors are caught and lead to a -warning and #f as the result." + "Wrap the one-argument PROC such that ENOENT, EIO, and ENOMEDIUM errors are +caught and lead to a warning and #f as the result." (lambda (device) (catch 'system-error (lambda () (proc device)) (lambda args - ;; When running on the hand-made /dev, - ;; 'disk-partitions' could return partitions for which - ;; we have no /dev node. Handle that gracefully. (let ((errno (system-error-errno args))) (cond ((= ENOENT errno) (format (current-error-port) @@ -671,11 +668,10 @@ warning and #f as the result." (define (partition-field-reader read field) "Return a procedure that takes a device and returns the value of a FIELD in the partition superblock or #f." - (let ((read (ENOENT-safe read))) - (lambda (device) - (let ((sblock (read device))) - (and sblock - (field sblock)))))) + (lambda (device) + (let ((sblock (read device))) + (and sblock + (field sblock))))) (define (read-partition-field device partition-field-readers) "Returns the value of a FIELD in the partition superblock of DEVICE or #f. It @@ -742,11 +738,14 @@ partition field reader that returned a value." (define (partition-predicate reader =) "Return a predicate that returns true if the FIELD of partition header that was READ is = to the given value." - (lambda (expected) - (lambda (device) - (let ((actual (reader device))) - (and actual - (= actual expected)))))) + ;; When running on the hand-made /dev, 'disk-partitions' could return + ;; partitions for which we have no /dev node. Handle that gracefully. + (let ((reader (ENOENT-safe reader))) + (lambda (expected) + (lambda (device) + (let ((actual (reader device))) + (and actual + (= actual expected))))))) (define partition-label-predicate (partition-predicate read-partition-label string=?)) -- cgit 1.4.1 From b6269fb7bcd2ef7adfb90b148492bb7a62336f92 Mon Sep 17 00:00:00 2001 From: Tobias Geerinckx-Rice Date: Tue, 4 May 2021 11:39:08 +0200 Subject: file-systems: Handle abnormal ‘bcachefs fsck’ exits. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * gnu/build/file-systems.scm (check-bcachefs-file-system): Handle a STATUS:EXIT-VAL of #F. --- gnu/build/file-systems.scm | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'gnu/build/file-systems.scm') diff --git a/gnu/build/file-systems.scm b/gnu/build/file-systems.scm index 6111cd747c..23ff25d71f 100644 --- a/gnu/build/file-systems.scm +++ b/gnu/build/file-systems.scm @@ -3,7 +3,7 @@ ;;; Copyright © 2016, 2017 David Craven ;;; Copyright © 2017 Mathieu Othacehe ;;; Copyright © 2019 Guillaume Le Vaillant -;;; Copyright © 2019, 2020 Tobias Geerinckx-Rice +;;; Copyright © 2019–2021 Tobias Geerinckx-Rice ;;; Copyright © 2019 David C. Trudgian ;;; Copyright © 2020 Maxim Cournoyer ;;; @@ -264,11 +264,12 @@ bytevector." "Return the health of a bcachefs file system on DEVICE." (let ((ignored-bits (logior 2)) ; DEVICE was mounted read-only (status + ;; A number, or #f on abnormal termination (e.g., assertion failure). (status:exit-val (apply system* "bcachefs" "fsck" "-p" "-v" ;; Make each multi-device member a separate argument. (string-split device #\:))))) - (match (logand (lognot ignored-bits) status) + (match (and=> status (cut logand <> (lognot ignored-bits))) (0 'pass) (1 'errors-corrected) (_ 'fatal-error)))) -- cgit 1.4.1 From 71f15ca8713317551e93b59734cf25d7bdb96c54 Mon Sep 17 00:00:00 2001 From: Tobias Geerinckx-Rice Date: Tue, 4 May 2021 11:43:19 +0200 Subject: file-systems: Rewrite comment. * gnu/build/file-systems.scm (read-bcachefs-superblock): Make comment less damned negative. --- gnu/build/file-systems.scm | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'gnu/build/file-systems.scm') diff --git a/gnu/build/file-systems.scm b/gnu/build/file-systems.scm index 23ff25d71f..4eeb81cf26 100644 --- a/gnu/build/file-systems.scm +++ b/gnu/build/file-systems.scm @@ -239,15 +239,15 @@ if DEVICE does not contain an linux-swap file system." (define (read-bcachefs-superblock device) "Return the raw contents of DEVICE's bcachefs superblock as a bytevector, or #f if DEVICE does not contain a bcachefs file system." - ;; We completely ignore the back-up superblock & any checksum errors. - ;; Superblock field names, with offset & length respectively, in bytes: + ;; Field offsets & lengths, in bytes. There are more (and the superblock is + ;; extensible) but we need only some basic information here: ;; 0 16 bch_csum ;; 16 8 version ;; 24 16 magic - ;; 40 16 uuid ← ‘internal UUID’, you probably don't want this - ;; 56 16 user_uuid ← ‘external UUID’, the one by which to mount + ;; 40 16 uuid ← ‘internal’: you probably don't want this one + ;; 56 16 user_uuid ← ‘external’: user-visible one by which to mount ;; 72 32 label - ;; … there are more & the superblock is extensible, but we don't care yet. + ;; Assume a sane file system: ignore the back-up superblock & checksums. (read-superblock device 4096 104 bcachefs-superblock?)) (define (bcachefs-superblock-external-uuid sblock) -- cgit 1.4.1