> 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/vinvalbuf.9.md).

# vinvalbuf.9

`vinvalbuf` — 刷新并失效与 vnode 关联的所有缓冲区

## 名称

`vinvalbuf`

## 概要

`#include <sys/param.h>`

`#include <sys/vnode.h>`

`int vinvalbuf(struct vnode *vp, int flags, struct ucred *cred, int slpflag, int slptimeo)`

## 描述

`vinvalbuf()` 函数失效与给定 vnode 关联的所有缓冲区。这包括干净列表和脏列表上的缓冲区。如果指定了 `V_SAVE` 标志，则脏列表上的缓冲区在释放之前先同步。如果 vnode 关联有 VM 对象，则将其移除。

其参数如下：

**`vp`** 指向将失效其缓冲区的 vnode 的指针。

**`flags`** 唯一支持的标志是 `V_SAVE`，表示脏缓冲区应与磁盘同步。

**`cred`** 如果设置了 `V_SAVE`，用于 [VOP\_FSYNC(9)](https://github.com/FreeBSD-Ask/freebsd-man-sc/tree/main/man9/vop_fsync.9.md) 缓冲区的用户凭证。

**`slpflag`** 用于函数中任何睡眠优先级的 slp 标志。

**`slptimeo`** 函数中任何睡眠的超时时间。

## 锁

调用前假定 vnode 已被锁定，返回时保持锁定。

调用前必须持有 `Giant`，返回时保持锁定。

## 返回值

成功时返回 0。

## 伪代码

```c
vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
error = vinvalbuf(devvp, V_SAVE, cred, 0, 0);
VOP_UNLOCK(devvp, 0);
if (error)
	return (error);
```

## 错误

**\[`ENOSPC`]** 文件系统已满。（使用 `V_SAVE`）

**\[`EDQUOT`]** 磁盘配额超限。（使用 `V_SAVE`）

**\[`EWOULDBLOCK`]** 睡眠操作超时。（参见 `slptimeo`）

**\[`ERESTART`]** 需要传递信号，应重启系统调用。（在 `slpflag` 中设置 `PCATCH`）

**\[`EINTR`]** 系统被信号中断。（在 `slpflag` 中设置 `PCATCH`）

## 参见

tsleep(9), [VOP\_FSYNC(9)](https://github.com/FreeBSD-Ask/freebsd-man-sc/tree/main/man9/vop_fsync.9.md)

## 作者

本手册页由 Chad David <davidc@acns.ab.ca> 编写。


---

# 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/vinvalbuf.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.
