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

# VOP\_ALLOCATE.9

`VOP_ALLOCATE` — 为文件分配存储空间

## 名称

`VOP_ALLOCATE`

## 概要

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

int
VOP_ALLOCATE(struct vnode *vp, off_t *offset, off_t *len, int ioflag,
    struct ucred *cred)
```

## 描述

此调用为文件中一个偏移量范围分配存储空间。它用于实现 [posix\_fallocate(2)](https://github.com/FreeBSD-Ask/freebsd-man-sc/tree/main/man2/posix_fallocate.2.md) 系统调用。

其参数为：

**`vp`** 文件的 vnode。

**`offset`** 文件中要分配存储空间的范围的起始位置。

**`len`** 文件中要分配存储空间的范围的长度。

**`ioflag`** 要给予文件系统的指令和提示。

**`cred`** 调用者的凭据。

`offset` 和 `len` 参数在返回时被更新以反映仍需分配的范围部分。部分分配被视为成功操作。文件内容不会改变。

## 锁定

文件在入口时应被独占锁定，并在退出时仍将保持锁定状态。

## 返回值

如果调用成功则返回零，否则返回适当的错误代码。

## 错误

**\[`EFBIG`]** 试图写入的文件超过了进程的文件大小限制或最大文件大小。

**\[`ENOSPC`]** 文件系统已满。

**\[`EPERM`]** 文件上设置了仅追加标志，但调用者试图在当前文件末尾之前写入。

## 参见

[vnode(9)](/man/man9/vnode.9.md), VOP\_READ(9), VOP\_WRITE(9)


---

# 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_allocate.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.
