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

# VOP\_ACCESS.9

`VOP_ACCESS` — 检查文件或 Unix 域套接字的访问权限

## 名称

`VOP_ACCESS`, `VOP_ACCESSX`

## 概要

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

int
VOP_ACCESS(struct vnode *vp, accmode_t accmode, struct ucred *cred,
    struct thread *td)

int
VOP_ACCESSX(struct vnode *vp, accmode_t accmode, struct ucred *cred,
    struct thread *td)
```

## 描述

此入口点根据给定凭据检查文件的访问权限。

其参数为：

**`vp`** 要检查的文件的 vnode。

**`accmode`** 所需的访问类型。

**`cred`** 要检查的用户凭据。

**`td`** 正在检查的线程。

`accmode` 是一个掩码，可以包含 \<sys/vnode.h> 中描述的标志，例如 `VREAD`、`VWRITE` 或 `VEXEC`。对于 `VOP_ACCESS`，`accmode` 中可以设置的标志只有 `VEXEC`、`VWRITE`、`VREAD`、`VADMIN` 和 `VAPPEND`。要检查其他标志，必须改用 `VOP_ACCESSX`。

## 锁定

vnode 在入口时将被锁定，并在返回时应保持锁定状态。

## 返回值

如果文件可以以指定方式访问，则返回零，否则返回适当的错误代码。

## 错误

**\[`EPERM`]** 试图更改不可变文件。

**\[`EACCES`]** 文件模式的权限位或 ACL 不允许请求的访问。

## 参见

[vaccess(9)](/man/man9/vaccess.9.md), [vaccess\_acl\_nfs4(9)](/man/man9/vaccess_acl_nfs4.9.md), [vaccess\_acl\_posix1e(9)](/man/man9/vaccess_acl_posix1e.9.md), [vnode(9)](/man/man9/vnode.9.md)

## 作者

本手册页由 Doug Rabson 编写。


---

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