> For the complete documentation index, see [llms.txt](https://book.bsdcn.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://book.bsdcn.org/4.3-bsd-unix-cao-zuo-xi-tong-she-ji-yu-shi-xian/di-san-bu-fen-io-xi-tong/8.3.-kuai-she-bei.md).

# 8.3 块设备

块设备的设备驱动由 `bdevsw` 表中的一个表项描述。块设备最常见的是磁盘机和磁带机。每个 `bdevsw` 结构含以下入口点：

`open`：为 I/O 操作做准备而打开设备。对块特殊设备文件的每次 `open` 系统调用，或在内部为挂载文件系统用 `mount` 系统调用准备设备时，调用设备的 open 入口点。`open()` 例程通常校验关联介质的完好性，例如核实设备在自动配置阶段被识别过、磁带机和磁盘机有介质在线。

`strategy`：发起读或写操作并立即返回。对设备上文件系统的 I/O 请求由系统翻译成对块 I/O 例程 `bread()` 和 `bwrite()` 的调用；这些块 I/O 例程再调用设备的 strategy 例程读写缓存中没有的数据。对 strategy 例程的每次调用给出一个指向 `buf` 结构的指针，其中含 I/O 请求的参数。若请求是同步的，调用者必须（在 `buf` 结构的地址上）入睡等 I/O 完成。

`close`：关闭设备。最后一个关心该设备的客户终止后调用 `close()` 例程——这一语义由更高层的 I/O 设施定义。磁盘设备关闭时无事可做，用空的 `close()` 例程。只支持单客户访问的设备必须把自身重新标记为可用。关闭曾以写方式打开的磁带机，通常导致往磁带写文件结束标记并回卷磁带。

`dump`：把全部物理内存写到设备。dump 入口点用于把内存内容保存到辅存。系统检测到不可恢复错误即将 **崩溃** 时自动转储；转储用于对导致系统崩溃的问题做事后分析。dump 例程在处理器最高优先级下被调用，设备驱动必须轮询设备状态而不能等中断。所有磁盘设备都应支持这一入口点，部分磁带设备也支持。

`psize`：返回磁盘驱动器分区的大小。驱动收到一个逻辑部件号，应返回该部件——通常是磁盘驱动器分区——以 DEV\_BSIZE 块计的大小。这一入口点在自举过程中用来计算崩溃转储的存放位置、确定交换设备的大小。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://book.bsdcn.org/4.3-bsd-unix-cao-zuo-xi-tong-she-ji-yu-shi-xian/di-san-bu-fen-io-xi-tong/8.3.-kuai-she-bei.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
