[Toybox] [TOY] lspci

Isaac idunham at lavabit.com
Thu Aug 1 23:31:57 PDT 2013


On Sat, Jul 27, 2013 at 09:56:53AM +0200, Felix Janda wrote:
> Rob Landley wrote:
> > On 07/22/2013 02:05:26 PM, Felix Janda wrote:
> > > > 75 lines total.
> > > 
> > > Down to 70 after application of the below patch with small fixes.
> > > 
> > > It felt more sensible to me to read 2 more bytes and ignore them than  
> > > to
> > > seek for 2 bytes in a file. So preadat_name now has one argument less.
> > > 
> > > Use calloc instead of malloc + memset. With this also the off-by-one
> > > error from (origninally) line 32 is fixed. It would be nice to use
> > > toybuf for this, wouldn't it? That would also make valgrind happier.
> > > 
> > > Print "" instead of "." when .../driver is missing.
> > > 
> > > The only difference between the usual output and the machine readable
> > > output is the format string. Use this to avoid some repetition.
> > > 
> > > Felix
> > 
> > patching file toys/pending/lspci.c
> > Hunk #2 FAILED at 32.
> > Hunk #3 succeeded at 65 (offset 1 line).
> > 1 out of 3 hunks FAILED -- saving rejects to file  
> > toys/pending/lspci.c.rej
> > 
> > Did I miss an intermediate patch? Could you send me a fresh one that  
> > applies to my current tree?
> 
> In the current tree I see that you have applied a newer version anyway.
> (with some minor cleanup of yours.)
> 
> Unfortunately that version has "lspci -e" broken as observed by Isaac
> somewhere in this thread. Below is a fix. (One could also replace the
> "!=" by "==".)
> 
> Anyway Isaac is doing (or planning to do) a major rewrite enabling lspci
> to read the pciid database for human readable names of vendors and devices.

I have a question or two in regards to that.
1-mmap or fgets?
It's a smallish file as data goes (currently~600 kb), and can be searched 
in very little time if mmap()ed. 
The alternative is an fgets() based loop, which could involve 
reading over 11,000 entries, and decent performance would require 
using a linked list for temporary storage, extracting and sorting the entries
from the linked list, looping over the sorted entries and storing the text,
then printing from the linked list (though you can print from the sorted data
if you don't care about order).
I'm thinking mmap sounds more practical.

2-is there a way to allow configuring a path in the toybox build system?
The database can live in several places, so I was thinking to have a 
customizeable default and allow setting the path in kconfig as well.

> 
> Felix


 1375425117.0


More information about the Toybox mailing list