From 23b37c3d40d497cc6f07437ab26ab10e60fb6e09 Mon Sep 17 00:00:00 2001 From: raingloom Date: Fri, 3 Apr 2020 02:32:23 +0200 Subject: file-systems: Add support for F2FS. * 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. Signed-off-by: Danny Milosavljevic --- gnu/build/file-systems.scm | 61 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 59 insertions(+), 2 deletions(-) (limited to 'gnu') diff --git a/gnu/build/file-systems.scm b/gnu/build/file-systems.scm index 902563b219..bbea4c766e 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." (2 'reboot-required) (_ 'fatal-error))) + +;;; +;;; 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. +;; should we read both? +(define (f2fs-superblock? sblock) + "Return #t when SBLOCK is an F2FS superblock." + (let ((magic (bytevector-u32-ref sblock 0 %f2fs-endianness))) + (= magic #xF2F52010))) + +(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 + #x400 + ;; difference between magic of second + ;; and first copies + (- #x1400 #x400) + f2fs-superblock?)) + +(define (f2fs-superblock-uuid sblock) + "Return the UUID of F2FS superblock SBLOCK as a 16-byte bytevector." + (sub-bytevector sblock + (- (+ #x460 12) + ;; subtract superblock offset + #x400) + 16)) + +(define (f2fs-superblock-volume-name sblock) + "Return the volume name of SBLOCK as a string of at most 512 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) + (0 'pass) + (_ 'fatal-error))) + ;;; ;;; 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 fat16-superblock-uuid) (partition-field-reader read-jfs-superblock - jfs-superblock-uuid))) + jfs-superblock-uuid) + (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)) (else #f))) -- cgit 1.4.1