.\" Copyright 1993 Rickard E. Faith (faith@cs.unc.edu) and .\" and Copyright 2006 Michael Kerrisk .\" .\" %%%LICENSE_START(VERBATIM) .\" Permission is granted to make and distribute verbatim copies of this .\" manual provided the copyright notice and this permission notice are .\" preserved on all copies. .\" .\" Permission is granted to copy and distribute modified versions of this .\" manual under the conditions for verbatim copying, provided that the .\" entire resulting derived work is distributed under the terms of a .\" permission notice identical to this one. .\" .\" Since the Linux kernel and libraries are constantly changing, this .\" manual page may be incorrect or out-of-date. The author(s) assume no .\" responsibility for errors or omissions, or for damages resulting from .\" the use of the information contained herein. The author(s) may not .\" have taken the same level of care in the production of this manual, .\" which is licensed free of charge, as they might when working .\" professionally. .\" .\" Formatted or processed versions of this manual, if unaccompanied by .\" the source, must acknowledge the copyright and authors of this work. .\" %%%LICENSE_END .\" .\" Modified 21 Aug 1994 by Michael Chastain : .\" Removed note about old libc (pre-4.5.26) translating to 'sync'. .\" Modified 15 Apr 1995 by Michael Chastain : .\" Added `see also' section. .\" Modified 13 Apr 1996 by Markus Kuhn .\" Added remarks about fdatasync. .\" Modified 31 Jan 1997 by Eric S. Raymond .\" Modified 18 Apr 2001 by Andi Kleen .\" Fix description to describe what it really does; add a few caveats. .\" 2006-04-28, mtk, substantial rewrite of various parts. .\" 2012-02-27 Various changes by Christoph Hellwig .\" .\"******************************************************************* .\" .\" This file was generated with po4a. Translate the source file. .\" .\"******************************************************************* .\" .\" Japanese Version Copyright (c) 1997 HANATAKA Shinya .\" all rights reserved. .\" Translated 1997-02-22, HANATAKA Shinya .\" Modified 2001-05-19, HANATAKA Shinya .\" Updated 2005-09-06, Akihiro MOTOKI .\" Updated 2006-07-30, Kentaro Shirakata .\" Updated 2007-10-13, Akihiro MOTOKI , LDP v2.65 .\" Updated 2012-04-30, Akihiro MOTOKI .\" .TH FSYNC 2 2014\-08\-19 Linux "Linux Programmer's Manual" .SH 名前 fsync \- メモリー上にあるファイルの内容をストレージデバイス上のものと同期させる .SH 書式 \fB#include \fP .sp \fBint fsync(int \fP\fIfd\fP\fB);\fP .sp \fBint fdatasync(int \fP\fIfd\fP\fB);\fP .sp .in -4n glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7) 参照): .in .sp \fBfsync\fP(): _BSD_SOURCE || _XOPEN_SOURCE .br .\" _POSIX_C_SOURCE\ >=\ 200112L only since glibc 2.8 || /* glibc 2.8 以降では: */ _POSIX_C_SOURCE\ >=\ 200112L .br \fBfdatasync\fP(): _POSIX_C_SOURCE\ >=\ 199309L || _XOPEN_SOURCE\ >=\ 500 .SH 説明 \fBfsync\fP() は、ファイルディスクリプター \fIfd\fP で参照されるファイルの、メモリー内で存在す る修正されたデータ (つまり修正されたバッファーキャッシュページ) を、ディスクデ バイス(またはその他の永続ストレージデバイス) に転送 (「フラッシュ」) し、これ により、システムがクラッシュしたり、再起動された後も、変更された全ての情報が 取り出せるようになる。「フラッシュ」には、ライトスルー (write through) や (存在する場合には) ディスクキャッシュのフラッシュも含まれる。この呼び出しは 転送が終わったとデバイスが報告するまでブロックする。またファイルに結びついた メタデータ情報 (\fBstat\fP(2) 参照) もフラッシュする。 \fBfsync\fP() の呼び出しは、ファイルが存在しているディレクトリのエントリーがディスクへ 書き込まれたことを保証するわけではない。 保証するためには明示的にそのディレクトリのファイルディスクリプターに対しても \fBfsync\fP() する必要がある。 \fBfdatasync\fP() は \fBfsync\fP() と同様であるが、メタデータの扱いが異なる。 \fBfdatasync\fP() は、それ以降のデータ読み込みを正しく扱うためにそのメタデータが必要に ならない限り、変更されたメタデータをフラッシュしない。 例えば、 st_atime や st_mtime (それぞれ最終アクセス時刻、最終修正時刻; \fBstat\fP(2) 参照) の変更はフラッシュを必要としない。 なぜならこれらはそれ以降のデータ読み込みを正しく扱うために 必要ではないからである。 一方、ファイルサイズ (\fBftruncate\fP(2) では \fIst_size\fP) の変更はメタデータのフラッシュが必要である。 \fBfdatasync\fP() の狙いは、全てのメタデータをディスクと同期する必要のない アプリケーションに対して、ディスクアクセスを減らすことである。 .SH 返り値 成功した場合、これらのシステムコールはゼロを返す。 エラーの場合、\-1 が返され、 \fIerrno\fP が適切に設定される。 .SH エラー .TP \fBEBADF\fP \fIfd\fP が有効なオープンされたディスクリプターでない。 .TP \fBEIO\fP 同期操作の間にエラーが発生した。 .TP \fBEROFS\fP, \fBEINVAL\fP \fIfd\fP が同期操作をサポートしてない特殊なファイルを参照している。 .SH 準拠 4.3BSD, POSIX.1\-2001. .SH 可用性 .\" POSIX.1-2001: It shall be defined to -1 or 0 or 200112L. .\" -1: unavailable, 0: ask using sysconf(). .\" glibc defines them to 1. \fBfdatasync\fP() が利用可能な POSIX システムでは、 \fB_POSIX_SYNCHRONIZED_IO\fP が \fI\fP で 0 より大きな値に定義される (\fBsysconf\fP(3) 参照)。 .SH 注意 (Linux はそうではないが) いくつかの UNIX システムでは \fIfd\fP が\fI書き込み可能な\fPファイルディスクリプターでなければならない。 Linux 2.2 以前では、 \fBfdatasync\fP() は \fBfsync\fP() と等価であり、性能面でのメリットはない。 古いカーネルやあまり使われていないファイルシステムの \fBfsync\fP() の実装では、 ディスクキャッシュをフラッシュする方法が分からない場合がある。そのような場合 には、安全に操作が行われることを保証するため、\fBhdparm\fP(8) や \fBsdparm\fP(8) を 使ってディスクキャッシュを無効にする必要がある。 .SH 関連項目 \fBbdflush\fP(2), \fBopen\fP(2), \fBsync\fP(2), \fBsync_file_range\fP(2), \fBhdparm\fP(8), \fBmount\fP(8), \fBsync\fP(1) .SH この文書について この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.79 の一部 である。プロジェクトの説明とバグ報告に関する情報は http://www.kernel.org/doc/man\-pages/ に書かれている。