> 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/man/man9/dev_clone.9.md).

# dev\_clone.9

`dev_clone` — devfs 中基于名称的设备克隆事件处理器

## 名称

`dev_clone`, `drain_dev_clone_events`

## 概要

```c
#include <sys/param.h>
#include <sys/conf.h>

void
clone_handler(void *arg, struct ucred *cr, char *name, int namelen,
    struct cdev **dev)
```

```c
EVENTHANDLER_REGISTER(dev_clone, clone_handler, arg, priority);
```

```c
void
drain_dev_clone_events(void)
```

## 描述

设备驱动程序可以注册一个监听器，每当在 [devfs(4)](/man/man4/devfs.4.md) 挂载点上进行的名称查找未能找到 vnode 时，该监听器就会收到通知。监听器应为 `dev_clone` 事件注册。当被调用时，它接收在处理程序注册时指定的第一个参数 `arg`、适当的凭据 `cr`，以及我们要查找的长度为 `namelen` 的名称 `name`。如果处理程序认为该名称合适并希望创建与此名称关联的设备，应在 `dev` 参数中将其返回给 devfs。

`drain_dev_clone_events` 函数是一个屏障。保证在 `drain_dev_clone_events` 调用之前开始的所有 `dev_clone` 事件处理程序调用，都在它返回控制权之前完成。

## 参见

[devfs(4)](/man/man4/devfs.4.md), [namei(9)](/man/man9/namei.9.md)


---

# 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://book.bsdcn.org/man/man9/dev_clone.9.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
