📄 block dd interfaces.htm
字号:
<a name="nx_id_466"></a>
The
<tt>buf</tt>
structure describes arbitrary I/O, but is usually associated with block
I/O and
<tt>physio</tt>.
<a name="nx_id_467"></a>
The
<tt>buf</tt>
structure does not contain data.
Instead, it contains information about where the data resides and
information about the types of I/O operations.
A systemwide pool of
<tt>buf</tt>
structures exists for block I/O; however, many device
drivers also include locally defined
<tt>buf</tt>
structures for use with the
<tt>physio</tt>
kernel interface.
The following code shows how the
<tt>/dev/xx</tt>
driver could use the systemwide pool of
<tt>buf</tt>
structures with the
<tt>xxminphys</tt>
interface.
</p><p>
</p><pre>xxminphys(bp)
register struct buf *bp; <a name="co_id_76_rtn_1"></a><a href="#co_id_76_1"><strong>[1]</strong></a>
{
<br>.<br>.<br>.<br>
</pre>
<p>
<a name="nx_id_468"></a>
</p><ol>
<p></p><li>
<a name="co_id_76_1"></a>
Declares a pointer to a
<tt>buf</tt>
structure called
<tt>bp</tt>.
The
<tt>xxminphys</tt>
interface references the systemwide pool of
<tt>buf</tt>
structures to perform a variety of tasks, including checking the size of
the requested transfer.
<a href="#co_id_76_rtn_1">[Return to example]</a>
</li></ol><p>
<a name="DeclLocalDefbuf"></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="block%20DD%20interfaces_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="block%20DD%20interfaces_files/TOC.GIF" alt="[Contents]" border="0"></a>
<a href="#ImplBlockDeviceRoutines"><img src="block%20DD%20interfaces_files/REW.GIF" alt="[Previous Chapter]" border="0"></a>
<a href="#UsingSysWidePoolofbuf"><img src="block%20DD%20interfaces_files/PREV.GIF" alt="[Previous Section]" border="0"></a>
<a href="#Understandbufmembers"><img src="block%20DD%20interfaces_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/drivertut14.html"><img src="block%20DD%20interfaces_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="block%20DD%20interfaces_files/INDEX.GIF" alt="[Index]" border="0"></a>
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/HELP.html"><img src="block%20DD%20interfaces_files/HELP.GIF" alt="[Help]" border="0"></a>
</p><p></p><hr><p>
</p><h3>
9.3.2 Declaring Locally Defined buf Structures
</h3>
<p>
The following code shows how the
<tt>/dev/xx</tt>
driver could
declare an array of locally defined
<tt>buf</tt>
structures and reference it with the controller
<tt>attach</tt>
interface:
</p><p>
</p><pre><br>.<br>.<br>.<br>
struct xx_unit {
<br>.<br>.<br>.<br>
struct buf *xxbuf;
<br>.<br>.<br>.<br>
} xx_unit[NXX];
<br>.<br>.<br>.<br>
#define XX TC_OPTION_SLOTS <a name="co_id_77_rtn_1"></a><a href="#co_id_77_1"><strong>[1]</strong></a>
<br>.<br>.<br>.<br>
struct buf xxbuf[NXX]; <a name="co_id_77_rtn_2"></a><a href="#co_id_77_2"><strong>[2]</strong></a>
<br>.<br>.<br>.<br>
xxcattach(ctlr)
struct controller *ctlr; <a name="co_id_77_rtn_3"></a><a href="#co_id_77_3"><strong>[3]</strong></a>
{
struct xx_unit *xxunit; <a name="co_id_77_rtn_4"></a><a href="#co_id_77_4"><strong>[4]</strong></a>
<br>.<br>.<br>.<br>
xxunit->xxbuf = &xxbuf[ctlr->ctlr_num]; <a name="co_id_77_rtn_5"></a><a href="#co_id_77_5"><strong>[5]</strong></a>
</pre>
<p>
<a name="nx_id_469"></a>
</p><ol>
<p></p><li>
<a name="co_id_77_1"></a>
The
<tt>NXX</tt>
constant is used to allocate the
<tt>buf</tt>
structures associated with the
<tt>XX</tt>
devices that currently exist on the system.
<a href="#co_id_77_rtn_1">[Return to example]</a>
<p></p></li><li>
<a name="co_id_77_2"></a>
Declares an array of
<tt>buf</tt>
structures called
<tt>xxbuf</tt>.
The
<tt>NXX</tt>
constant is used to allocate the
<tt>buf</tt>
structures for the maximum number of
<tt>XX</tt>
devices that currently exist on the system.
Thus, there is one
<tt>buf</tt>
structure per
<tt>XX</tt>
device.
<a href="#co_id_77_rtn_2">[Return to example]</a>
<p></p></li><li>
<a name="co_id_77_3"></a>
Declares a pointer to a
<tt>controller</tt>
structure associated with a specific
<tt>XX</tt>
device.
The
<tt>ctlr_num</tt>
member of this pointer is used as an index to obtain a specific
<tt>XX</tt>
device's associated
<tt>buf</tt>
structure.
<a name="nx_id_470"></a>
<a href="#co_id_77_rtn_3">[Return to example]</a>
<p></p></li><li>
<a name="co_id_77_4"></a>
Declares a pointer to the
<tt>xx_unit</tt>
data structure associated with this
<tt>XX</tt>
device.
It contains members that store such information as whether the
<tt>XX</tt>
device is opened and the
<tt>XX</tt>
device's TC slot number.
It also declares a pointer to the
<tt>xxbuf</tt>
structure.
<a name="nx_id_471"></a>
<a href="#co_id_77_rtn_4">[Return to example]</a>
<p></p></li><li>
<a name="co_id_77_5"></a>
Sets the buffer structure address (the
<tt>xxbuf</tt>
member of this
<tt>XX</tt>
device's
<tt>xx_unit</tt>
structure) to the address of this
<tt>XX</tt>
device's
<tt>buf</tt>
structure.
The
<tt>ctlr_num</tt>
member is used as an index into the array of
<tt>buf</tt>
structures associated with this
<tt>XX</tt>
device.
<a href="#co_id_77_rtn_5">[Return to example]</a>
</li></ol><p>
<a name="Understandbufmembers"></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="block%20DD%20interfaces_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="block%20DD%20interfaces_files/TOC.GIF" alt="[Contents]" border="0"></a>
<a href="#ImplBlockDeviceRoutines"><img src="block%20DD%20interfaces_files/REW.GIF" alt="[Previous Chapter]" border="0"></a>
<a href="#DeclLocalDefbuf"><img src="block%20DD%20interfaces_files/PREV.GIF" alt="[Previous Section]" border="0"></a>
<a href="#Theb_flagsMember"><img src="block%20DD%20interfaces_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/drivertut14.html"><img src="block%20DD%20interfaces_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="block%20DD%20interfaces_files/INDEX.GIF" alt="[Index]" border="0"></a>
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/HELP.html"><img src="block%20DD%20interfaces_files/HELP.GIF" alt="[Help]" border="0"></a>
</p><p></p><hr><p>
</p><h3>
9.3.3 Using buf Structure Members Related to Device Drivers
</h3>
<p>
</p><p>
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/drivertut13.html#TheMembersofthebufStruct">Table 9-1</a>
lists the members of the
<tt>buf</tt>
structure along with their associated data types that device drivers
might reference.
</p><p>
<a name="TheMembersofthebufStruct"></a>
</p><h3>
Table 9-1: Members of the buf Structure
</h3>
<a name="nx_id_472"></a>
<table border="4" cellpadding="4">
<tbody><tr>
<td align="left" valign="top">
<strong>
Member Name
</strong>
</td>
<td align="left" valign="top">
<strong>
Data Type
</strong>
</td>
</tr>
<tr>
<td align="left" valign="top">
<tt>b_flags</tt>
</td>
<td align="left" valign="top">
<tt>int</tt>
</td>
</tr>
<tr>
<td align="left" valign="top">
<tt>b_forw</tt>
</td>
<td align="left" valign="top">
<tt>struct buf *</tt>
</td>
</tr>
<tr>
<td align="left" valign="top">
<tt>b_back</tt>
</td>
<td align="left" valign="top">
<tt>struct buf *</tt>
</td>
</tr>
<tr>
<td align="left" valign="top">
<tt>av_forw</tt>
</td>
<td align="left" valign="top">
<tt>struct buf *</tt>
</td>
</tr>
<tr>
<td align="left" valign="top">
<tt>av_back</tt>
</td>
<td align="left" valign="top">
<tt>struct buf *</tt>
</td>
</tr>
<tr>
<td align="left" valign="top">
<tt>b_bcount</tt>
</td>
<td align="left" valign="top">
<tt>int</tt>
</td>
</tr>
<tr>
<td align="left" valign="top">
<tt>b_error</tt>
</td>
<td align="left" valign="top">
<tt>short</tt>
</td>
</tr>
<tr>
<td align="left" valign="top">
<tt>b_dev</tt>
</td>
<td align="left" valign="top">
<tt>dev_t</tt>
</td>
</tr>
<tr>
<td align="left" valign="top">
<tt>b_un.b_addr</tt>
</td>
<td align="left" valign="top">
<tt>caddr_t</tt>
</td>
</tr>
<tr>
<td align="left" valign="top">
<tt>b_lblkno</tt>
</td>
<td align="left" valign="top">
<tt>daddr_t</tt>
</td>
</tr>
<tr>
<td align="left" valign="top">
<tt>b_blkno</tt>
</td>
<td align="left" valign="top">
<tt>daddr_t</tt>
</td>
</tr>
<tr>
<td align="left" valign="top">
<tt>b_resid</tt>
</td>
<td align="left" valign="top">
<tt>int</tt>
</td>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -