1 .\" Hey Emacs! This file is -*- nroff -*- source.
3 .\" Copyright 1993 Rickard E. Faith (faith@cs.unc.edu) and
4 .\" and Copyright 2006 Michael Kerrisk <mtk.manpages@gmail.com>
6 .\" Permission is granted to make and distribute verbatim copies of this
7 .\" manual provided the copyright notice and this permission notice are
8 .\" preserved on all copies.
10 .\" Permission is granted to copy and distribute modified versions of this
11 .\" manual under the conditions for verbatim copying, provided that the
12 .\" entire resulting derived work is distributed under the terms of a
13 .\" permission notice identical to this one.
15 .\" Since the Linux kernel and libraries are constantly changing, this
16 .\" manual page may be incorrect or out-of-date. The author(s) assume no
17 .\" responsibility for errors or omissions, or for damages resulting from
18 .\" the use of the information contained herein. The author(s) may not
19 .\" have taken the same level of care in the production of this manual,
20 .\" which is licensed free of charge, as they might when working
23 .\" Formatted or processed versions of this manual, if unaccompanied by
24 .\" the source, must acknowledge the copyright and authors of this work.
26 .\" Modified 21 Aug 1994 by Michael Chastain <mec@shell.portal.com>:
27 .\" Removed note about old libc (pre-4.5.26) translating to 'sync'.
28 .\" Modified 15 Apr 1995 by Michael Chastain <mec@shell.portal.com>:
29 .\" Added `see also' section.
30 .\" Modified 13 Apr 1996 by Markus Kuhn <mskuhn@cip.informatik.uni-erlangen.de>
31 .\" Added remarks about fdatasync.
32 .\" Modified Fri Jan 31 16:27:42 1997 by Eric S. Raymond <esr@thyrsus.com>
33 .\" Modified 31 Jan 1997 by Eric S. Raymond <esr@thyrsus.com>
34 .\" Modified 18 Apr 2001 by Andi Kleen
35 .\" Fix description to describe what it really does; add a few caveats.
36 .\" 2006-04-28, mtk, substantial rewrite of various parts.
38 .\" Japanese Version Copyright (c) 1997 HANATAKA Shinya
39 .\" all rights reserved.
40 .\" Translated 1997-02-22, HANATAKA Shinya <hanataka@abyss.rim.or.jp>
41 .\" Modified 2001-05-19, HANATAKA Shinya <hanataka@abyss.rim.or.jp>
42 .\" Updated 2005-09-06, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
43 .\" Updated 2006-07-30, Kentaro Shirakata <argrath@ub32.org>
44 .\" Updated 2007-10-13, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v2.65
48 .\"WORD: synchronize 同期させる
50 .TH FSYNC 2 2008-11-07 "Linux" "Linux Programmer's Manual"
52 fsync \- メモリ上にあるファイルの内容をストレージデバイス上のものと同期させる
54 .B #include <unistd.h>
56 .BI "int fsync(int " fd );
58 .BI "int fdatasync(int " fd );
62 .RB ( feature_test_macros (7)
67 _BSD_SOURCE || _XOPEN_SOURCE
69 || /* glibc 2.8 以降では: */ _POSIX_C_SOURCE\ >=\ 200112L
70 .\" _POSIX_C_SOURCE\ >=\ 200112L は glibc 2.8 以降のみ
73 _POSIX_C_SOURCE\ >=\ 199309L || _XOPEN_SOURCE\ >=\ 500
78 で参照されるファイルの内部で持っているデータ
79 (つまりバッファキャッシュページ) のうち修正されたデータを、
80 そのファイルが属するディスクデバイス (またはその他の永続ストレージデバイス)
82 この呼び出しは転送が終わったとデバイスが報告するまでブロックする。
88 の呼び出しは、ファイルが存在しているディレクトリのエントリがディスクへ
90 保証するためには明示的にそのディレクトリのファイル記述子に対しても
99 は、それ以降のデータ読み込みを正しく扱うためにそのメタデータが必要に
100 ならない限り、変更されたメタデータをフラッシュしない。
103 (それぞれ最終アクセス時刻、最終修正時刻;
105 参照) の変更はフラッシュを必要としない。
106 なぜならこれらはそれ以降のデータ読み込みを正しく扱うために
112 の変更はメタデータのフラッシュが必要である。
114 の狙いは、全てのメタデータをディスクと同期する必要のない
115 アプリケーションに対して、ディスクアクセスを減らすことである。
117 成功した場合、これらのシステムコールはゼロを返す。
125 が書き込みのためにオープンされたファイル記述子でない。
130 .BR EROFS ", " EINVAL
132 が同期操作をサポートしてない特殊なファイルを参照している。
134 4.3BSD, POSIX.1-2001.
138 .B _POSIX_SYNCHRONIZED_IO
144 .\" POSIX.1-2001: It shall be defined to -1 or 0 or 200112L.
145 .\" -1: unavailable, 0: ask using sysconf().
146 .\" glibc defines them to 1.
148 データベースやログファイルにアクセスするアプリケーションは、
149 非常に小さなデータの断片の書き込みを行い、その後すぐに
151 を呼び出して、書き込んだデータがハードディスクに物理的に
156 一つは新しく書き込まれたデータに対するものであり、
157 もう一つは inode に格納される修正時刻 (modification time) を
159 修正時刻の更新が不可分な操作 (トランザクション) の一部ではない場合、
161 を使うことで、不必要な inode のディスク書き込み操作を避けることができる。
163 データが配置されているハードディスクの書き込みキャッシュが有効に
168 から戻ってきたとしても、そのデータは実際には永続的な記憶媒体に
170 .\" IDE ディスクのキャッシュを無効にする方法については
178 でディレクトリ・エントリも暗黙のうちに同期する。
180 2.4 より前のカーネルでは巨大なファイルに
198 .BR sync_file_range (2),