[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
02/09: file-systems: Add 'cleanly-unmounted-ext2?'.
From: |
guix-commits |
Subject: |
02/09: file-systems: Add 'cleanly-unmounted-ext2?'. |
Date: |
Fri, 1 Jul 2022 06:27:33 -0400 (EDT) |
civodul pushed a commit to branch master
in repository guix.
commit 4636640de8ecd9e3702bca75c9ce0649ac5d4979
Author: Ludovic Courtès <ludo@gnu.org>
AuthorDate: Fri Jul 1 09:44:04 2022 +0200
file-systems: Add 'cleanly-unmounted-ext2?'.
* gnu/build/file-systems.scm (ext2-superblock-cleanly-unmounted?)
(cleanly-unmounted-ext2?): New procedures.
---
gnu/build/file-systems.scm | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/gnu/build/file-systems.scm b/gnu/build/file-systems.scm
index b06a4cc25c..1d3b33e7bd 100644
--- a/gnu/build/file-systems.scm
+++ b/gnu/build/file-systems.scm
@@ -52,6 +52,8 @@
read-partition-uuid
read-luks-partition-uuid
+ cleanly-unmounted-ext2?
+
bind-mount
system*/tty
@@ -193,6 +195,23 @@ NUL terminator, return the size of the bytevector."
if DEVICE does not contain an ext2 file system."
(read-superblock device 1024 264 ext2-superblock?))
+(define (ext2-superblock-cleanly-unmounted? sblock)
+ "Return true if SBLOCK denotes a file system that was cleanly unmounted,
+false otherwise."
+ (define EXT2_VALID_FS 1) ;cleanly unmounted
+ (define EXT2_ERROR_FS 2) ;errors detected
+
+ (define EXT3_FEATURE_INCOMPAT_RECOVER #x0004) ;journal needs recovery
+
+ (let ((state (bytevector-u16-ref sblock 58 %ext2-endianness)))
+ (cond ((= state EXT2_VALID_FS)
+ (let ((incompatible-features
+ (bytevector-u32-ref sblock 96 %ext2-endianness)))
+ (zero? (logand incompatible-features
+ EXT3_FEATURE_INCOMPAT_RECOVER))))
+ ((= state EXT2_ERROR_FS) #f)
+ (else (error "invalid ext2 superblock state" state)))))
+
(define (ext2-superblock-uuid sblock)
"Return the UUID of ext2 superblock SBLOCK as a 16-byte bytevector."
(sub-bytevector sblock 104 16))
@@ -220,6 +239,11 @@ errors. Otherwise, fix only those considered safe to
repair automatically."
(2 'reboot-required)
(_ 'fatal-error)))
+(define (cleanly-unmounted-ext2? device) ;convenience procedure
+ "Return true if DEVICE is an ext2 file system and if it was cleanly
+unmounted."
+ (ext2-superblock-cleanly-unmounted? (read-ext2-superblock device)))
+
;;;
;;; Linux swap.
- branch master updated (b5c6062bce -> 741895676b), guix-commits, 2022/07/01
- 03/09: services: root-file-system: Cleanly unmount upon shutdown., guix-commits, 2022/07/01
- 08/09: image: Add sanitizers for 'format' and 'partition-table-type'., guix-commits, 2022/07/01
- 02/09: file-systems: Add 'cleanly-unmounted-ext2?'.,
guix-commits <=
- 06/09: image: Avoid use of the deprecated 'gpt' option of genimage., guix-commits, 2022/07/01
- 04/09: image: 'system-image' throws when given an incorrect image format., guix-commits, 2022/07/01
- 05/09: image: Add default value for partition initializer., guix-commits, 2022/07/01
- 01/09: gnu: texlive-fmtcount: Add proper 'license' value., guix-commits, 2022/07/01
- 07/09: image: Raise an error when an image lacks a bootable partition., guix-commits, 2022/07/01
- 09/09: tests: Add sanitizer test., guix-commits, 2022/07/01