From eafb0b6bb52257524b36a88f91486663350c729b Mon Sep 17 00:00:00 2001 From: Kana Steimle Date: Wed, 6 Nov 2024 12:35:31 -0800 Subject: [PATCH] blkid, mount: fix `blkid -L` and add support for `mount LABEL=...` 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. --- tests/blkid.test | 3 +++ toys/lsb/mount.c | 9 ++++++++- toys/other/blkid.c | 2 +- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/tests/blkid.test b/tests/blkid.test index bcd38f3d..d0f6fbed 100755 --- a/tests/blkid.test +++ b/tests/blkid.test @@ -45,6 +45,9 @@ testing "squashfs" "BLKID squashfs" 'temp.img: TYPE="squashfs"\n' "" "" 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' \ "" "" diff --git a/toys/lsb/mount.c b/toys/lsb/mount.c index ff0b7e12..84d82e2a 100644 --- a/toys/lsb/mount.c +++ b/toys/lsb/mount.c @@ -37,7 +37,8 @@ config MOUNT 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 @@ static void mount_filesystem(char *dev, char *dir, char *type, 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 --git a/toys/other/blkid.c b/toys/other/blkid.c index f6502e7c..47510393 100644 --- a/toys/other/blkid.c +++ b/toys/other/blkid.c @@ -162,13 +162,13 @@ static void do_blkid(int fd, char *name) 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; } -- 2.39.5