Subject: Re: Reading sysctl values in the kernel
To: Alan Ritter <rittera@cc.wwu.edu>
From: Andrew Brown <atatat@atatdot.net>
List: tech-kern
Date: 07/24/2005 21:42:39
>>>          sysctl_createv(&sc->sysctllog, 0, NULL, NULL,
>>>                  CTLFLAG_READWRITE|CTLFLAG_OWNDESC, CTLTYPE_STRING,
>>>                  vals->nc_cfgkey, vals->nc_cfgdesc, NULL,
>>>                        0, vals->nc_val, strlen(vals->nc_val),
>>>                        ndis_node->sysctl_num, CTL_CREATE, CTL_EOL);
>>
>> that works.  okay, so you have "n" children and not "1".
>>
>> i note, however, that you're telling the sysctl subsystem to copy (and
>> "own") the description, but not the data actually being instrumented.
>> since these are writeable values, i presume you're taking care that
>> the space for the data is not going to be reused accidentally?
>
>The "vals" structure here is a pointer into an array of structures
>(ndis_regvals[]) which is staticly initialized in ndis_driver_data.h,
>which is the file generated from the Windows .sys and .inf files using the
>ndiscvt utility (probably more information than you wanted :-)  Anyway, I
>don't think it would get re-used for anything, but I should go through the
>rest of the NDIS code, and make sure.

i was just confused by the use of CTLFLAG_OWNDESC and no use of
CTLFLAG_OWNDATA where both are addressed from the same structure.

>> also,
>> the space alloted for each "value" is only as large as the space you
>> indicate here (via the strlen() call).
>
>does sysctl_createv() allocate space to store the sysctl_data
>(sysctl_un.scu_data.sud_data) field in?  I took a brief look at the source
>for sysctl_createv() and it didn't seem like it.  Maybe there's something
>I'm missing here.

sysctl_createv() calls sysctl_create() which abuses^Wuses
CTLFLAG_OWNDATA for you.  if you also give a pointer to data, it will
copy it into place for you.  see the code in sysctl_create()
immediately following the comment "at this point, if sz is zero..."

>anyway thanks again, I'm really glad that the dynamic sysctl interface is
>there for me to use :-)

i hope you're finding it easy to use and not too convoluted.  :)

-- 
|-----< "CODE WARRIOR" >-----|
codewarrior@daemon.org             * "ah!  i see you have the internet
twofsonet@graffiti.com (Andrew Brown)                that goes *ping*!"
werdna@squooshy.com       * "information is power -- share the wealth."