From 383d8536b748786b2072f5f61e1e24d0c9b4585d Mon Sep 17 00:00:00 2001
* gnu/build/file-systems.scm (%f2fs-endianness): New syntax.
(f2fs-superblock?, read-f2fs-superblock, f2fs-superblock-uuid)
(f2fs-superblock-volume-name, check-f2fs-file-system): New procedures.
(%partition-label-readers, %partition-uuid-readers, check-file-system): Register them.
gnu/build/file-systems.scm | 61 ++++++++++++++++++++++++++++++++++++--
1 file changed, 59 insertions(+), 2 deletions(-)
Toggle diff (95 lines)
diff --git a/gnu/build/file-systems.scm b/gnu/build/file-systems.scm
index 902563b219..3742252421 100644
--- a/gnu/build/file-systems.scm
+++ b/gnu/build/file-systems.scm
@@ -336,6 +336,58 @@ if DEVICE does not contain a JFS file system."
+;;; F2FS (Flash-Friendly File System)
+;;; https://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs.git/tree/include/linux/f2fs_fs.h
+;;; (but using xxd proved to be simpler)
+(define-syntax %f2fs-endianness
+ ;; Endianness of F2FS file systems
+ (identifier-syntax (endianness little)))
+;; F2FS actually stores two adjacent copies of the superblock.
+(define (f2fs-superblock? sblock)
+ "Return #t when SBLOCK is an F2FS superblock."
+ (let ((magic (bytevector-u32-ref sblock 0 %f2fs-endianness)))
+(define (read-f2fs-superblock device)
+ "Return the raw contents of DEVICE's F2FS superblock as a bytevector, or #f
+if DEVICE does not contain an F2FS file system."
+ (read-superblock device
+ ;; offset of magic in first copy
+ ;; difference between magic of second
+(define (f2fs-superblock-uuid sblock)
+ "Return the UUID of F2FS superblock SBLOCK as a 16-byte bytevector."
+ ;; subtract superblock offset
+(define (f2fs-superblock-volume-name sblock)
+ "Return the volume name of SBLOCK as a string of at most 16 characters, or
+#f if SBLOCK has no volume name."
+ (utf16->string (sub-bytevector sblock (- (+ #x470 12) #x400) 512) %f2fs-endianness))
+(define (check-f2fs-file-system device)
+ "Return the health of a F2FS file system on DEVICE."
+ (match (status:exit-val
+ (system* "fsck.f2fs" "-p" device))
+ ;; 0 and -1 are the only two possibilities
+ ;; (according to the manpage)
;;; LUKS encrypted devices.
@@ -472,7 +524,9 @@ partition field reader that returned a value."
(partition-field-reader read-fat16-superblock
fat16-superblock-volume-name)
(partition-field-reader read-jfs-superblock
- jfs-superblock-volume-name)))
+ jfs-superblock-volume-name)
+ (partition-field-reader read-f2fs-superblock
+ f2fs-superblock-volume-name)))
(define %partition-uuid-readers
(list (partition-field-reader read-iso9660-superblock
@@ -486,7 +540,9 @@ partition field reader that returned a value."
(partition-field-reader read-fat16-superblock
(partition-field-reader read-jfs-superblock
+ (partition-field-reader read-f2fs-superblock
+ f2fs-superblock-uuid)))
(define read-partition-label
(cut read-partition-field <> %partition-label-readers))
@@ -582,6 +638,7 @@ were found."
((string-prefix? "btrfs" type) check-btrfs-file-system)
((string-suffix? "fat" type) check-fat-file-system)
((string-prefix? "jfs" type) check-jfs-file-system)
+ ((string-prefix? "f2fs" type) check-f2fs-file-system)
((string-prefix? "nfs" type) (const 'pass))