guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

03/03: file-systems: Fix F2FS volume name accessor.


From: guix-commits
Subject: 03/03: file-systems: Fix F2FS volume name accessor.
Date: Sun, 3 May 2020 14:36:19 -0400 (EDT)

dannym pushed a commit to branch master
in repository guix.

commit f73f4b3a2d7a313a6cb1667bd69205ea4b09f57c
Author: Danny Milosavljevic <address@hidden>
AuthorDate: Sun May 3 17:29:39 2020 +0200

    file-systems: Fix F2FS volume name accessor.
    
    Follow-up to 23b37c3d40d497cc6f07437ab26ab10e60fb6e09.
    
    * gnu/build/file-systems.scm (bytevector-utf16-length): New procedure.
    (null-terminated-utf16->string): New procedure.
    (f2fs-superblock-volume-name): Use it.
---
 gnu/build/file-systems.scm | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/gnu/build/file-systems.scm b/gnu/build/file-systems.scm
index bbea4c7..4ac672d 100644
--- a/gnu/build/file-systems.scm
+++ b/gnu/build/file-systems.scm
@@ -98,6 +98,22 @@ takes a bytevector and returns #t when it's a valid 
superblock."
 (define null-terminated-latin1->string
   (cut latin1->string <> zero?))
 
+(define (bytevector-utf16-length bv)
+  "Given a bytevector BV containing a NUL-terminated UTF16-encoded string,
+determine where the NUL terminator is and return its index.  If there's no
+NUL terminator, return the size of the bytevector."
+  (let ((length (bytevector-length bv)))
+    (let loop ((index 0))
+      (if (< index length)
+          (if (zero? (bytevector-u16-ref bv index 'little))
+              index
+              (loop (+ index 2)))
+          length))))
+
+(define (null-terminated-utf16->string bv endianness)
+  (utf16->string (sub-bytevector bv 0 (bytevector-utf16-length bv))
+                 endianness))
+
 
 ;;;
 ;;; Ext2 file systems.
@@ -377,7 +393,9 @@ if DEVICE does not contain an F2FS file system."
 (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))
+  (null-terminated-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."



reply via email to

[Prev in Thread] Current Thread [Next in Thread]