[Toybox] About blkid -U and -L
Dony Dominic
donydominic2021 at gmail.com
Fri Jul 31 12:28:23 UTC 2026
Hey, I checked /toys/lsb/mount.c.
mount invokes blkid, which expects some value for -U and -L.
$ sudo ./toybox mount UUID='' "$tmpdir/mnt"
mount: No uuid
$ sudo ./toybox mount LABEL='' "$tmpdir/mnt"
mount: No label
-------------------------------------------------------------------------------------------------
// NOTE : omitted some irrelevant lines
char *s = chomp(xrunread((char *[]){"blkid", "-U", dev, 0}, 0));
if (!s || strlen(s)>=sizeof(toybuf)) return error_msg("No uuid %s",
dev);
char *s = chomp(xrunread((char *[]){"blkid", "-L", dev, 0}, 0));
if (!s || strlen(s)>=sizeof(toybuf)) return error_msg("No label %s",
dev);
-------------------------------------------------------------------------------------------------
I wanted to ask whether this behavior change is desirable for Toybox.
Also, while referencing blkid (util-linux).
I found blkid (toybox) reporting UUID_SUB (device UUID) as UUID (filesystem
UUID).
Is it intentional?
and an offset issue for extracting "label" from superblock.
/*
* ====== linux ========== (from linux/fs/btrfs/fs.h : struct
btrfs_super_block)
* uuid offset : 0x20
* magic offset : 0x40
* dev_item offset : 0xc9
* uuid_sub offset : 0x10b (dev_item.uuid)
* label offset : 0x12b
*
* ====== toybox ========== (from fstypes[] in blkid.c)
* uuid offset : 0x10b
* magic offset : 0x40
* label offset : 0x11b
*/
$ blkid
/dev/sda2: LABEL="donyd" UUID="a11d14b6-79ff-4e25-9760-36f6a9dd3e99"
UUID_SUB="04035241-f737-47cb-8cee-dd18767a6fa9" BLOCK_SIZE="4096"
TYPE="btrfs" PARTUUID="15baa080-c34c-4137-94b1-938e6674213a"
$ sudo ./toybox blkid /dev/sda2 # current behaviour
/dev/sda2: LABEL="��y�N%�`6���>�donyd"
UUID="04035241-f737-47cb-8cee-dd18767a6fa9" TYPE="btrfs"
$ sudo ./toybox blkid /dev/sda2 # after adjusting offset
/dev/sda2: LABEL="donyd" UUID="a11d14b6-79ff-4e25-9760-36f6a9dd3e99"
TYPE="btrfs"
Open to suggestions.
Thank you
On Fri, 24 Jul 2026 at 01:25, enh <enh at google.com> wrote:
> On Thu, Jul 23, 2026 at 3:51 PM Rob Landley via Toybox
> <toybox at lists.landley.net> wrote:
> >
> > 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?
>
> looking at external/toybox/Android.bp, blkid is something we build but
> do not install a symlink for.
>
> (and a quick test on a real device suggests it's not a case where
> we're installing some other blkid in its place.)
>
> > 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
> > _______________________________________________
> > Toybox mailing list
> > Toybox at lists.landley.net
> > https://lists.landley.net/mailman/listinfo/toybox
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.landley.net/pipermail/toybox/attachments/20260731/9117bbd4/attachment.htm>
More information about the Toybox
mailing list