📄 fsync.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta name="generator" content="HTML Tidy, see www.w3.org"><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><link type="text/css" rel="stylesheet" href="style.css"><!-- Generated by The Open Group's rhtm tool v1.2.1 --><!-- Copyright (c) 2001-2003 The Open Group, All Rights Reserved --><title>fsync</title></head><body bgcolor="white"><script type="text/javascript" language="JavaScript" src="../jscript/codes.js"></script><basefont size="3"> <a name="fsync"></a> <a name="tag_03_195"></a><!-- fsync --> <!--header start--><center><font size="2">The Open Group Base Specifications Issue 6<br>IEEE Std 1003.1, 2003 Edition<br>Copyright © 2001-2003 The IEEE and The Open Group, All Rights reserved.</font></center><!--header end--><hr size="2" noshade><h4><a name="tag_03_195_01"></a>NAME</h4><blockquote>fsync - synchronize changes to a file</blockquote><h4><a name="tag_03_195_02"></a>SYNOPSIS</h4><blockquote class="synopsis"><div class="box"><code><tt><sup>[<a href="javascript:open_code('FSC')">FSC</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"> #include <<a href="../basedefs/unistd.h.html">unistd.h</a>><br><br> int fsync(int</tt> <i>fildes</i><tt>); <img src="../images/opt-end.gif" alt="[Option End]" border="0"></tt></code></div><tt><br></tt></blockquote><h4><a name="tag_03_195_03"></a>DESCRIPTION</h4><blockquote><p>The <i>fsync</i>() function shall request that all data for the open file descriptor named by <i>fildes</i> is to be transferredto the storage device associated with the file described by <i>fildes</i> in an implementation-defined manner. The <i>fsync</i>()function shall not return until the system has completed that action or until an error is detected.</p><p><sup>[<a href="javascript:open_code('SIO')">SIO</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">If _POSIX_SYNCHRONIZED_IO is defined, the <i>fsync</i>() function shall force all currently queued I/O operations associated withthe file indicated by file descriptor <i>fildes</i> to the synchronized I/O completion state. All I/O operations shall be completedas defined for synchronized I/O file integrity completion. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></p></blockquote><h4><a name="tag_03_195_04"></a>RETURN VALUE</h4><blockquote><p>Upon successful completion, <i>fsync</i>() shall return 0. Otherwise, -1 shall be returned and <i>errno</i> set to indicate theerror. If the <i>fsync</i>() function fails, outstanding I/O operations are not guaranteed to have been completed.</p></blockquote><h4><a name="tag_03_195_05"></a>ERRORS</h4><blockquote><p>The <i>fsync</i>() function shall fail if:</p><dl compact><dt>[EBADF]</dt><dd>The <i>fildes</i> argument is not a valid descriptor.</dd><dt>[EINTR]</dt><dd>The <i>fsync</i>() function was interrupted by a signal.</dd><dt>[EINVAL]</dt><dd>The <i>fildes</i> argument does not refer to a file on which this operation is possible.</dd><dt>[EIO]</dt><dd>An I/O error occurred while reading from or writing to the file system.</dd></dl><p>In the event that any of the queued I/O operations fail, <i>fsync</i>() shall return the error conditions defined for <a href="../functions/read.html"><i>read</i>()</a> and <a href="../functions/write.html"><i>write</i>()</a>.</p></blockquote><hr><div class="box"><em>The following sections are informative.</em></div><h4><a name="tag_03_195_06"></a>EXAMPLES</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_03_195_07"></a>APPLICATION USAGE</h4><blockquote><p>The <i>fsync</i>() function should be used by programs which require modifications to a file to be completed before continuing;for example, a program which contains a simple transaction facility might use it to ensure that all modifications to a file orfiles caused by a transaction are recorded.</p></blockquote><h4><a name="tag_03_195_08"></a>RATIONALE</h4><blockquote><p>The <i>fsync</i>() function is intended to force a physical write of data from the buffer cache, and to assure that after asystem crash or other failure that all data up to the time of the <i>fsync</i>() call is recorded on the disk. Since the conceptsof "buffer cache", "system crash", "physical write", and "non-volatile storage" are not defined here, the wording has to bemore abstract.</p><p>If _POSIX_SYNCHRONIZED_IO is not defined, the wording relies heavily on the conformance document to tell the user what can beexpected from the system. It is explicitly intended that a null implementation is permitted. This could be valid in the case wherethe system cannot assure non-volatile storage under any circumstances or when the system is highly fault-tolerant and thefunctionality is not required. In the middle ground between these extremes, <i>fsync</i>() might or might not actually cause datato be written where it is safe from a power failure. The conformance document should identify at least that one configurationexists (and how to obtain that configuration) where this can be assured for at least some files that the user can select to use forcritical data. It is not intended that an exhaustive list is required, but rather sufficient information is provided so that ifcritical data needs to be saved, the user can determine how the system is to be configured to allow the data to be written tonon-volatile storage.</p><p>It is reasonable to assert that the key aspects of <i>fsync</i>() are unreasonable to test in a test suite. That does not makethe function any less valuable, just more difficult to test. A formal conformance test should probably force a system crash (powershutdown) during the test for this condition, but it needs to be done in such a way that automated testing does not require this tobe done except when a formal record of the results is being made. It would also not be unreasonable to omit testing for<i>fsync</i>(), allowing it to be treated as a quality-of-implementation issue.</p></blockquote><h4><a name="tag_03_195_09"></a>FUTURE DIRECTIONS</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_03_195_10"></a>SEE ALSO</h4><blockquote><p><a href="sync.html"><i>sync</i>()</a> , the Base Definitions volume of IEEE Std 1003.1-2001, <a href="../basedefs/unistd.h.html"><i><unistd.h></i></a></p></blockquote><h4><a name="tag_03_195_11"></a>CHANGE HISTORY</h4><blockquote><p>First released in Issue 3.</p></blockquote><h4><a name="tag_03_195_12"></a>Issue 5</h4><blockquote><p>Aligned with <i>fsync</i>() in the POSIX Realtime Extension. Specifically, the DESCRIPTION and RETURN VALUE sections are muchexpanded, and the ERRORS section is updated to indicate that <i>fsync</i>() can return the error conditions defined for <a href="../functions/read.html"><i>read</i>()</a> and <a href="../functions/write.html"><i>write</i>()</a>.</p></blockquote><h4><a name="tag_03_195_13"></a>Issue 6</h4><blockquote><p>This function is marked as part of the File Synchronization option.</p><p>The following new requirements on POSIX implementations derive from alignment with the Single UNIX Specification:</p><ul><li><p>The [EINVAL] and [EIO] mandatory error conditions are added.</p></li></ul></blockquote><div class="box"><em>End of informative text.</em></div><hr><hr size="2" noshade><center><font size="2"><!--footer start-->UNIX ® is a registered Trademark of The Open Group.<br>POSIX ® is a registered Trademark of The IEEE.<br>[ <a href="../mindex.html">Main Index</a> | <a href="../basedefs/contents.html">XBD</a> | <a href="../utilities/contents.html">XCU</a> | <a href="../functions/contents.html">XSH</a> | <a href="../xrat/contents.html">XRAT</a>]</font></center><!--footer end--><hr size="2" noshade></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -