[Toybox] About blkid -U and -L
Rob Landley
rob at landley.net
Thu Jul 23 19:44:39 UTC 2026
On 7/22/26 10:15, Dony Dominic via Toybox wrote:
> I am implementing "TODO: -U and -L should require arguments", in
> toys/other/blkid.c at line 5.
Hmmm, I don't currently remember what I meant when I left myself that
todo. (If we start requiring an argument we break the existing behavior.)
One hiccup is that -U with no arguments scans devices and shows uuids,
which implies that -U /dev/sda would show the UUID of _just_ sda, but
the --help text implies that -U _with_ an argument searches for a device
with that UUID, ala -U 01234567-89ab-cdef-0123-456789abcdef says
/dev/sda3 or something. Which is NOT the same as blkid -U /dev/sda3
spitting out the hash...
Sigh, is there a HOST blkid command? I haven't got one installed and
searching the debian repo just finds "libblkid1" which is not it... Brad
Conroy hasn't been around recently, has he? I need to change that ftp://
URL at the top... the resulting doc is still there on the web site but
not immediately useful (it's library docs again)...
Ok, https://man7.org/linux/man-pages/man8/blkid.8.html is presumably
what I'm looking for. (Is it installed with/by libblkid...?)
-U, --uuid uuid
Look up the device that uses this filesystem uuid. For more
details see the --label option.
(Oh duh, it _is_ installed, I keep forgetting that debian doesn't put
sbin in the $PATH when you're not logged in as root. I guess I forgot to
fix that last time I reinstalled my laptop...)
So the TODO meant that the other blkid command is doing -U HASH and
finding a device, and we should support that. Which isn't what _I_ would
have thought it would do, I'd have thought:
$ toybox blkid NetBSD-10.1-amd64.iso
NetBSD-10.1-amd64.iso: LABEL="NETBSD_101" UUID="2024-12-16-13-08-11-00"
TYPE="iso9660"
$ toybox blkid -U NetBSD-10.1-amd64.iso
blkid: /dev/mmcblk0: Permission denied
blkid: /dev/mmcblk0p1: Permission denied
blkid: /dev/sda: Permission denied
blkid: /dev/sda1: Permission denied
blkid: /dev/sda2: Permission denied
Which I guess is:
$ toybox blkid -s UUID NetBSD-10.1-amd64.iso
NetBSD-10.1-amd64.iso: UUID="2024-12-16-13-08-11-00"
In a very non-unix way, needs sed to implement:
if [ "$UUID" = "$(blkid -s UUID NetBSD-10.1-amd64.iso)" ]
Either way, non-obvious. There is definitely something to fix here, but
I'd need to squint at the existing command and possibly lament people
not understanding unix...
> Currently both -U and -L flags prints all the UUIDs and LABELS of each
> devices respectively.
>
> My approach is, which passes "make test_blkid" after rebuild:
> 1.
> USE_BLKID(NEWTOY(blkid, "ULo:s*[!LU]", TOYFLAG_BIN|TOYFLAG_LINEBUF))
> to
> USE_BLKID(NEWTOY(blkid, "U:L:o:s*[!LU]", TOYFLAG_BIN|TOYFLAG_LINEBUF))
Which means that in the previous version "blkid -U" did something that's
no longer doable, and would currently break mount. And I can't just have
mount do the -s thing because gratuitous extra output, which yes is in
the util-linux version:
$ /sbin/blkid -s UUID NetBSD-10.1-amd64.iso
NetBSD-10.1-amd64.iso: UUID="2024-12-16-13-08-11-00"
$ /sbin/blkid -U NetBSD-10.1-amd64.iso
$
> 2.
> GLOBALS(
> struct arg_list *s;
> char *o;
> )
>
> to
>
> GLOBALS(
> struct arg_list *s;
> char *o;
> char *l;
> char *u;
> )
Stylistically I tend to go "char *o, *l, *u;" on the same line, and if
the options are -U and -L then the variables would be capitalized too,
but that's easy to fix later.
> and the existing parser logic handles the cases of -U and -L with no
> arguments :
>
> $ sudo ./toybox blkid -U
> blkid: Missing argument to -U (see "blkid --help")
> $ sudo ./toybox blkid -L
> blkid: Missing argument to -L (see "blkid --help")
For a definition of "handles" that means "no longer does what it used to
do. Which is a problem because toys/lsb/mount.c is running blkid -U and
blkid -U to implement its UUID= and LABEL= options.
> but in the usage comment, the current implementation expects to dump all
> UUIDs and LABELs with -U and -L,respectively,with no arguments.
> /*
> -U Show UUID only (or device with that UUID)
> -L Show LABEL only (or device with that LABEL)
> */
>
> I wanted to ask whether this is the right direction? Open to suggestions.
> Thank you
Alas I don't really use this command enough to have a proper feel for
what it _should_ do. Ask Elliott maybe?
The /sbin/blkid --help output says:
-L, --label <label> convert LABEL to device name
-U, --uuid <uuid> convert UUID to device name
And I guess we should match it, but there's some fixing up to do. And I
don't understand why they'd have:
-t, --match-token <token> find device with a specific token
(NAME=value pair)
And _also_ have -L and -U if that's what they're doing...? Isn't -U XXX
just a synonym for blkid -t UUID=XXX ?
(So many options in /sbin/blkid's help output. Garbage collect? Cache
file? Overwrite device size? Gather information about I/O limits? What's
this "usage" you can filter by?)
Rob
More information about the Toybox
mailing list