.\" 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 2020\-06\-09 Linux "Linux Programmer's Manual" .SH 名前 fsync \- メモリー上にあるファイルの内容をストレージデバイス上のものと同期させる .SH 書式 \fB#include \fP .PP \fBint fsync(int \fP\fIfd\fP\fB);\fP .PP \fBint fdatasync(int \fP\fIfd\fP\fB);\fP .PP .RS -4 glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7) 参照): .RE .PP \fBfsync\fP(): 2.16 以降: No feature test macros need be defined glibc 2.15 以前: _BSD_SOURCE || _XOPEN_SOURCE || /* since glibc 2.8: */ _POSIX_C_SOURCE\ >=\ 200112L .br \fBfdatasync\fP(): _POSIX_C_SOURCE\ >=\ 199309L || _XOPEN_SOURCE\ >=\ 500 .SH 説明 \fBfsync\fP() transfers ("flushes") all modified in\-core data of (i.e., modified buffer cache pages for) the file referred to by the file descriptor \fIfd\fP to the disk device (or other permanent storage device) so that all changed information can be retrieved even if the system crashes or is rebooted. This includes writing through or flushing a disk cache if present. The call blocks until the device reports that the transfer has completed. .PP As well as flushing the file data, \fBfsync\fP() also flushes the metadata information associated with the file (see \fBinode\fP(7)). .PP \fBfsync\fP() の呼び出しは、ファイルが存在しているディレクトリのエントリーがディスクへ 書き込まれたことを保証するわけではない。 保証するためには明示的にそのディレクトリのファイルディスクリプターに対しても \fBfsync\fP() する必要がある。 .PP \fBfdatasync\fP() は \fBfsync\fP() と同様であるが、メタデータの扱いが異なる。 \fBfdatasync\fP() は、それ以降のデータ読み込みを正しく扱うためにそのメタデータが必要に ならない限り、変更されたメタデータをフラッシュしない。 例えば、 st_atime や st_mtime (それぞれ最終アクセス時刻、最終修正時刻; \fBinode\fP(7) 参照) の変更はフラッシュを必要としない。 なぜならこれらはそれ以降のデータ読み込みを正しく扱うために 必要ではないからである。 一方、ファイルサイズ (\fBftruncate\fP(2) では \fIst_size\fP) の変更はメタデータのフラッシュが必要である。 .PP \fBfdatasync\fP() の狙いは、全てのメタデータをディスクと同期する必要のない アプリケーションに対して、ディスクアクセスを減らすことである。 .SH 返り値 成功した場合、これらのシステムコールはゼロを返す。 エラーの場合、\-1 が返され、 \fIerrno\fP が適切に設定される。 .SH エラー .TP \fBEBADF\fP \fIfd\fP が有効なオープンされたディスクリプターでない。 .TP \fBEIO\fP .\" commit 088737f44bbf6378745f5b57b035e57ee3dc4750 An error occurred during synchronization. This error may relate to data written to some other file descriptor on the same file. Since Linux 4.13, errors from write\-back will be reported to all file descriptors that might have written the data which triggered the error. Some filesystems (e.g., NFS) keep close track of which data came through which file descriptor, and give more precise reporting. Other filesystems (e.g., most local filesystems) will report errors to all file descriptors that were open on the file when the error was recorded. .TP \fBENOSPC\fP Disk space was exhausted while synchronizing. .TP \fBEROFS\fP, \fBEINVAL\fP \fIfd\fP が同期操作をサポートしてない特殊なファイル (パイプ、FIFO、ソケットなど) を参照している。 .TP \fBENOSPC\fP, \fBEDQUOT\fP \fIfd\fP is bound to a file on NFS or another filesystem which does not allocate space at the time of a \fBwrite\fP(2) system call, and some previous write failed due to insufficient storage space. .SH 準拠 POSIX.1\-2001, POSIX.1\-2008, 4.3BSD. .PP .\" 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ファイルディスクリプターでなければならない。 .PP Linux 2.2 以前では、 \fBfdatasync\fP() は \fBfsync\fP() と等価であり、性能面でのメリットはない。 .PP 古いカーネルやあまり使われていないファイルシステムの \fBfsync\fP() の実装では、ディスクキャッシュをフラッシュする方法が分からない場合がある。そのような場合には、安全に操作が行われることを保証するため、\fBhdparm\fP(8) や \fBsdparm\fP(8) を使ってディスクキャッシュを無効にする必要がある。 .SH 関連項目 \fBsync\fP(1), \fBbdflush\fP(2), \fBopen\fP(2), \fBposix_fadvise\fP(2), \fBpwritev\fP(2), \fBsync\fP(2), \fBsync_file_range\fP(2), \fBfflush\fP(3), \fBfileno\fP(3), \fBhdparm\fP(8), \fBmount\fP(8) .SH この文書について この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 5.10 の一部である。プロジェクトの説明とバグ報告に関する情報は \%https://www.kernel.org/doc/man\-pages/ に書かれている。