file-systems: Invoke fsck tools with 'system*/tty'.

This ensures those programs, if invoked by shepherd (where standard
input is /dev/null), can still interact with the user if needed.

* gnu/build/file-systems.scm (check-ext2-file-system)
(check-bcachefs-file-system, check-btrfs-file-system):
(check-fat-file-system, check-jfs-file-system):
(check-f2fs-file-system, check-ntfs-file-system):
(check-xfs-file-system): Use 'system*/tty' instead of 'system*'.
This commit is contained in:
Ludovic Courtès 2022-04-08 11:56:42 +02:00
parent 931f13840b
commit dcb0e54a4f
No known key found for this signature in database
GPG key ID: 090B11993D9AEBB5

View file

@ -208,13 +208,13 @@ (define (check-ext2-file-system device force? repair)
do not write to the file system to fix errors. If it's #t, fix all do not write to the file system to fix errors. If it's #t, fix all
errors. Otherwise, fix only those considered safe to repair automatically." errors. Otherwise, fix only those considered safe to repair automatically."
(match (status:exit-val (match (status:exit-val
(apply system* `("e2fsck" "-v" "-C" "0" (apply system*/tty "e2fsck" "-v" "-C" "0"
,@(if force? '("-f") '()) `(,@(if force? '("-f") '())
,@(match repair ,@(match repair
(#f '("-n")) (#f '("-n"))
(#t '("-y")) (#t '("-y"))
(_ '("-p"))) (_ '("-p")))
,device))) ,device)))
(0 'pass) (0 'pass)
(1 'errors-corrected) (1 'errors-corrected)
(2 'reboot-required) (2 'reboot-required)
@ -340,14 +340,14 @@ (define (check-bcachefs-file-system device force? repair)
(status (status
;; A number, or #f on abnormal termination (e.g., assertion failure). ;; A number, or #f on abnormal termination (e.g., assertion failure).
(status:exit-val (status:exit-val
(apply system* `("bcachefs" "fsck" "-v" (apply system*/tty "bcachefs" "fsck" "-v"
,@(if force? '("-f") '()) `(,@(if force? '("-f") '())
,@(match repair ,@(match repair
(#f '("-n")) (#f '("-n"))
(#t '("-y")) (#t '("-y"))
(_ '("-p"))) (_ '("-p")))
;; Make each multi-device member a separate argument. ;; Make each multi-device member a separate argument.
,@(string-split device #\:)))))) ,@(string-split device #\:))))))
(match (and=> status (cut logand <> (lognot ignored-bits))) (match (and=> status (cut logand <> (lognot ignored-bits)))
(0 'pass) (0 'pass)
(1 'errors-corrected) (1 'errors-corrected)
@ -392,17 +392,17 @@ (define (check-btrfs-file-system device force? repair)
fix only those considered safe to repair automatically." fix only those considered safe to repair automatically."
(if force? (if force?
(match (status:exit-val (match (status:exit-val
(apply system* `("btrfs" "check" "--progress" (apply system*/tty "btrfs" "check" "--progress"
;; Btrfs's --force is not relevant to us here. ;; Btrfs's --force is not relevant to us here.
,@(match repair `(,@(match repair
;; Upstream considers ALL repairs dangerous ;; Upstream considers ALL repairs dangerous
;; and will warn the user at run time. ;; and will warn the user at run time.
(#t '("--repair")) (#t '("--repair"))
(_ '("--readonly" ; a no-op for clarity (_ '("--readonly" ; a no-op for clarity
;; A 466G file system with 180G used is ;; A 466G file system with 180G used is
;; enough to kill btrfs with 6G of RAM. ;; enough to kill btrfs with 6G of RAM.
"--mode" "lowmem"))) "--mode" "lowmem")))
,device))) ,device)))
(0 'pass) (0 'pass)
(_ 'fatal-error)) (_ 'fatal-error))
'pass)) 'pass))
@ -440,11 +440,11 @@ (define (check-fat-file-system device force? repair)
not write to the file system to fix errors. Otherwise, automatically fix them not write to the file system to fix errors. Otherwise, automatically fix them
using the least destructive approach." using the least destructive approach."
(match (status:exit-val (match (status:exit-val
(apply system* `("fsck.vfat" "-v" (system*/tty "fsck.vfat" "-v"
,@(match repair (match repair
(#f '("-n")) (#f "-n")
(_ '("-a"))) ; no 'safe/#t distinction (_ "-a")) ;no 'safe/#t distinction
,device))) device))
(0 'pass) (0 'pass)
(1 'errors-corrected) (1 'errors-corrected)
(_ 'fatal-error))) (_ 'fatal-error)))
@ -573,7 +573,7 @@ (define (check-jfs-file-system device force? repair)
only if FORCE? is true. Otherwise, replay the transaction log before checking only if FORCE? is true. Otherwise, replay the transaction log before checking
and automatically fix found errors." and automatically fix found errors."
(match (status:exit-val (match (status:exit-val
(apply system* (apply system*/tty
`("jfs_fsck" "-v" `("jfs_fsck" "-v"
;; The LEVEL logic is convoluted. To quote fsck/xchkdsk.c ;; The LEVEL logic is convoluted. To quote fsck/xchkdsk.c
;; (-p, -a, and -r are aliases in every way): ;; (-p, -a, and -r are aliases in every way):
@ -649,10 +649,10 @@ (define (check-f2fs-file-system device force? repair)
"warning: forced check of F2FS ~a implies repairing any errors~%" "warning: forced check of F2FS ~a implies repairing any errors~%"
device)) device))
(match (status:exit-val (match (status:exit-val
(apply system* `("fsck.f2fs" (apply system*/tty "fsck.f2fs"
,@(if force? '("-f") '()) `(,@(if force? '("-f") '())
,@(if repair '("-p") '("--dry-run")) ,@(if repair '("-p") '("--dry-run"))
,device))) ,device)))
;; 0 and -1 are the only two possibilities according to the man page. ;; 0 and -1 are the only two possibilities according to the man page.
(0 'pass) (0 'pass)
(_ 'fatal-error))) (_ 'fatal-error)))
@ -737,9 +737,9 @@ (define (check-ntfs-file-system device force? repair)
true and the volume has been repaired by an external tool, clear the volume true and the volume has been repaired by an external tool, clear the volume
dirty flag to indicate that it's now safe to mount." dirty flag to indicate that it's now safe to mount."
(match (status:exit-val (match (status:exit-val
(apply system* `("ntfsfix" (system*/tty "ntfsfix"
,@(if repair '("--clear-dirty") '("--no-action")) (if repair "--clear-dirty" "--no-action")
,device))) device))
(0 'pass) (0 'pass)
(_ 'fatal-error))) (_ 'fatal-error)))
@ -782,11 +782,11 @@ (define (check-xfs-file-system device force? repair)
Otherwise, only replay the log, and check without attempting further repairs." Otherwise, only replay the log, and check without attempting further repairs."
(define (xfs_repair) (define (xfs_repair)
(status:exit-val (status:exit-val
(apply system* `("xfs_repair" "-Pv" (system*/tty "xfs_repair" "-Pv"
,@(match repair (match repair
(#t '("-e")) (#t "-e")
(_ '("-n"))) ; will miss some errors (_ "-n")) ;will miss some errors
,device)))) device)))
(if force? (if force?
;; xfs_repair fails with exit status 2 if the log is dirty, which is ;; xfs_repair fails with exit status 2 if the log is dirty, which is
;; likely in situations where you're running xfs_repair. Only the kernel ;; likely in situations where you're running xfs_repair. Only the kernel