OSDN Git Service

Import translated manuals from JM CVS Repository.
[linuxjm/jm.git] / manual / LDP_man-pages / draft / man2 / fsync.2
1 .\" Hey Emacs! This file is -*- nroff -*- source.
2 .\"
3 .\" Copyright 1993 Rickard E. Faith (faith@cs.unc.edu) and
4 .\" and Copyright 2006 Michael Kerrisk <mtk.manpages@gmail.com>
5 .\"
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.
9 .\"
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.
14 .\"
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
21 .\" professionally.
22 .\"
23 .\" Formatted or processed versions of this manual, if unaccompanied by
24 .\" the source, must acknowledge the copyright and authors of this work.
25 .\"
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.
37 .\"
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
45 .\"
46 .\"WORD:        core                    ¥á¥â¥ê
47 .\"WORD:        disk                    ¥Ç¥£¥¹¥¯
48 .\"WORD:        synchronize             Æ±´ü¤µ¤»¤ë
49 ..\"
50 .TH FSYNC 2 2008-11-07 "Linux" "Linux Programmer's Manual"
51 .\"O .SH NAME
52 .SH Ì¾Á°
53 .\"O fsync, fdatasync \- synchronize a file's in-core state with storage device
54 fsync \- ¥á¥â¥ê¾å¤Ë¤¢¤ë¥Õ¥¡¥¤¥ë¤ÎÆâÍƤò¥¹¥È¥ì¡¼¥¸¥Ç¥Ð¥¤¥¹¾å¤Î¤â¤Î¤ÈƱ´ü¤µ¤»¤ë
55 .\"O .SH SYNOPSIS
56 .SH ½ñ¼°
57 .B #include <unistd.h>
58 .sp
59 .BI "int fsync(int " fd );
60 .sp
61 .BI "int fdatasync(int " fd );
62 .sp
63 .in -4n
64 .\"O Feature Test Macro Requirements for glibc (see
65 .\"O .BR feature_test_macros (7)):
66 glibc ¸þ¤±¤Îµ¡Ç½¸¡ºº¥Þ¥¯¥í¤ÎÍ×·ï
67 .RB ( feature_test_macros (7)
68 »²¾È):
69 .in
70 .sp
71 .BR fsync ():
72 _BSD_SOURCE || _XOPEN_SOURCE
73 .br
74 .\"O          || /* since glibc 2.8: */ _POSIX_C_SOURCE\ >=\ 200112L
75          || /* glibc 2.8 °Ê¹ß¤Ç¤Ï: */ _POSIX_C_SOURCE\ >=\ 200112L
76 .\"O .\" _POSIX_C_SOURCE\ >=\ 200112L only since glibc 2.8
77 .\" _POSIX_C_SOURCE\ >=\ 200112L ¤Ï glibc 2.8 °Ê¹ß¤Î¤ß
78 .br
79 .BR fdatasync ():
80 _POSIX_C_SOURCE\ >=\ 199309L || _XOPEN_SOURCE\ >=\ 500
81 .\"O .SH DESCRIPTION
82 .SH ÀâÌÀ
83 .\"O .BR fsync ()
84 .\"O transfers ("flushes") all modified in-core data of
85 .\"O (i.e., modified buffer cache pages for) the
86 .\"O file referred to by the file descriptor
87 .\"O .I fd
88 .\"O to the disk device (or other permanent storage device)
89 .\"O where that file resides.
90 .BR fsync ()
91 ¤Ï¡¢¥Õ¥¡¥¤¥ëµ­½Ò»Ò
92 .I fd
93 ¤Ç»²¾È¤µ¤ì¤ë¥Õ¥¡¥¤¥ë¤ÎÆâÉô¤Ç»ý¤Ã¤Æ¤¤¤ë¥Ç¡¼¥¿
94 (¤Ä¤Þ¤ê¥Ð¥Ã¥Õ¥¡¥­¥ã¥Ã¥·¥å¥Ú¡¼¥¸) ¤Î¤¦¤Á½¤Àµ¤µ¤ì¤¿¥Ç¡¼¥¿¤ò¡¢
95 ¤½¤Î¥Õ¥¡¥¤¥ë¤¬Â°¤¹¤ë¥Ç¥£¥¹¥¯¥Ç¥Ð¥¤¥¹ (¤Þ¤¿¤Ï¤½¤Î¾¤Î±Ê³¥¹¥È¥ì¡¼¥¸¥Ç¥Ð¥¤¥¹)
96 ¤ËžÁ÷ (¡Ö¥Õ¥é¥Ã¥·¥å¡×) ¤¹¤ë¡£
97 .\"O The call blocks until the device reports that the transfer has completed.
98 .\"O It also flushes metadata information associated with the file (see
99 .\"O .BR stat (2)).
100 ¤³¤Î¸Æ¤Ó½Ð¤·¤ÏžÁ÷¤¬½ª¤ï¤Ã¤¿¤È¥Ç¥Ð¥¤¥¹¤¬Êó¹ð¤¹¤ë¤Þ¤Ç¥Ö¥í¥Ã¥¯¤¹¤ë¡£
101 ¤Þ¤¿¥Õ¥¡¥¤¥ë¤Ë·ë¤Ó¤Ä¤¤¤¿¥á¥¿¥Ç¡¼¥¿¾ðÊó
102 .RB ( stat (2)
103 »²¾È) ¤â¥Õ¥é¥Ã¥·¥å¤¹¤ë¡£
104
105 .\"O Calling
106 .\"O .BR fsync ()
107 .\"O does not necessarily ensure
108 .\"O that the entry in the directory containing the file has also reached disk.
109 .\"O For that an explicit
110 .\"O .BR fsync ()
111 .\"O on a file descriptor for the directory is also needed.
112 .BR fsync ()
113 ¤Î¸Æ¤Ó½Ð¤·¤Ï¡¢¥Õ¥¡¥¤¥ë¤¬Â¸ºß¤·¤Æ¤¤¤ë¥Ç¥£¥ì¥¯¥È¥ê¤Î¥¨¥ó¥È¥ê¤¬¥Ç¥£¥¹¥¯¤Ø
114 ½ñ¤­¹þ¤Þ¤ì¤¿¤³¤È¤òÊݾڤ¹¤ë¤ï¤±¤Ç¤Ï¤Ê¤¤¡£
115 Êݾڤ¹¤ë¤¿¤á¤Ë¤ÏÌÀ¼¨Åª¤Ë¤½¤Î¥Ç¥£¥ì¥¯¥È¥ê¤Î¥Õ¥¡¥¤¥ëµ­½Ò»Ò¤ËÂФ·¤Æ¤â
116 .BR fsync ()
117 ¤¹¤ëɬÍפ¬¤¢¤ë¡£
118
119 .\"O .BR fdatasync ()
120 .\"O is similar to
121 .\"O .BR fsync (),
122 .\"O but does not flush modified metadata unless that metadata
123 .\"O is needed in order to allow a subsequent data retrieval to be
124 .\"O correctly handled.
125 .BR fdatasync ()
126 ¤Ï
127 .BR fsync ()
128 ¤ÈƱÍͤǤ¢¤ë¤¬¡¢¥á¥¿¥Ç¡¼¥¿¤Î°·¤¤¤¬°Û¤Ê¤ë¡£
129 .BR fdatasync ()
130 ¤Ï¡¢¤½¤ì°Ê¹ß¤Î¥Ç¡¼¥¿Æɤ߹þ¤ß¤òÀµ¤·¤¯°·¤¦¤¿¤á¤Ë¤½¤Î¥á¥¿¥Ç¡¼¥¿¤¬É¬ÍפË
131 ¤Ê¤é¤Ê¤¤¸Â¤ê¡¢Êѹ¹¤µ¤ì¤¿¥á¥¿¥Ç¡¼¥¿¤ò¥Õ¥é¥Ã¥·¥å¤·¤Ê¤¤¡£
132 .\"O For example, changes to
133 .\"O .I st_atime
134 .\"O or
135 .\"O .I st_mtime
136 .\"O (respectively, time of last access and
137 .\"O time of last modification; see
138 .\"O .BR stat (2))
139 .\"O do not require flushing because they are not necessary for
140 .\"O a subsequent data read to be handled correctly.
141 Î㤨¤Ð¡¢
142 st_atime ¤ä st_mtime
143 (¤½¤ì¤¾¤ìºÇ½ª¥¢¥¯¥»¥¹»þ¹ï¡¢ºÇ½ª½¤Àµ»þ¹ï;
144 .BR stat (2)
145 »²¾È) ¤ÎÊѹ¹¤Ï¥Õ¥é¥Ã¥·¥å¤òɬÍפȤ·¤Ê¤¤¡£
146 ¤Ê¤¼¤Ê¤é¤³¤ì¤é¤Ï¤½¤ì°Ê¹ß¤Î¥Ç¡¼¥¿Æɤ߹þ¤ß¤òÀµ¤·¤¯°·¤¦¤¿¤á¤Ë
147 ɬÍפǤϤʤ¤¤«¤é¤Ç¤¢¤ë¡£
148 .\"O On the other hand, a change to the file size
149 .\"O .RI ( st_size ,
150 .\"O as made by say
151 .\"O .BR ftruncate (2)),
152 .\"O would require a metadata flush.
153 °ìÊý¡¢¥Õ¥¡¥¤¥ë¥µ¥¤¥º
154 .RB ( ftruncate (2)
155 ¤Ç¤Ï
156 .IR st_size )
157 ¤ÎÊѹ¹¤Ï¥á¥¿¥Ç¡¼¥¿¤Î¥Õ¥é¥Ã¥·¥å¤¬É¬ÍפǤ¢¤ë¡£
158 .\"O The aim of
159 .\"O .BR fdatasync ()
160 .\"O is to reduce disk activity for applications that do not
161 .\"O require all metadata to be synchronized with the disk.
162 .BR fdatasync ()
163 ¤ÎÁÀ¤¤¤Ï¡¢Á´¤Æ¤Î¥á¥¿¥Ç¡¼¥¿¤ò¥Ç¥£¥¹¥¯¤ÈƱ´ü¤¹¤ëɬÍפΤʤ¤
164 ¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤ËÂФ·¤Æ¡¢¥Ç¥£¥¹¥¯¥¢¥¯¥»¥¹¤ò¸º¤é¤¹¤³¤È¤Ç¤¢¤ë¡£
165 .\"O .SH "RETURN VALUE"
166 .SH ÊÖ¤êÃÍ
167 .\"O On success, these system calls return zero.
168 .\"O On error, \-1 is returned, and
169 .\"O .I errno
170 .\"O is set appropriately.
171 À®¸ù¤·¤¿¾ì¹ç¡¢¤³¤ì¤é¤Î¥·¥¹¥Æ¥à¥³¡¼¥ë¤Ï¥¼¥í¤òÊÖ¤¹¡£
172 ¥¨¥é¡¼¤Î¾ì¹ç¡¢\-1 ¤¬ÊÖ¤µ¤ì¡¢
173 .I errno
174 ¤¬Å¬ÀÚ¤ËÀßÄꤵ¤ì¤ë¡£
175 .\"O .SH ERRORS
176 .SH ¥¨¥é¡¼
177 .TP
178 .B EBADF
179 .\"O .I fd
180 .\"O is not a valid file descriptor open for writing.
181 .I fd
182 ¤¬½ñ¤­¹þ¤ß¤Î¤¿¤á¤Ë¥ª¡¼¥×¥ó¤µ¤ì¤¿¥Õ¥¡¥¤¥ëµ­½Ò»Ò¤Ç¤Ê¤¤¡£
183 .TP
184 .B EIO
185 .\"O An error occurred during synchronization.
186 Ʊ´üÁàºî¤Î´Ö¤Ë¥¨¥é¡¼¤¬È¯À¸¤·¤¿¡£
187 .TP
188 .BR EROFS ", " EINVAL
189 .\"O .I fd
190 .\"O is bound to a special file which does not support synchronization.
191 .I fd
192 ¤¬Æ±´üÁàºî¤ò¥µ¥Ý¡¼¥È¤·¤Æ¤Ê¤¤Æüì¤Ê¥Õ¥¡¥¤¥ë¤ò»²¾È¤·¤Æ¤¤¤ë¡£
193 .\"O .SH "CONFORMING TO"
194 .SH ½àµò
195 4.3BSD, POSIX.1-2001.
196 .\"O .SH AVAILABILITY
197 .SH ²ÄÍÑÀ­
198 .\"O On POSIX systems on which
199 .\"O .BR fdatasync ()
200 .\"O is available,
201 .\"O .B _POSIX_SYNCHRONIZED_IO
202 .\"O is defined in
203 .\"O .I <unistd.h>
204 .\"O to a value greater than 0.
205 .\"O (See also
206 .\"O .BR sysconf (3).)
207 .BR fdatasync ()
208 ¤¬ÍøÍѲÄǽ¤Ê POSIX ¥·¥¹¥Æ¥à¤Ç¤Ï¡¢
209 .B _POSIX_SYNCHRONIZED_IO
210 ¤¬
211 .I <unistd.h>
212 ¤Ç 0 ¤è¤êÂ礭¤ÊÃͤËÄêµÁ¤µ¤ì¤ë
213 .RB ( sysconf (3)
214 »²¾È)¡£
215 .\" POSIX.1-2001: It shall be defined to -1 or 0 or 200112L.
216 .\" -1: unavailable, 0: ask using sysconf().
217 .\" glibc defines them to 1.
218 .\"O .SH NOTES
219 .SH Ãí°Õ
220 .\"O Applications that access databases or log files often write a tiny
221 .\"O data fragment (e.g., one line in a log file) and then call
222 .\"O .BR fsync ()
223 .\"O immediately in order to ensure that the written data is physically
224 .\"O stored on the harddisk.
225 .\"O Unfortunately,
226 .\"O .BR fsync ()
227 .\"O will always initiate two write operations: one for the newly written
228 .\"O data and another one in order to update the modification time stored
229 .\"O in the inode.
230 .\"O If the modification time is not a part of the transaction
231 .\"O concept
232 .\"O .BR fdatasync ()
233 .\"O can be used to avoid unnecessary inode disk write operations.
234 ¥Ç¡¼¥¿¥Ù¡¼¥¹¤ä¥í¥°¥Õ¥¡¥¤¥ë¤Ë¥¢¥¯¥»¥¹¤¹¤ë¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Ï¡¢
235 Èó¾ï¤Ë¾®¤µ¤Ê¥Ç¡¼¥¿¤ÎÃÇÊҤνñ¤­¹þ¤ß¤ò¹Ô¤¤¡¢¤½¤Î¸å¤¹¤°¤Ë
236 .BR fsync ()
237 ¤ò¸Æ¤Ó½Ð¤·¤Æ¡¢½ñ¤­¹þ¤ó¤À¥Ç¡¼¥¿¤¬¥Ï¡¼¥É¥Ç¥£¥¹¥¯¤ËʪÍýŪ¤Ë
238 ³Î¼Â¤Ë³ÊǼ¤µ¤ì¤ë¤è¤¦¤Ë¤¹¤ë¤³¤È¤¬Â¿¤¤¡£
239 »ÄÇ°¤Ê¤¬¤é¡¢
240 .BR fsync ()
241 ¤Ï¾ï¤Ë 2¤Ä¤Î½ñ¤­¹þ¤ßÁàºî¤ò³«»Ï¤¹¤ë¡£
242 °ì¤Ä¤Ï¿·¤·¤¯½ñ¤­¹þ¤Þ¤ì¤¿¥Ç¡¼¥¿¤ËÂФ¹¤ë¤â¤Î¤Ç¤¢¤ê¡¢
243 ¤â¤¦°ì¤Ä¤Ï inode ¤Ë³ÊǼ¤µ¤ì¤ë½¤Àµ»þ¹ï (modification time) ¤ò
244 ¹¹¿·¤¹¤ë¤¿¤á¤Î¤â¤Î¤Ç¤¢¤ë¡£
245 ½¤Àµ»þ¹ï¤Î¹¹¿·¤¬ÉÔ²Äʬ¤ÊÁàºî (¥È¥é¥ó¥¶¥¯¥·¥ç¥ó) ¤Î°ìÉô¤Ç¤Ï¤Ê¤¤¾ì¹ç¡¢
246 .BR fdatasync ()
247 ¤ò»È¤¦¤³¤È¤Ç¡¢ÉÔɬÍפʠinode ¤Î¥Ç¥£¥¹¥¯½ñ¤­¹þ¤ßÁàºî¤òÈò¤±¤ë¤³¤È¤¬¤Ç¤­¤ë¡£
248
249 .\"O If the underlying hard disk has write caching enabled, then
250 .\"O the data may not really be on permanent storage when
251 .\"O .BR fsync ()
252 .\"O /
253 .\"O .BR fdatasync ()
254 .\"O return.
255 .\"O .\" See
256 .\"O .\" .BR hdparm (8)
257 .\"O .\" for how to disable that cache for IDE disks.
258 ¥Ç¡¼¥¿¤¬ÇÛÃÖ¤µ¤ì¤Æ¤¤¤ë¥Ï¡¼¥É¥Ç¥£¥¹¥¯¤Î½ñ¤­¹þ¤ß¥­¥ã¥Ã¥·¥å¤¬Í­¸ú¤Ë
259 ¤Ê¤Ã¤Æ¤¤¤ë¾ì¹ç¡¢
260 .BR fsync ()
261 /
262 .BR fdatasync ()
263 ¤«¤éÌá¤Ã¤Æ¤­¤¿¤È¤·¤Æ¤â¡¢¤½¤Î¥Ç¡¼¥¿¤Ï¼ÂºÝ¤Ë¤Ï±Ê³Ū¤Êµ­²±ÇÞÂΤË
264 ³ÊǼ¤µ¤ì¤Æ¤¤¤Ê¤¤¤«¤â¤·¤ì¤Ê¤¤¡£
265 .\" IDE ¥Ç¥£¥¹¥¯¤Î¥­¥ã¥Ã¥·¥å¤ò̵¸ú¤Ë¤¹¤ëÊýË¡¤Ë¤Ä¤¤¤Æ¤Ï
266 .\" .BR hdparm (8)
267 .\" ¤ò»²¾È¤Î¤³¤È¡£
268 .LP
269 .\"O When an ext2 file system is mounted with the
270 .\"O .I sync
271 .\"O option, directory entries are also implicitly synced by
272 .\"O .BR fsync ().
273 ext2 ¥Õ¥¡¥¤¥ë¡¦¥·¥¹¥Æ¥à¤¬
274 .I sync
275 ¥ª¥×¥·¥ç¥ó¤Ä¤­¤Ç¥Þ¥¦¥ó¥È¤µ¤ì¤Æ¤¤¤ë¾ì¹ç¡¢
276 .BR fsync ()
277 ¤Ç¥Ç¥£¥ì¥¯¥È¥ê¡¦¥¨¥ó¥È¥ê¤â°ÅÌۤΤ¦¤Á¤ËƱ´ü¤¹¤ë¡£
278 .LP
279 .\"O On kernels before 2.4,
280 .\"O .BR fsync ()
281 .\"O on big files can be inefficient.
282 .\"O An alternative might be to use the
283 .\"O .B O_SYNC
284 .\"O flag to
285 .\"O .BR open (2).
286 2.4 ¤è¤êÁ°¤Î¥«¡¼¥Í¥ë¤Ç¤ÏµðÂç¤Ê¥Õ¥¡¥¤¥ë¤Ë
287 .BR fsync ()
288 ¤ò»ÈÍѤ¹¤ë¤³¤È¤Ï¸úΨ¤¬°­¤¤¾ì¹ç¤¬¤¢¤ë¡£
289 Ê̤ÎÊýË¡¤È¤·¤Æ
290 .BR open (2)
291 ¤ÎºÝ¤Ë
292 .B O_SYNC
293 ¥Õ¥é¥°¤ò»ÈÍѤ¹¤ë¤Î¤¬Îɤ¤¤«¤â¤·¤ì¤Ê¤¤¡£
294
295 .\"O In Linux 2.2 and earlier,
296 .\"O .BR fdatasync ()
297 .\"O is equivalent to
298 .\"O .BR fsync (),
299 .\"O and so has no performance advantage.
300 Linux 2.2 °ÊÁ°¤Ç¤Ï¡¢
301 .BR fdatasync ()
302 ¤Ï
303 .BR fsync ()
304 ¤ÈÅù²Á¤Ç¤¢¤ê¡¢À­Ç½Ì̤ǤΥá¥ê¥Ã¥È¤Ï¤Ê¤¤¡£
305 .\"O .SH "SEE ALSO"
306 .SH ´ØÏ¢¹àÌÜ
307 .BR bdflush (2),
308 .BR open (2),
309 .BR sync (2),
310 .BR sync_file_range (2),
311 .BR hdparm (8),
312 .BR mount (8),
313 .BR sync (8),
314 .BR update (8)