POSIX_FALLOCATE

Section: Linux Programmer's Manual (3)
Updated: 2020-11-01
Index JM Home Page
 

名前

posix_fallocate - ファイルのスペースを確保する  

書式

#include <fcntl.h>

int posix_fallocate(int fd, off_t offset, off_t len);

glibc 向けの機能検査マクロの要件 (feature_test_macros(7) 参照):

posix_fallocate():

_POSIX_C_SOURCE >= 200112L
 

説明

関数 posix_fallocate() は、ファイルディスクリプター fd で参照されるファイルに対して、ディスクスペースを確実に確保する。 ディスクスペースは offset から始まる len バイトの範囲のバイトである。 posix_fallocate() の呼び出しが成功した後、指定された範囲のバイトに対する書き込みは、 ディスクスペースの不足で失敗しないことが保証される。

ファイルのサイズが offset+len より小さい場合、ファイルはこのサイズになるように拡大される。 それ以外の場合、ファイルサイズは変わらない。  

返り値

posix_fallocate() は成功した場合、0 を返す。 失敗した場合、エラー番号を返す。 errno が設定されない点に注意すること。  

エラー

EBADF
fd が有効なファイルディスクリプターでないか、 書き込み用としてオープンされていない。
EFBIG
offset+len が最大ファイルサイズを超えている。
EINTR
実行中にシグナルが捕捉された。
EINVAL
offset was less than 0, or len was less than or equal to 0, or the underlying filesystem does not support the operation.
ENODEV
fd が通常のファイルとして参照されていない。
ENOSPC
fd が参照するファイルを含むデバイスに十分な空き領域がない。
EOPNOTSUPP
The filesystem containing the file referred to by fd does not support this operation. This error code can be returned by C libraries that don't perform the emulation shown in NOTES, such as musl libc.
ESPIPE
fd がパイプを参照している。
 

バージョン

posix_fallocate() は glibc 2.1.94 以降で利用可能である。  

属性

この節で使用されている用語の説明については、 attributes(7) を参照。
インターフェース 属性
posix_fallocate() Thread safety MT-Safe (ただし「注意」を参照)
 

準拠

POSIX.1-2001.

POSIX.1-2008 では、 len が 0 の場合、もしくは offset が 0 未満の場合、 EINVAL エラーを返すものとされている。 POSIX.1-2001 では、 len が 0 未満の場合、もしくは offset が 0 未満の場合、 EINVAL エラーを返すものとされている。また、 len が 0 の場合、 EINVAL エラーを返してもよいとされている。  

注意

In the glibc implementation, posix_fallocate() is implemented using the fallocate(2) system call, which is MT-safe. If the underlying filesystem does not support fallocate(2), then the operation is emulated with the following caveats:
*
The emulation is inefficient.
*
There is a race condition where concurrent writes from another thread or process could be overwritten with null bytes.
*
There is a race condition where concurrent file size increases by another thread or process could result in a file whose size is smaller than expected.
*
If fd has been opened with the O_APPEND or O_WRONLY flags, the function fails with the error EBADF.

In general, the emulation is not MT-safe. On Linux, applications may use fallocate(2) if they cannot tolerate the emulation caveats. In general, this is only recommended if the application plans to terminate the operation if EOPNOTSUPP is returned, otherwise the application itself will need to implement a fallback with all the same problems as the emulation provided by glibc.  

関連項目

fallocate(1), fallocate(2), lseek(2), posix_fadvise(2)  

この文書について

この man ページは Linux man-pages プロジェクトのリリース 5.10 の一部である。プロジェクトの説明とバグ報告に関する情報は https://www.kernel.org/doc/man-pages/ に書かれている。

関連キーワード

fallocate, 参照, offset, FALLOCATE, エラー, emulation, 注意, not, operation, EINVAL

Linux マニュアル 一覧

[man1] [man2] [man3] [man4] [man5] [man6] [man7] [man8]
[a] [b] [c] [d] [e] [f] [g] [h] [i] [j] [k] [l] [m] [n] [o] [p] [q] [r] [s] [t] [u] [v] [w] [x] [y] [z]

 

Index

名前
書式
説明
返り値
エラー
バージョン
属性
準拠
注意
関連項目
この文書について

This document was created by man2html, using the manual pages.
Time: 12:08:37 GMT, June 11, 2022