[Toybox] I aten't dead.

Rob Landley rob at landley.net
Thu Feb 26 13:19:28 PST 2015



On 02/26/2015 12:01 PM, Isaac Dunham wrote:
> On Thu, Feb 26, 2015 at 06:26:19AM -0600, Rob Landley wrote:
>> On 02/25/2015 10:27 AM, Isaac Dunham wrote:
>>> On Wed, Feb 25, 2015 at 03:19:23AM -0600, Rob Landley wrote:
>>>> There's a marvelous book called "the unix philosophy" by mike gancarz
>>>> that talks about output intended for humans vs output intended to be
>>>> processed by other tools.
>>>>
>>>> A scriptable tool is one where you can do:
>>>>
>>>>   echo $(( $(wc -l < blah) * 3))
>>>>
>>>> If it's scriptable, the output of one tool is naturally the input to
>>>> another. Admittedly this can be annoying to use from the command line
>>>> such as the way "ls" with no arguments will produce no output when run
>>>> in an empty directory. But the _reason_ for that is so "for i in $(ls);
>>>> do blah $i; done" doesn't have to filter the ls output to use it in a
>>>> script.
>>>
>>> Thread hijack/blkid feature I'd like to see (no need to do it now, I'm
>>> willing to try writing it at a later point).
>>>
>>> I was just fighting with non-scriptable output in another tool:
>>> blkid.
>>
>> Which is why fstype exists, although it only gives you the type not the
>> other attributes.
> 
> I'm actually after just the label/just the uuid.

A properly scriptable solution would be "blkid -s label" producing
_just_ the label output with no escapes or modifiers (which you could
then pipe through base64 or something if you needed that).

I'm not sure whether your use case is "give me this data", "behave like
host blkid", or whether the correct solution is to extend mdev.

>>>  -s <tag>    show specified tag(s) (default show all tags)
>>>
>>> <tag> is TYPE/SEC_TYPE/UUID/PARTUUID/LABEL, and means that only
>>> the fields specified get shown, in the same order as usual.
>>> Example:
>>> blkid -s TYPE -s LABEL -s UUID /dev/sda1
>>> /dev/sda1: LABEL="ECS_CDRUN" UUID="DEAD-BEEF" TYPE="vfat"
>>
>> If it takes a comma separated list and maybe I can get it to share code
>> with ps -o and mount -o.
> 
> No, but a linked list of strings (optstring "s*") should work.

I mean if splitting fields at commas won't interfere. (You can already
provide multiple -o to mount.)

>>> And the ID_FS_LABEL_ENC field of -o udev matches what I'm looking for
>>> exactly.
>>
>> I'm confused: what is your use case?
> 
> Narrowly:
> Populate /dev/disk/by-{label,uuid}/ with symlinks having the same name 
> that udev gives them, so that mount by label and mount by uuid work right.
> 
> Broadly:
> I've been working on a package to allow busybox mdev to replace udev
> in Debian-based distros, which has already gotten some interest from
> others on the "Dng" list ("Dng" stands for "Debian's not Gnome"; it's
> the list for Devuan, the fork of Debian over systemd).

Ooh, possibly I should be subscribed to that list...

> Meanwhile, Jude Nelson has been working on a daemon that should
> be a replacement for udev (vdev); this will use helper scripts much like
> mdev does, and I'm planning to add /dev/disk/by-label/ support for it.
> On Debian/Devuan, I know that blkid is provided by util-linux, but
> I'd rather be *able* to switch out components.

Being able to switch out components is a strong argument for
compatability, and thus this insanely horrible API the blkid people put
together without the foggiest understanding how to make something
scriptable.

Looking at the blkdev man page: I note that the -d flag is nuts, the -c
and -g options are also nuts (why is this the end user's problem?)...

Huh, the -t option's man page entry is broken:

  -t  option.  If there are multiple devices that match the  specified
      search  parameter,  then the device with the highest priority is
      returned, and/or the first device found  at  a  given  priority.
      Device  types in order of decreasing priority are Device Mapper,
      EVMS, LVM, MD, and  finally  regular  block  devices.   If  this
      option  is  not  specified,  blkid will print all of the devices
      that match the search parameter.

Starts in the middle of a sentence...

How -l and -t are supposed to interact is not clear...

  $ sudo blkid /dev/sdb1
  /dev/sdb1: LABEL="SEI" UUID="6E12-2741" TYPE="vfat"
  $ sudo blkid -o value -s label /dev/sdb1
  $ sudo blkid -o value -s LABEL /dev/sdb1
  SEI

And the -s values are case sensitive. Of course they are.

That said, the above appears to be the magic incantation to get LABEL
and UUID fields. I don't have an example of one with an escaped label,
although I point you at the tests/blkid directory if you'd like to
submit one I can poke at.

Would implementing "-o value" and -s FIELD be sufficient for your purposes?

>> In theory properly quoted shell strings shouldn't care what their
>> contents are (modulo NUL bytes and stripping trailing whitespace):
>>
>>   X="$(fruitbat -x)"
>>   command "$X"
>>
>> Should be fine about having semicolons and quotes and stuff in what $X
>> expands to...? So the classic definition of "scriptable" would be not
>> having any LABEL= at all, but instead having a way to request the
>> specific field of interest...?
> 
> Which is  what "blkid -s LABEL -o value" does.

Is using that bad?

> But any of the other 
> 
>> (And if you want a label that's really screwing with mount-by-label, put
>> a / in it.)
> 
> udev/blkid -o udev handles this by converting all "unsafe" chars to
> "\x<hex value>" so a label "/" becomes "/dev/disk/by-label/\x2f".

Hmmm, I remember there being a way to do that...

Not cat -v, not uuencode, not base64... grrr, I remember having done it,
but not how. And of course with blkid -o format controls _both_ labeling
and escaping without any orthogonal control for the specific field.
Because they hate Don Norman.

> Thanks,
> Isaac Dunham

Rob

 1424985568.0


More information about the Toybox mailing list