[Toybox] [PATCH] BLKID: Add support for iso9660

Eric Molitor emolitor at molitor.org
Mon Feb 6 06:53:22 PST 2023


Add iso9660 support to blkid. Rather than attach a binary for the test
generate the blkid test image file in tests/files/blkid via

xorriso -as mkisofs -V 'MYISO' -o iso --modification-date=1970010212554200
/dev/null
bzip2 iso
- Eric
---
 tests/blkid.test   |  3 +++
 toys/other/blkid.c | 12 +++++++++++-
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/tests/blkid.test b/tests/blkid.test
index fd336663..4c385dcb 100755
--- a/tests/blkid.test
+++ b/tests/blkid.test
@@ -28,6 +28,9 @@ testing "ext4" "BLKID ext4" \
 testing "f2fs" "BLKID f2fs" \
   'temp.img: LABEL="myf2fs" UUID="b53d3619-c204-4c0b-8504-36363578491c"
TYPE="f2fs"\n' \
   "" ""
+testing "iso" "BLKID iso" \
+  'temp.img: SEC_TYPE="msdos" LABEL="MYISO" UUID="1970-01-02-12-55-42-00"
TYPE="iso9660"\n' \
+  "" ""
 testing "msdos" "BLKID msdos" \
   'temp.img: SEC_TYPE="msdos" LABEL="mymsdos" UUID="6E1E-0851"
TYPE="vfat"\n' \
   "" ""
diff --git a/toys/other/blkid.c b/toys/other/blkid.c
index 46c9a3ff..726ae754 100644
--- a/toys/other/blkid.c
+++ b/toys/other/blkid.c
@@ -54,6 +54,7 @@ struct fstype {
   {"btrfs", 0x4D5F53665248425FULL, 8, 65600, 65803, 256, 65819},
   {"cramfs", 0x28cd3d45, 4, 0, 0, 16, 48},
   {"f2fs", 0xF2F52010, 4, 1024, 1132, 512, 0x47c},
+  {"iso9660", 0x444301, 3, 0x8000, 0x832d, 32, 0x8028},
   {"jfs", 0x3153464a, 4, 32768, 32920, 16, 32904},
   {"nilfs", 0x3434, 2, 1030, 1176, 80, 1192},
   {"reiserfs", 0x724573496552ULL, 6, 8244, 8276, 16, 8292},
@@ -166,7 +167,7 @@ static void do_blkid(int fd, char *name)
   len = fstypes[i].label_len;
   if (!FLAG(U) && len) {
     s = toybuf+fstypes[i].label_off-off;
-    if (!strcmp(type, "vfat")) {
+    if (!strcmp(type, "vfat") || !strcmp(type, "iso9660")) {
       show_tag("SEC_TYPE", "msdos");
       while (len && s[len-1]==' ') len--;
       if (strstart(&s, "NO NAME")) len=0;
@@ -198,6 +199,15 @@ static void do_blkid(int fd, char *name)
     } else if (!strcmp(type, "vfat")) {
         s += sprintf(s, "%02X%02X-%02X%02X", toybuf[uoff+3],
toybuf[uoff+2],
                      toybuf[uoff+1], toybuf[uoff]);
+    } else if (!strcmp(type, "iso9660")) {
+        s += sprintf(s, "%c%c%c%c-", toybuf[uoff], toybuf[uoff+1],
+                     toybuf[uoff+2], toybuf[uoff+3]);
+        s += sprintf(s, "%c%c-", toybuf[uoff+4], toybuf[uoff+5]);
+        s += sprintf(s, "%c%c-", toybuf[uoff+6], toybuf[uoff+7]);
+        s += sprintf(s, "%c%c-", toybuf[uoff+8], toybuf[uoff+9]);
+        s += sprintf(s, "%c%c-", toybuf[uoff+10], toybuf[uoff+11]);
+        s += sprintf(s, "%c%c-", toybuf[uoff+12], toybuf[uoff+13]);
+        s += sprintf(s, "%c%c", toybuf[uoff+14], toybuf[uoff+15]);
     } else {
       for (j = 0; j < 16; j++)
         s += sprintf(s, "-%02x"+!(0x550 & (1<<j)), toybuf[uoff+j]);
-- 
2.39.1
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.landley.net/pipermail/toybox-landley.net/attachments/20230206/4ce8f810/attachment.htm>


More information about the Toybox mailing list