From: David Craven <david@craven.ch>
To: guix-devel@gnu.org
Subject: [PATCH 1/8] file-systems: Add FAT32 support.
Date: Tue, 14 Feb 2017 16:28:26 +0100 [thread overview]
Message-ID: <20170214152834.19651-2-david@craven.ch> (raw)
In-Reply-To: <20170214152834.19651-1-david@craven.ch>
* gnu/build/file-systems.scm (%fat32-endianness, fat32-superblock?,
read-fat32-superblock, fat32-superblock-uuid, fat32-uuid->string,
fat32-superblock-volume-name, check-fat32-file-system): New variables.
(%partition-label-readers, %partition-uuid-readers, check-file-system): Add
fat support.
(latin1->string): New variable.
(null-terminated-latin1->string): Use latin1->string.
---
gnu/build/file-systems.scm | 66 +++++++++++++++++++++++++++++++++++++++++-----
1 file changed, 59 insertions(+), 7 deletions(-)
diff --git a/gnu/build/file-systems.scm b/gnu/build/file-systems.scm
index f8ab95370..8c621d439 100644
--- a/gnu/build/file-systems.scm
+++ b/gnu/build/file-systems.scm
@@ -106,15 +106,17 @@ takes a bytevector and returns #t when it's a valid superblock."
(bytevector-copy! bv start result 0 size)
result))
-(define (null-terminated-latin1->string bv)
- "Return the volume name of SBLOCK as a string of at most 256 characters, or
-#f if SBLOCK has no volume name."
- ;; This is a Latin-1, nul-terminated string.
- (let ((bytes (take-while (negate zero?) (bytevector->u8-list bv))))
+(define (latin1->string bv terminator)
+ "Return a string of BV, a latin1 bytevector, or #f. TERMINATOR is a predicate
+that takes a number and returns #t when a termination character is found."
+ (let ((bytes (take-while (negate terminator) (bytevector->u8-list bv))))
(if (null? bytes)
#f
(list->string (map integer->char bytes)))))
+(define null-terminated-latin1->string
+ (cut latin1->string <> zero?))
+
\f
;;;
;;; Ext2 file systems.
@@ -194,6 +196,51 @@ if DEVICE does not contain a btrfs file system."
\f
;;;
+;;; FAT32 file systems.
+;;;
+
+;; <http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-107.pdf>.
+
+(define-syntax %fat32-endianness
+ ;; Endianness of fat file systems.
+ (identifier-syntax (endianness little)))
+
+(define (fat32-superblock? sblock)
+ "Return #t when SBLOCK is a fat32 superblock."
+ (bytevector=? (sub-bytevector sblock 82 8)
+ (string->utf8 "FAT32 ")))
+
+(define (read-fat32-superblock device)
+ "Return the raw contents of DEVICE's btrfs superblock as a bytevector, or #f
+if DEVICE does not contain a fat file system."
+ (read-superblock device 0 90 fat32-superblock?))
+
+(define (fat32-superblock-uuid sblock)
+ "Return the Volume ID of a fat superblock SBLOCK as a 4-byte bytevector."
+ (sub-bytevector sblock 67 4))
+
+(define (fat32-uuid->string uuid)
+ "Convert fat32 UUID, a 4-byte bytevector, to its string representation."
+ (let ((high (bytevector-uint-ref uuid 0 %fat32-endianness 2))
+ (low (bytevector-uint-ref uuid 2 %fat32-endianness 2)))
+ (format #f "~:@(~x-~x~)" low high)))
+
+(define (fat32-superblock-volume-name sblock)
+ "Return the volume name of SBLOCK as a string of at most 11 characters, or
+#f if SBLOCK has no volume name. The volume name is a space terminated latin1
+string."
+ (latin1->string (sub-bytevector sblock 71 11) (cut eq? 32 <>)))
+
+(define (check-fat32-file-system device)
+ "Return the health of a fat file system on DEVICE."
+ (match (status:exit-val
+ (system* "dosfsck" "-v" "-a" device))
+ (0 'pass)
+ (1 'errors-corrected)
+ (_ 'fatal-error)))
+
+\f
+;;;
;;; LUKS encrypted devices.
;;;
@@ -307,13 +354,17 @@ partition field reader that returned a value."
(list (partition-field-reader read-ext2-superblock
ext2-superblock-volume-name)
(partition-field-reader read-btrfs-superblock
- btrfs-superblock-volume-name)))
+ btrfs-superblock-volume-name)
+ (partition-field-reader read-fat32-superblock
+ fat32-superblock-volume-name)))
(define %partition-uuid-readers
(list (partition-field-reader read-ext2-superblock
ext2-superblock-uuid)
(partition-field-reader read-btrfs-superblock
- btrfs-superblock-uuid)))
+ btrfs-superblock-uuid)
+ (partition-field-reader read-fat32-superblock
+ fat32-superblock-uuid)))
(define read-partition-label
(cut read-partition-field <> %partition-label-readers))
@@ -481,6 +532,7 @@ the following:
(cond
((string-prefix? "ext" type) check-ext2-file-system)
((string-prefix? "btrfs" type) check-btrfs-file-system)
+ ((string-prefix? "vfat" type) check-fat32-file-system)
(else #f)))
(if check-procedure
--
2.11.1
next prev parent reply other threads:[~2017-02-14 15:29 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-14 15:28 [PATCH 0/8] WIP: Better support for non-grub bootloaders David Craven
2017-02-14 15:28 ` David Craven [this message]
2017-03-01 16:30 ` [PATCH 1/8] file-systems: Add FAT32 support Danny Milosavljevic
2017-02-14 15:28 ` [PATCH 2/8] system: Pass <bootloader-parameter> to grub David Craven
2017-02-14 15:28 ` [PATCH 2/8] system: Pass <boot-parameters> " David Craven
2017-02-14 15:28 ` [PATCH 3/8] system: Add extlinux support David Craven
2017-02-14 15:28 ` [PATCH 4/8] scripts: system: Rename --no-grub option to --no-bootloader David Craven
2017-02-14 15:28 ` [PATCH 5/8] vm: Remove hard coded kernel file name David Craven
2017-02-28 22:48 ` Danny Milosavljevic
2017-02-14 15:28 ` [PATCH 6/8] vm: Improve readability of run-vm.sh generation David Craven
2017-02-28 23:44 ` Danny Milosavljevic
2017-02-14 15:28 ` [PATCH 7/8] vm: Fix full-boot? option David Craven
2017-03-06 22:44 ` Ludovic Courtès
2017-02-14 15:28 ` [PATCH 8/8] bootloader: Add install procedures and use them David Craven
2017-03-06 22:04 ` [PATCH 0/8] WIP: Better support for non-grub bootloaders Ludovic Courtès
2017-03-17 12:43 ` Mathieu Othacehe
2017-03-17 12:49 ` John Darrington
2017-03-18 13:53 ` Ludovic Courtès
2017-03-18 17:25 ` David Craven
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170214152834.19651-2-david@craven.ch \
--to=david@craven.ch \
--cc=guix-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/guix.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.