[PATCH] gnu: build: file-systems: Add ISO-9660.

  • Done
  • quality assurance status badge
Details
2 participants
  • Danny Milosavljevic
  • Ludovic Courtès
Owner
unassigned
Submitted by
Danny Milosavljevic
Severity
normal

Debbugs page

Danny Milosavljevic wrote 8 years ago
(address . guix-patches@gnu.org)(name . Danny Milosavljevic)(address . dannym@scratchpost.org)
20170502200436.29885-1-dannym@scratchpost.org
* gnu/build/file-systems.scm (iso9660-superblock?,
read-iso9660-primary-volume-descriptor, read-iso9660-superblock,
iso9660-superblock-uuid, iso9660-uuid->string,
iso9660-superblock-volume-name): New variables.
(%partition-label-readers): Add iso9660.
(%partition-uuid-readers): Add iso9660.
---
gnu/build/file-systems.scm | 67 ++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 65 insertions(+), 2 deletions(-)

Toggle diff (92 lines)
diff --git a/gnu/build/file-systems.scm b/gnu/build/file-systems.scm
index 0cb84b8aa..e2a6cd626 100644
--- a/gnu/build/file-systems.scm
+++ b/gnu/build/file-systems.scm
@@ -230,6 +230,65 @@ Trailing spaces are trimmed."
;;;
+;;; ISO9660 file systems.
+;;;
+
+;; <http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-119.pdf>.
+
+(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))
+
+(define (iso9660-uuid->string uuid)
+ ;; Drops GMT offset for compatibility with Grub, blkid and /dev/disk/by-uuid.
+ ;; Compare Grub: "2014-12-02-19-30-23-00".
+ ;; Compare blkid result: "2014-12-02-19-30-23-00".
+ ;; Compare /dev/disk/by-uuid entry: "2014-12-02-19-30-23-00".
+ (define digits->string latin1->string)
+ (let* ((year (sub-bytevector uuid 0 4))
+ (month (sub-bytevector uuid 4 2))
+ (day (sub-bytevector uuid 6 2))
+ (hour (sub-bytevector uuid 8 2))
+ (minute (sub-bytevector uuid 10 2))
+ (second (sub-bytevector uuid 12 2))
+ (hundreths (sub-bytevector uuid 14 2))
+ ;; offset: In 15 min intervals, two's complement, from GMT.
+ (offset (bytevector-u8-ref uuid 16))
+ (parts (list year month day hour minute second hundreths)))
+ (string-append (string-join (map digits->string parts)))))
+
+(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 +399,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 +409,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)
Danny Milosavljevic wrote 8 years ago
[PATCH v2] gnu: build: file-systems: Add ISO-9660.
(address . 26751@debbugs.gnu.org)(name . Danny Milosavljevic)(address . dannym@scratchpost.org)
20170502203209.13124-1-dannym@scratchpost.org
* gnu/build/file-systems.scm (iso9660-superblock?,
read-iso9660-primary-volume-descriptor, read-iso9660-superblock,
iso9660-superblock-uuid, iso9660-uuid->string,
iso9660-superblock-volume-name): New variables.
(%partition-label-readers): Add iso9660.
(%partition-uuid-readers): Add iso9660.
---
gnu/build/file-systems.scm | 64 ++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 62 insertions(+), 2 deletions(-)

