[Toybox] [PATCH] blkid, mount: fix `blkid -L` and add support for `mount LABEL=...`

Kana Steimle kanasteimle at gmail.com
Sat Nov 2 01:30:44 PDT 2024


Fixes `blkid -L`, and uses that to implement `mount LABEL=...`, the
same way
`mount UUID=...` was implemented.

Previously blkid would erroneously print SEC_TYPE="msdos" for vfat
filesystems
when the -L option was passed. This line is moved to only print it when
neither
-U or -L are passed.

Also fixed to match util-linux's blkid behavior better:
SEC_TYPE="msdos" is not
added to the list of tags when the vfat filesystem is fat32 (presumably
because
fat32 is not compatible with msdos). A test is added to check this
behavior.

To create the fat32.bz2 file used by the test, run the following
commands:
$ fallocate -l33M fat32
$ mkfs.vfat -n myfat32 -i 0xB25B2ECB -F 32 fat32
$ bzip2 fat32

It's my first time submitting a patch to any project, so if there's
anything I
should do differently in the future, please let me know.

---

diff -ruN a/tests/blkid.test b/tests/blkid.test
--- a/tests/blkid.test 2024-04-08 18:50:07.000000000 -0700
+++ b/tests/blkid.test 2024-11-01 23:10:15.199427430 -0700
@@ -45,6 +45,9 @@
 testing "vfat" "BLKID vfat" \
   'temp.img: SEC_TYPE="msdos" LABEL="myvfat" UUID="7356-B91D"
TYPE="vfat"\n' \
   "" ""
+testing "fat32" "BLKID fat32" \
+  'temp.img: LABEL="myfat32" UUID="B25B-2ECB" TYPE="vfat"\n' \
+  "" ""
 testing "xfs" "BLKID xfs" \
   'temp.img: LABEL="XFS_test" UUID="d63a1dc3-27d5-4dd4-8b38-
f4f97f495c6f" TYPE="xfs"\n' \
   "" ""
Binary files a/tests/files/blkid/fat32.bz2 and
b/tests/files/blkid/fat32.bz2 differ
diff -ruN a/toys/lsb/mount.c b/toys/lsb/mount.c
--- a/toys/lsb/mount.c 2024-04-08 18:50:07.000000000 -0700
+++ b/toys/lsb/mount.c 2024-11-01 23:48:00.608730582 -0700
@@ -37,7 +37,8 @@
     Autodetects loopback mounts (a file on a directory) and bind
mounts (file
     on file, directory on directory), so you don't need to say --bind
or --loop.
     You can also "mount -a /path" to mount everything in /etc/fstab
under /path,
-    even if it's noauto. DEVICE starting with UUID= is identified by
blkid -U.
+    even if it's noauto. DEVICE starting with UUID= is identified by
blkid -U,
+    and DEVICE starting with LABEL= is identified by blkid -L.
 
 #config SMBMOUNT
 #  bool "smbmount"
@@ -171,6 +172,12 @@
     if (!s || strlen(s)>=sizeof(toybuf)) return error_msg("No uuid
%s", dev);
     strcpy(dev = toybuf, s);
     free(s);
+  } else if (strstart(&dev, "LABEL=")) {
+    char *s = chomp(xrunread((char *[]){"blkid", "-L", dev, 0}, 0));
+
+    if (!s || strlen(s)>=sizeof(toybuf)) return error_msg("No label
%s", dev);
+    strcpy(dev = toybuf, s);
+    free(s);
   }
 
   // Autodetect bind mount or filesystem type
diff -ruN a/toys/other/blkid.c b/toys/other/blkid.c
--- a/toys/other/blkid.c 2024-04-08 18:50:07.000000000 -0700
+++ b/toys/other/blkid.c 2024-11-01 23:09:29.352925418 -0700
@@ -162,13 +162,13 @@
   if (!FLAG(L) && !FLAG(U)) {
     if (!TT.o || !strcasecmp(TT.o, "full")) printf("%s:", name);
     else if (!strcasecmp(TT.o, "export")) show_tag("DEVNAME", name);
+    if (*type=='v' && fstypes[i].magic_len == 4) show_tag("SEC_TYPE",
"msdos");
   }
 
   len = fstypes[i].label_len;
   if (!FLAG(U) && len) {
     s = toybuf+fstypes[i].label_off-off;
     if (!strcmp(type, "vfat") || !strcmp(type, "iso9660")) {
-      if (*type=='v') show_tag("SEC_TYPE", "msdos");
       while (len && s[len-1]==' ') len--;
       if (strstart(&s, "NO NAME")) len=0;
     }


More information about the Toybox mailing list