[Toybox] [TOY] lspci - no *alloc

Isaac idunham at lavabit.com
Thu Jul 25 05:47:42 PDT 2013


On Thu, Jul 25, 2013 at 10:31:47AM +0200, Felix Janda wrote:
> 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?

If by "small" you mean "Probably smaller than toybuf" (see resource and config).

> 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.
I honestly had not thought about that, but really, it is needed if we do that.

Would it work if we save it to a linked list of structs and print at the end? 
Would llist* work with that?
(I'm thinking about putting a pointer in GLOBALS.)
The structs would need char clname[128], devname[128].
Fortunately /usr/share/misc/pci.ids is sorted.

> Felix
> 



 1374756462.0


More information about the Toybox mailing list