📄 block dd interfaces.htm
字号:
<html><head><title>Implementing Block Device Driver Interfaces</title>
<meta name="ROBOTS" content="NOFOLLOW">
<meta name="DESCRIPTION" content="Writing Device Drivers Tutorial: DIGITAL UNIX Version 4.0B documentation set">
<meta name="AUTHOR" content="Copyright (c) Digital Equipment Corporation 1996. All Rights Reserved."></head>
<body>
<a name="ImplBlockDeviceRoutines"></a>
<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="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/drivertut12.html"><img src="block%20DD%20interfaces_files/REW.GIF" alt="[Previous Chapter]" border="0"></a>
<img src="block%20DD%20interfaces_files/BLANK.GIF" border="0">
<a href="#ImplementTheDumpRoutine"><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><h1>9 Implementing Block Device Driver Interfaces</h1>
<p>
Block device drivers can contain the following sections:
</p><ul>
<p></p><li>
A dump section, which
contains a
<tt>dump</tt>
interface
<p></p></li><li>
A
<tt>psize</tt>
section, which
contains a
<tt>psize</tt>
interface
<p></p></li><li>
A strategy section, which
contains a
<tt>strategy</tt>
interface
</li></ul><p>
The following sections explain how to implement or set up each of these
interfaces.
<a name="ImplementTheDumpRoutine"></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>
<img src="block%20DD%20interfaces_files/BLANK.GIF" border="0">
<a href="#ImplementThepsizeRoutine"><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><h2>
9.1 Implementing the dump Interface
</h2>
<p>
<a name="nx_id_461"></a>
A device driver's
<tt>dump</tt>
interface performs the tasks necessary to copy system memory to the dump
device.
The code associated with a
<tt>dump</tt>
interface resides in the dump section of the device
driver.
You specify the entry point for a driver's
<tt>dump</tt>
interface in a
<tt>dsent</tt>
structure.
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/drivertut8.html#dev_swit_tbls">Section 5.4</a>
describes the
<tt>dsent</tt>
structure.
<cite>Writing Device Drivers: Reference</cite>
provides a reference page that gives additional information on the
arguments and tasks associated with
a
<tt>dump</tt>
interface.
</p><p>
To implement a
<tt>dump</tt>
interface you must understand the
<tt>dev_t</tt>
data type, which is discussed in
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/drivertut12.html#Thedev_tDataType">Section 8.1.1</a>.
<a name="nx_id_462"></a>
The following code shows you how to set up a
<tt>dump</tt>
interface, using the
<tt>/dev/xx</tt>
driver as an example:
</p><p>
</p><p>
</p><pre>xxdump(dumpdev)
dev_t dumpdev; <a name="co_id_74_rtn_1"></a><a href="#co_id_74_1"><strong>[1]</strong></a>
{
</pre>
<p>
<br>
<tt>.</tt>
<br>
<tt>.</tt>
<br>
<tt>.</tt>
<br>
</p><p>
</p><ol>
<p></p><li>
<a name="co_id_74_1"></a>
Declares an argument that specifies
the device on which the dump operation should be performed.
The values in this argument are passed to the driver's
<tt>dump</tt>
interface.
Typically, these values specify the disk unit number and partition.
The dump device is often specified explicitly in the target (system)
configuration file.
If the dump device is not explicitly specified in the system
configuration file, the default is to dump to the dump partition of the
system's boot device.
<a href="#co_id_74_rtn_1">[Return to example]</a>
</li></ol><p>
</p><blockquote><p align="center"><font size="+1"><strong>Note</strong></font></p><p>
Digital UNIX does not currently support a
<tt>dump</tt>
interface's ability to copy the contents of system memory to the
specified device.
Device driver writers should not provide a
<tt>dump</tt>
interface for this version of Digital UNIX.
</p></blockquote><p>
<a name="ImplementThepsizeRoutine"></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="#ImplementTheDumpRoutine"><img src="block%20DD%20interfaces_files/PREV.GIF" alt="[Previous Section]" border="0"></a>
<a href="#ImplementTheStrategyRoutine"><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><h2>
9.2 Implementing the psize Interface
</h2>
<p>
<a name="nx_id_463"></a>
A device driver's
<tt>psize</tt>
interface performs the tasks necessary to return the size of a disk
partition.
Typically, only a disk device driver would implement a
<tt>psize</tt>
interface.
The code associated with a
<tt>psize</tt>
interface resides in the
<tt>psize</tt>
section of the device driver.
You specify the entry point for a driver's
<tt>psize</tt>
interface in a
<tt>dsent</tt>
structure.
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/drivertut8.html#dev_swit_tbls">Section 5.4</a>
describes the
<tt>dsent</tt>
structure.
<cite>Writing Device Drivers: Reference</cite>
provides a reference page that gives additional information on the
arguments and tasks associated with
a
<tt>psize</tt>
interface.
See
<cite>Writing Device Drivers: Advanced Topics</cite>
for an example implementation of a
<tt>psize</tt>
interface.
</p><p>
To implement a
<tt>psize</tt>
interface you must understand the
<tt>dev_t</tt>
data type, which is discussed in
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/drivertut12.html#Thedev_tDataType">Section 8.1.1</a>.
<a name="nx_id_464"></a>
The following code shows you how to set up a
<tt>psize</tt>
interface, using the
<tt>/dev/xx</tt>
driver as an example:
</p><p>
</p><p>
</p><pre>xxpsize(dev)
dev_t dev; <a name="co_id_75_rtn_1"></a><a href="#co_id_75_1"><strong>[1]</strong></a>
{
</pre>
<p>
<br>
<tt>.</tt>
<br>
<tt>.</tt>
<br>
<tt>.</tt>
<br>
</p><p>
</p><ol>
<p></p><li>
<a name="co_id_75_1"></a>
Declares an argument that specifies
the device and partition for which the size is being requested.
<a href="#co_id_75_rtn_1">[Return to example]</a>
</li></ol><p>
<a name="ImplementTheStrategyRoutine"></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="#ImplementThepsizeRoutine"><img src="block%20DD%20interfaces_files/PREV.GIF" alt="[Previous Section]" border="0"></a>
<a href="#UsingSysWidePoolofbuf"><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><h2>
9.3 Implementing the strategy Interface
</h2>
<p>
<a name="nx_id_465"></a>
A device driver's
<tt>strategy</tt>
interface performs the tasks necessary to perform block I/O for block
devices and to initiate read and write operations for character devices.
The code associated with a
<tt>strategy</tt>
interface resides in the strategy section of the device
driver.
You specify the entry point for a driver's
<tt>strategy</tt>
interface in a
<tt>dsent</tt>
structure.
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/drivertut8.html#dev_swit_tbls">Section 5.4</a>
describes the
<tt>dsent</tt>
structure.
<cite>Writing Device Drivers: Reference</cite>
provides a reference page that gives additional information on the
arguments and tasks associated with
a
<tt>strategy</tt>
interface.
</p><p>
Although the strategy section applies to block device drivers,
character device drivers can also contain a
<tt>strategy</tt>
interface
that is called by the character driver's
<tt>read</tt>
and
<tt>write</tt>
interfaces.
</p><p>
The following list describes some typical tasks that you perform when
implementing
a
<tt>strategy</tt>
interface:
</p><ul>
<p></p><li>
Use the system wide pool of
<tt>buf</tt>
structures
<p></p></li><li>
Use locally defined
<tt>buf</tt>
structures
<p></p></li><li>
Use the
<tt>buf</tt>
structure
<p></p></li><li>
Use buffer cache management
<p></p></li><li>
Set up the
<tt>strategy</tt>
interface
</li></ul><p>
Your
<tt>strategy</tt>
interface will probably perform most of these tasks and, possibly, some
additional ones.
The following sections describe each of these tasks, using the
<tt>/dev/xx</tt>
driver as an example.
<a name="UsingSysWidePoolofbuf"></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="#ImplementTheStrategyRoutine"><img src="block%20DD%20interfaces_files/PREV.GIF" alt="[Previous Section]" border="0"></a>
<a href="#DeclLocalDefbuf"><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.1 Using the Systemwide Pool of buf Structures
</h3>
<p>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -