📄 supp static n dynamic config.htm
字号:
</p><p>
</p><ol>
<p></p><li>
<a name="co_id_35_1"></a>
Declares an argument called
<tt><var>op</var></tt>
to contain a constant that describes the
configuration operation to be performed on the driver.
This argument is used in a
<tt>switch</tt>
statement and evaluates to one of the following valid constants:
<tt>CFG_OP_CONFIGURE</tt>,
<tt>CFG_OP_UNCONFIGURE</tt>,
<tt>CFG_OP_QUERY</tt>,
or
<tt>CFG_OP_RECONFIGURE</tt>.
<a href="#co_id_35_rtn_1">[Return to example]</a>
<p></p></li><li>
<a name="co_id_35_2"></a>
Declares a pointer to a
<tt>cfg_attr_t</tt>
data structure called
<tt>indata</tt>
that consists of inputs to the
<tt>none_configure</tt>
interface.
The
<tt>cfgmgr</tt>
framework fills in this data structure.
The
<tt>cfg_attr_t</tt>
data structure is used to represent a variety of information,
including the
<tt>/dev/none</tt>
driver's major number requirements.
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/drivertut10.html#cfg_attrStruct">Section 6.2</a>
describes the
<tt>cfg_attr_t</tt>
structure.
<a href="#co_id_35_rtn_2">[Return to example]</a>
<p></p></li><li>
<a name="co_id_35_3"></a>
Declares an argument called
<tt><var>indatalen</var></tt>
to store the size of this input data structure.
This argument represents the number of
<tt>cfg_attr_t</tt>
structures included in
<tt><var>indata</var></tt>.
<a href="#co_id_35_rtn_3">[Return to example]</a>
<p></p></li><li>
<a name="co_id_35_4"></a>
Used with user-defined operations.
The configuration entry point for user-defined operations is
when the
<tt><var>optype</var></tt>
argument of the driver's
<tt>configure</tt>
interface is
<tt>CFG_OP_USERDEFINED</tt>.
<a href="#co_id_35_rtn_4">[Return to example]</a>
<p></p></li><li>
<a name="co_id_35_5"></a>
Used with user-defined operations.
The configuration entry point for user-defined operations is
when the
<tt><var>optype</var></tt>
argument of the driver's
<tt>configure</tt>
interface is
<tt>CFG_OP_USERDEFINED</tt>.
<a href="#co_id_35_rtn_5">[Return to example]</a>
<p></p></li><li>
<a name="co_id_35_6"></a>
Declares a variable called
<tt><var>retval</var></tt>
to store the return value from the
<tt>register_configuration</tt>
interface.
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/drivertut10.html#UsingCreRtnstoRegContrlDevInfo">Section 6.6.4.3</a>
discusses the
<tt>register_configuration</tt>
interface.
<a href="#co_id_35_rtn_6">[Return to example]</a>
<p></p></li><li>
<a name="co_id_35_7"></a>
Declares a variable called
<tt><var>i</var></tt>
used in the
<tt>for</tt>
loop when
<tt>none_configure</tt>
unconfigures the dynamically configured
<tt>/dev/none</tt>
driver.
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/drivertut10.html#UsingCreRtnstoRegContrlDevInfo">Section 6.6.4.3</a>
shows the use of this
<tt>for</tt>
loop in the
<tt>CFG_OP_UNCONFIGURE</tt>
operation.
<a href="#co_id_35_rtn_7">[Return to example]</a>
<p></p></li><li>
<a name="co_id_35_8"></a>
Declares a variable called
<tt><var>driver_cfg_state</var></tt>
that stores the configuration state (either static or dynamic) of the
driver.
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/drivertut10.html#DetermineConfigState">Section 6.6.3</a>
shows the use of this variable in the
<tt>CFG_OP_CONFIGURE</tt>
operation.
<a href="#co_id_35_rtn_8">[Return to example]</a>
<p></p></li><li>
<a name="co_id_35_9"></a>
Defines a constant that represents the number of configuration lines in
the
<tt>sysconfigtab</tt>
file fragment.
<a href="#co_id_35_rtn_9">[Return to example]</a>
<p></p></li><li>
<a name="co_id_35_10"></a>
Declares an array of
<tt>cfg_attr_t</tt>
data structures and calls it
<tt>cfg_buf</tt>.
The number of
<tt>cfg_attr_t</tt>
structures in the array matches the number of configuration lines
specified in the
<tt>sysconfigtab</tt>
file fragment for this device driver.
The
<tt>cfgmgr</tt>
framework passes the
<tt>cfg_attr_t</tt>
array to the
<tt><var>indata</var></tt>
argument of the driver's
<tt>configure</tt>
interface.
This array contains the strings that are stored in the
<tt>sysconfigtab</tt>
database for this
device driver.
<p>
Thus, for the
<tt>/dev/none</tt>
device driver,
the
<tt>cfgmgr</tt>
framework passes the
<tt>cfg_attr_t</tt>
array to the
<tt><var>indata</var></tt>
argument and the number of
<tt>cfg_attr_t</tt>
structures in the array to the
<tt><var>indatalen</var></tt>
argument of the
<tt>none_configure</tt>
interface.
</p><p>
This code is used to verify the driver during development.
To save space in the final driver product, it is compiled out.
<a href="#co_id_35_rtn_10">[Return to example]</a>
</p></li></ol><p>
<a name="ImplCFG_OP_CONFIGURE"></a>
</p><p></p><hr><p align="center">
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/Digital_UNIX_Bookshelf.html"><img src="supp%20static%20n%20dynamic%20config_files/BOOKSHELF.GIF" alt="[Return to Library]" border="0"></a>
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/TOC.html"><img src="supp%20static%20n%20dynamic%20config_files/TOC.GIF" alt="[Contents]" border="0"></a>
<a href="#ImplConfigureRtn"><img src="supp%20static%20n%20dynamic%20config_files/REW.GIF" alt="[Previous Chapter]" border="0"></a>
<a href="#SetUpConfigureRtn"><img src="supp%20static%20n%20dynamic%20config_files/PREV.GIF" alt="[Previous Section]" border="0"></a>
<a href="#Parsingthecfg_attr_tArray"><img src="supp%20static%20n%20dynamic%20config_files/NEXT.GIF" alt="[Next Section]" border="0"></a>
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/drivertut11.html"><img src="supp%20static%20n%20dynamic%20config_files/FF.GIF" alt="[Next Chapter]" border="0"></a>
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/INDEX.html"><img src="supp%20static%20n%20dynamic%20config_files/INDEX.GIF" alt="[Index]" border="0"></a>
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/HELP.html"><img src="supp%20static%20n%20dynamic%20config_files/HELP.GIF" alt="[Help]" border="0"></a>
</p><p></p><hr><p>
</p><h2>
6.6 Implementing the CFG_OP_CONFIGURE Operation
</h2>
<p>
<a name="nx_id_307"></a>
The
<tt>configure</tt>
interface's
<tt>CFG_OP_CONFIGURE</tt>
operation performs the tasks associated with cooperating with the
<tt>cfgmgr</tt>
framework to complete configure (load) requests of a statically or
dynamically configured driver.
A configure (load) request for a dynamically configured driver is
made as a result of a system manager's use of the
<tt>sysconfig</tt>
utility.
The
<tt>configure</tt>
interface's
<tt>CFG_OP_CONFIGURE</tt>
operation performs the following tasks related to configuring (loading)
the device driver.
Your
<tt>configure</tt>
interface will probably perform most of these tasks and, possibly, some
additional ones.
</p><ul>
<p></p><li>
Parse the attributes in the
<tt>cfg_attr_t</tt>
data structure array
<p></p></li><li>
Initialize the device driver name
<p></p></li><li>
Determine the configuration state
<p></p></li><li>
Register controller and device information
<p></p></li><li>
Register I/O services interfaces and reserve a major number
<p></p></li><li>
Implement callback interfaces
</li></ul><p>
The following sections describe each of these tasks.
<a name="Parsingthecfg_attr_tArray"></a>
</p><p></p><hr><p align="center">
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/Digital_UNIX_Bookshelf.html"><img src="supp%20static%20n%20dynamic%20config_files/BOOKSHELF.GIF" alt="[Return to Library]" border="0"></a>
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/TOC.html"><img src="supp%20static%20n%20dynamic%20config_files/TOC.GIF" alt="[Contents]" border="0"></a>
<a href="#ImplConfigureRtn"><img src="supp%20static%20n%20dynamic%20config_files/REW.GIF" alt="[Previous Chapter]" border="0"></a>
<a href="#ImplCFG_OP_CONFIGURE"><img src="supp%20static%20n%20dynamic%20config_files/PREV.GIF" alt="[Previous Section]" border="0"></a>
<a href="#CheckDevDrvName"><img src="supp%20static%20n%20dynamic%20config_files/NEXT.GIF" alt="[Next Section]" border="0"></a>
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/drivertut11.html"><img src="supp%20static%20n%20dynamic%20config_files/FF.GIF" alt="[Next Chapter]" border="0"></a>
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/INDEX.html"><img src="supp%20static%20n%20dynamic%20config_files/INDEX.GIF" alt="[Index]" border="0"></a>
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/HELP.html"><img src="supp%20static%20n%20dynamic%20config_files/HELP.GIF" alt="[Help]" border="0"></a>
</p><p></p><hr><p>
</p><h3>
6.6.1 Parsing Attributes in the cfg_attr_t Structure Array
</h3>
<p>
<a name="nx_id_308"></a>
One task associated with the
<tt>CFG_OP_CONFIGURE</tt>
operation is to parse the
<tt>cfg_attr_t</tt>
structure array to determine if any of the attributes failed to load.
The following code shows you how to parse the
<tt>cfg_attr_t</tt>
structure array, using the
<tt>/dev/none</tt>
device driver as an example:
</p><p>
</p><p>
</p><pre> switch (op) {
<p>
</p><p>
case CFG_OP_CONFIGURE: <a name="co_id_36_rtn_1"></a><a href="#co_id_36_1"><strong>[1]</strong></a>
</p><p>
</p><p>
bcopy(indata, cfg_buf[0].name, <a name="co_id_36_rtn_2"></a><a href="#co_id_36_2"><strong>[2]</strong></a>
indatalen*(sizeof(cfg_attr_t)));
for(i=0; i < indatalen; i++) <a name="co_id_36_rtn_3"></a><a href="#co_id_36_3"><strong>[3]</strong></a>
switch(cfg_buf[i].type){ <a name="co_id_36_rtn_4"></a><a href="#co_id_36_4"><strong>[4]</strong></a>
case CFG_ATTR_STRTYPE:
break;
default:
switch(cfg_buf[i].status){ <a name="co_id_36_rtn_5"></a><a href="#co_id_36_5"><strong>[5]</strong></a>
case CFG_FRAME_SUCCESS:
break;
default:
printf("%s:",cfg_buf[i].name); <a name="co_id_36_rtn_6"></a><a href="#co_id_36_6"><strong>[6]</strong></a>
switch(cfg_buf[i].status){ <a name="co_id_36_rtn_7"></a><a href="#co_id_36_7"><strong>[7]</strong></a>
case CFG_ATTR_EEXISTS: <a name="co_id_36_rtn_8"></a><a href="#co_id_36_8"><strong>[8]</strong></a>
printf("Attribute does not exist\n");
break;
case CFG_ATTR_EOP:
printf("Attribute does not support operation\n");
break;
case CFG_ATTR_ESUBSYS:
printf("Subsystem Failure\n");
break;
case CFG_ATTR_ESMALL:
printf("Attribute size/value too small\n");
break;
case CFG_ATTR_ELARGE:
printf("Attribute size/value too large\n");
break;
case CFG_ATTR_ETYPE:
printf("Attribute invalid type\n");
break;
case CFG_ATTR_EINDEX:
printf("Attribute invalid index\n");
break;
case CFG_ATTR_EMEM:
printf("Attribute memory allocation error\n");
break;
default:
printf("**Unknown attribute: ");
printf("%x\n", cfg_buf[i].status);
}
}
break;
}
if(none_config == TRUE)
return(EINVAL); <a name="co_id_36_rtn_9"></a><a href="#co_id_36_9"><strong>[9]</strong></a>
</p></pre>
<p>
</p><p>
</p><ol>
<p></p><li>
<a name="co_id_36_1"></a>
Specifies the
<tt>CFG_OP_CONFIGURE</tt>
constant to indicate that this section of code implements the
configure (static and dynamic) driver operation.
The file
<tt>/usr/sys/include/sys/sysconfig.h</tt>
contains the definition of this constant.
<a href="#co_id_36_rtn_1">[Return to example]</a>
<p></p></li><li>
<a name="co_id_36_2"></a>
Calls the
<tt>bcopy</tt>
interface to copy a series of bytes with a specified limit.
<p>
The
<tt>bcopy</tt>
interface takes three arguments:
</p><ul>
<p></p><li>
The first argument is a pointer to a byte string (array of characters).
<p>
In this call, the array of characters is the
<tt>cfg_attr_t</tt>
structure that the
<tt>cfgmgr</tt>
framework passes to the
<tt><var>indata</var></tt>
argument.
</p><p></p></li><li>
The second argument is a pointer to a buffer that is at least the size
specified in the third argument.
<p>
In this call, the buffer is the array of
<tt>cfg_attr_t</tt>
structures called
<tt>cfg_buf</tt>.
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/drivertut10.html#SetUpConfigureRtn">Section 6.5</a>
shows the declaration of this array.
</p><p></p></li><li>
The third argument is the number of bytes to be copied.
<p>
In this call, the number of bytes to copy is the result of the
<tt>sizeof</tt>
operator (in this case the number of bytes associated with the
<tt>cfg_attr_t</tt>
structure).
</p></li></ul><p>
</p><p>
The
<tt>bcopy</tt>
interface copies the
<tt>cfg_attr_t</tt>
structure stored in the
<tt><var>indata</var></tt>
argument to the first element of the
<tt>cfg_buf</tt>
buffer array.
<a name="nx_id_309"></a>
<a name="nx_id_310"></a>
The
<tt>/dev/none</tt>
device driver requests that the
<tt>cfgmgr</tt>
framework initialize the
<tt>none_attributes</tt>
structure with all of the attributes specified for the
<tt>none</tt>
entry in the
<tt>/etc/sysconfigtab</tt>
database.
<a href="#co_id_36_rtn_2">[Return to example]</a>
</p><p></p></li><li>
<a name="co_id_36_3"></a>
Sets up a
<tt>for</tt>
loop to traverse the
<tt>cfg_attr_t</tt>
structure.
The
<tt>for</tt>
loop uses the
<tt><var>indatalen</var></tt>
argument (the size of the
<tt>cfg_attr_t</tt>
structure) to determine how many times the
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -