[Toybox] [TOY] lspci - no *alloc

Felix Janda felix.janda at posteo.de
Thu Jul 25 01:31:47 PDT 2013


Isaac wrote:
> On Wed, Jul 24, 2013 at 09:20:51PM +0200, Felix Janda wrote:
> > Attached Isaac's toy edited to use toybuf instead of
> > dynamic memory allocation. It could look prettier, though...
> > 
> > Felix
> > 
> Broken:
> /toybox lspci -e
> 00:00.0 Class 0600: 8086
> :27ac
>  
> 00:02.0 Class 0300: 8086
> :27ae
>  
> ..
> /toybox lspci
> 00:00.0 Class 0600: 8086:27ac 
> 00:02.0 Class 0300: 8086:27ae
> ..
> 
> The -e flag should be expanding the width of "class" (it isn't),
> and it should not be making lspci print 3 lines per entry.
> And I'm not sure how to fix it.

Sorry, I obviously didn't test -e...

<      size = 6 + 2*((toys.optflags & FLAG_e) && (p != toybuf));
>      size = 6 + 2*((toys.optflags & FLAG_e) && (p == toybuf));

Or better:

>      size = ((toys.optflags & FLAG_e) && (p == toybuf)) ? 8 : 6;

So I guess that the code is quite hard to comprehend.

> By the way, there are requests for more features (-v/-vv and text output) 
> that would mean slightly different approaches to getting data; (p)readat_name 
> would work in many of these cases, but text output means reading to toybuf
> (which would clobber this), and I would also need to add more fields of varying sizes.

Yeah, I guess I did some premature optimizations. But still the data read from the
/sys files is of relatively small fixed size?

Instead of to toybuf one could also put the buffers on the stack freeing up toybuf
for other purposes.

For the text output the structure of the toy would change a lot if we want to
avoid reparsing the pci id database for each device.

Felix

 1374741107.0


More information about the Toybox mailing list