Skip to content

Commit

Permalink
blkid, mount: fix blkid -L and add support for mount LABEL=...
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Kana Steimle authored and landley committed Nov 8, 2024
1 parent 542f627 commit eafb0b6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
3 changes: 3 additions & 0 deletions tests/blkid.test
Original file line number Diff line number Diff line change
Expand Up @@ -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' \
"" ""
Expand Down
9 changes: 8 additions & 1 deletion toys/lsb/mount.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion toys/other/blkid.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit eafb0b6

Please sign in to comment.