[TUHS] Were all of you.. Hippies?

Random832 random832 at fastmail.com
Fri Mar 24 23:55:23 AEST 2017


On Fri, Mar 24, 2017, at 06:21, Tim Bradshaw wrote:
> And if, for instance, I have a regular need to enumerate various
> properties of the avatars of the PCI devices in the filesystem, I might
> decide to write a program which does that, rather than patching together
> some arcane mass of cat | sed |awk each time (if even the contents of the
> avatars isn't some awful binary blob, which I think it should not be but
> whether that's a Unixism or not I am not sure).

If you think parsing a binary blob can't be done in a shell script,
you're not trying hard enough. Relevant tools include dd [with the seek
and skip], od, head and tail [in byte count mode of course]. For
creating binary data, printf is sufficient.

If you think that parsing a binary blob *shouldn't* be done in a shell
script, and the suggestion is absolutely horrifying, you're of course
correct.

> (None of this is meant to imply that systems which have such commands
> have got this right -- I completely agree that they should present things
> in the filesystem -- just that they could have got it right and the
> command might still exist.)

List of files opened by lspci:
/sys/bus/pci/devices
/sys/bus/pci/devices/{each
subdirectory}/{resource,irq,vendor,device,class}
/sys/bus/pci/devices/{each subdirectory}/{config,label}
/sys/bus/pci/slots
/usr/share/misc/pci.ids{.gz,}
/etc/passwd and various other files that libc's "nsswitch" getpw* is to
blame for, to locate the home directory for the following
~/.pciids-cache
/etc/udev/udev.conf
{various directories}/hwdb.bin

Honestly I'm not sure how anyone can be aware of how extensive Linux's
/proc and /sys filesystems are and assume that tools like lspci etc are
doing anything but collating data found in them.

The content of all of those files [well, all the /proc ones that are
actually device avatars - i suspect hwdb.bin is not] is textual (often a
single hexadecimal constant), and it's therefore probably possible to
write it in sh and awk if you had to. But what's wrong with C?



More information about the TUHS mailing list