[PATCH] one more hdparm patch with command line parsing bug fix

Bernhard Fischer rep.nop at aon.at
Sun May 14 18:06:57 UTC 2006


On Sun, May 14, 2006 at 06:01:13PM +0200, Tito wrote:
>On Sunday 14 May 2006 16:55, Tito wrote:
>> On Saturday 13 May 2006 23:01, Tito wrote:
>> > On Saturday 13 May 2006 22:04, you wrote:
>> > > On Sat, May 13, 2006 at 09:24:48PM +0200, Tito wrote:
>> > > >On Saturday 13 May 2006 18:43, Bernhard Fischer wrote:
>> > > >> 
>> > 
>> > BTW:
>> > 
>> > +#define opt_noisy                      (1<<0)
>> > +#define opt_verbose                    (1<<1)
>> > +#define opt_get_identity       (1<<2)
>> > +#define opt_get_geom           (1<<3)
>> > +#define opt_quiet                      (1<<4)
>> > +#define opt_do_flush           (1<<5)
>> > +#define opt_do_ctimings                (1<<6)
>> > +#define opt_do_timings         (1<<7)
>> > 
>> > by doing this for all the options don't we risk to overflow static unsigned int opts = 1; /* noisy is on */
>> > as this was the problem that made impossible to use bb_getoptulflags without additonal patches from
>> > vodz and even with them it was very problematic.
>> > 
>> > Think that we have to manage 38 options
>> > 
>> > #define opt_38th      (1<<37)  ??? is this ok
>> > 
>> > Ciao,
>> > Tito
>> > 
>> 
>> Maybe something like this would resolve the problem of overflowing the var holding opts.
>> 
>> char opt[n]; /* initialize all to '\0' ? maybe memset or the compiler does it for us ? */
>> 
>> #define opt_noisy                     opt[0]
>> #define opt_verbose                opt[1]
>> #define opt_get_identity          opt[2]
>> #define opt_get_geom             opt[3]
>> #define opt_quiet                      opt[4]
>> #define opt_do_flush                opt[5]
>> #define opt_do_ctimings          opt[6]
>> #define opt_do_timings            opt[8]
>> #define set_*		                     opt[x]
>> #define get_*                             opt[y]
>> 
>> and so on.
>> 
>> to turn an option on 
>> opt[0] ='1';
>> 
>> to test
>> 
>> if (opt_verbose)                         /* if (opt[1])
>> 
>> So we could handle whatever number of flags (and/or commandline opts) with one char string
>> and remove about 60 long or int vars.
>> 
>> What do you think about it?
>> 
>> Ciao,
>> Tito
>
>Update, I have tested this with all 61 vars, it works fine but increases the size slightly
>to   text    data     bss     dec     hex filename
>  22110     144     712   22966    59b6 hdparm.o
>:-(

In contrast to ulflags, we can use several optN easily (this is most
likely the smallest thing we can do).

An alternative approach, which i'd expect to be slightly larger than
using several optN is to use one bitfield:
static struct opts_s {
	unsigned noisy:1;
	unsigned and:1;
	unsigned so:1;
	unsigned on:1;
} opts = {1};
if (opts.noisy) {be noisy;}

Accessing the members is, as said, larger than just looking at the bits
in opts1, opts2, opts3.

HTH



More information about the busybox mailing list