From mboxrd@z Thu Jan 1 00:00:00 1970 From: ludo@gnu.org (Ludovic =?utf-8?Q?Court=C3=A8s?=) Subject: Re: GuixSD bootable ISO-9669 image Date: Tue, 02 May 2017 14:37:04 +0200 Message-ID: <87efw7igen.fsf@gnu.org> References: <20170418141719.llp77itz7vyq5rij@abyayala> <87k26hwxt0.fsf@gmail.com> <8760i0m7vg.fsf@gnu.org> <87pog3u3ms.fsf@gmail.com> <87k26afl07.fsf_-_@gmail.com> <20170427190840.79bcaa76@scratchpost.org> <20170427220009.1d0d4607@scratchpost.org> <20170428101844.540ce399@scratchpost.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:38553) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d5X3I-0002CM-7I for guix-devel@gnu.org; Tue, 02 May 2017 08:37:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d5X3F-0005dp-1D for guix-devel@gnu.org; Tue, 02 May 2017 08:37:12 -0400 In-Reply-To: <20170428101844.540ce399@scratchpost.org> (Danny Milosavljevic's message of "Fri, 28 Apr 2017 10:18:44 +0200") List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org Sender: "Guix-devel" To: Danny Milosavljevic Cc: guix-devel@gnu.org --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hi! I just tested your patch, Danny (last version attached): I took the image at and then did: --8<---------------cut here---------------start------------->8--- scheme@(guile-user)> ,m (gnu build file-systems) scheme@(gnu build file-systems)> (define sb (read-iso9660-superblock "/tmp/= debian-8.7.1-amd64-netinst.iso.part")) scheme@(gnu build file-systems)> (iso9660-superblock-volume-name sb) $2 =3D "Debian 8.7.1 amd64 1" scheme@(gnu build file-systems)> (iso9660-superblock-uuid sb) $3 =3D #vu8(50 48 49 55 48 49 49 54 49 49 48 49 48 49 48 48 0) scheme@(gnu build file-systems)> (bytevector-length $3) $4 =3D 17 scheme@(gnu build file-systems)> (uuid->string $3) $5 =3D "32303137-3031-3136-3131-303130313030" --8<---------------cut here---------------end--------------->8--- Seems to work! Could you clarify the two =E2=80=9CSee grub=E2=80=9D in here: --8<---------------cut here---------------start------------->8--- (define (iso9660-superblock-uuid sblock) "Return the Volume ID of a iso9660 superblock SBLOCK as a 4-byte bytevect= or." ;; Note: The field is the volume creation time. ;; FIXME Use only certain parts (See grub). ;; FIXME treat "all 0" as invalid. (sub-bytevector sblock 813 17)) ;; FIXME make result human-readable (See grub). ;(define (iso9660-uuid->string uuid) --8<---------------cut here---------------end--------------->8--- Should =E2=80=98iso9660-uuid->string=E2=80=99 be different from =E2=80=98uu= id->string=E2=80=99? Anyway, I think we should polish and commit real soon. :-) Perhaps we can add a note about endianness and assume little endian for now. Thank you Danny! Ludo=E2=80=99. --=-=-= Content-Type: text/x-patch Content-Disposition: inline diff --git a/gnu/build/file-systems.scm b/gnu/build/file-systems.scm index 0cb84b8aa..4c826830d 100644 --- a/gnu/build/file-systems.scm +++ b/gnu/build/file-systems.scm @@ -230,6 +230,55 @@ Trailing spaces are trimmed." ;;; +;;; ISO9660 file systems. +;;; + +;; . + +;(define-syntax %iso9660-endianness +; ;; Endianness of iso9660 file systems that we use. +; ;; Actually, iso9660 has redundant data (i.e. data for both endiannesses). +; (identifier-syntax (endianness little))) + +(define (iso9660-superblock? sblock) + "Return #t when SBLOCK is a iso9660 superblock." + (bytevector=? (sub-bytevector sblock 1 6) + ;; Note: "\x01" is the volume descriptor format version + (string->utf8 "CD001\x01"))) + +(define (read-iso9660-primary-volume-descriptor device offset) + "Find and read the first primary volume descriptor, starting at OFFSET. + Return #f if not found." + (let* ((sblock (read-superblock device offset 2048 iso9660-superblock?)) + (type-code (if sblock (array-ref sblock 0) 255))) + (match type-code + (255 #f) ; Volume Descriptor Set Terminator. + (1 sblock) ; Primary Volume Descriptor + (_ (read-iso9660-primary-volume-descriptor device (+ offset 2048)))))) + +(define (read-iso9660-superblock device) + "Return the raw contents of DEVICE's iso9660 superblock as a bytevector, or +#f if DEVICE does not contain a iso9660 file system." + ;; Start reading at sector 16. + (read-iso9660-primary-volume-descriptor device (* 2048 16))) + +(define (iso9660-superblock-uuid sblock) + "Return the Volume ID of a iso9660 superblock SBLOCK as a 4-byte bytevector." + ;; Note: The field is the volume creation time. + ;; FIXME Use only certain parts (See grub). + ;; FIXME treat "all 0" as invalid. + (sub-bytevector sblock 813 17)) + +;; FIXME make result human-readable (See grub). +;(define (iso9660-uuid->string uuid) + +(define (iso9660-superblock-volume-name sblock) + "Return the volume name of SBLOCK as a string. The volume name is an ASCII +string. Trailing spaces are trimmed." + (string-trim-right (latin1->string (sub-bytevector sblock 40 32) (lambda (c) #f)) #\space)) + + +;;; ;;; LUKS encrypted devices. ;;; @@ -340,7 +389,9 @@ partition field reader that returned a value." (_ #f))) (define %partition-label-readers - (list (partition-field-reader read-ext2-superblock + (list (partition-field-reader read-iso9660-superblock + iso9660-superblock-volume-name) + (partition-field-reader read-ext2-superblock ext2-superblock-volume-name) (partition-field-reader read-btrfs-superblock btrfs-superblock-volume-name) @@ -348,7 +399,9 @@ partition field reader that returned a value." fat32-superblock-volume-name))) (define %partition-uuid-readers - (list (partition-field-reader read-ext2-superblock + (list (partition-field-reader read-iso9660-superblock + iso9660-superblock-uuid) + (partition-field-reader read-ext2-superblock ext2-superblock-uuid) (partition-field-reader read-btrfs-superblock btrfs-superblock-uuid) --=-=-=--