Toggle diff (89 lines)
diff --git a/gnu/build/file-systems.scm b/gnu/build/file-systems.scm
index 0cb84b8aa..3e702cc8d 100644
--- a/gnu/build/file-systems.scm
+++ b/gnu/build/file-systems.scm
@@ -230,6 +230,62 @@ Trailing spaces are trimmed."
;;;
+;;; ISO9660 file systems.
+;;;
+
+;; <http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-119.pdf>.
+
+(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 modification time of a iso9660 superblock SBLOCK as a bytevector."
+ ;; FIXME Use only certain parts (See grub).
+ ;; FIXME treat "all 0" as invalid.
+ ;; Drops GMT offset for compatibility with Grub, blkid and /dev/disk/by-uuid.
+ ;; Compare Grub: "2014-12-02-19-30-23-00".
+ ;; Compare blkid result: "2014-12-02-19-30-23-00".
+ ;; Compare /dev/disk/by-uuid entry: "2014-12-02-19-30-23-00".
+ (sub-bytevector sblock 830 16))
+
+(define (iso9660-uuid->string uuid)
+ (define digits->string latin1->string)
+ (let* ((year (sub-bytevector uuid 0 4))
+ (month (sub-bytevector uuid 4 2))
+ (day (sub-bytevector uuid 6 2))
+ (hour (sub-bytevector uuid 8 2))
+ (minute (sub-bytevector uuid 10 2))
+ (second (sub-bytevector uuid 12 2))
+ (hundreths (sub-bytevector uuid 14 2))
+ (parts (list year month day hour minute second hundreths)))
+ (string-append (string-join (map digits->string parts)))))
+
+(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 +396,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 +406,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)
Ludovic Courtès wrote 8 years ago
(name . Danny Milosavljevic)(address . dannym@scratchpost.org)(address . 26751@debbugs.gnu.org)
87zievymg2.fsf@gnu.org
Danny Milosavljevic <dannym@scratchpost.org> skribis:

Toggle quote (7 lines)
> * gnu/build/file-systems.scm (iso9660-superblock?,
> read-iso9660-primary-volume-descriptor, read-iso9660-superblock,
> iso9660-superblock-uuid, iso9660-uuid->string,
> iso9660-superblock-volume-name): New variables.
> (%partition-label-readers): Add iso9660.
> (%partition-uuid-readers): Add iso9660.

[...]

Toggle quote (5 lines)
> +(define (iso9660-superblock-uuid sblock)
> + "Return the modification time of a iso9660 superblock SBLOCK as a bytevector."
> + ;; FIXME Use only certain parts (See grub).
> + ;; FIXME treat "all 0" as invalid.

Please expound these two comments, as discussed on guix-devel.

Toggle quote (18 lines)
> + ;; Drops GMT offset for compatibility with Grub, blkid and /dev/disk/by-uuid.
> + ;; Compare Grub: "2014-12-02-19-30-23-00".
> + ;; Compare blkid result: "2014-12-02-19-30-23-00".
> + ;; Compare /dev/disk/by-uuid entry: "2014-12-02-19-30-23-00".
> + (sub-bytevector sblock 830 16))
> +
> +(define (iso9660-uuid->string uuid)
> + (define digits->string latin1->string)
> + (let* ((year (sub-bytevector uuid 0 4))
> + (month (sub-bytevector uuid 4 2))
> + (day (sub-bytevector uuid 6 2))
> + (hour (sub-bytevector uuid 8 2))
> + (minute (sub-bytevector uuid 10 2))
> + (second (sub-bytevector uuid 12 2))
> + (hundreths (sub-bytevector uuid 14 2))
> + (parts (list year month day hour minute second hundreths)))
> + (string-append (string-join (map digits->string parts)))))

Neat! Please add a docstring.

Toggle quote (5 lines)
> +(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))

Please trim to 80 columns. :-)

OK with these changes, thank you!

Ludo’.
Danny Milosavljevic wrote 8 years ago
(no subject)
(address . control@debbugs.gnu.org)
20170507212106.7b1c20b4@scratchpost.org
close 26166
close 26541
close 26614
close 26751
close 26692
close 26731
close 26743
close 26744
?
Your comment

This issue is archived.

To comment on this conversation send an email to 26751@debbugs.gnu.org

To respond to this issue using the mumi CLI, first switch to it
mumi current 26751
Then, you may apply the latest patchset in this issue (with sign off)
mumi am -- -s
Or, compose a reply to this issue
mumi compose
Or, send patches to this issue
mumi send-email *.patch
You may also tag this issue. See list of standard tags. For example, to set the confirmed and easy tags
mumi command -t +confirmed -t +easy
Or, remove the moreinfo tag and set the help tag
mumi command -t -moreinfo -t +help