• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2<html lang="en">
3<head>
4<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
5<meta http-equiv="Content-Style-Type" content="text/css">
6<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
7<title>FatFs - f_sync</title>
8</head>
9
10<body>
11
12<div class="para func">
13<h2>f_sync</h2>
14<p>The f_sync function flushes the cached information of a writing file.</p>
15<pre>
16FRESULT f_sync (
17  FIL* <span class="arg">fp</span>     <span class="c">/* [IN] File object */</span>
18);
19</pre>
20</div>
21
22<div class="para arg">
23<h4>Parameter</h4>
24<dl class="par">
25<dt>fp</dt>
26<dd>Pointer to the open file object to be flushed.</dd>
27</dl>
28</div>
29
30
31<div class="para ret">
32<h4>Return Values</h4>
33<p>
34<a href="rc.html#ok">FR_OK</a>,
35<a href="rc.html#de">FR_DISK_ERR</a>,
36<a href="rc.html#ie">FR_INT_ERR</a>,
37<a href="rc.html#io">FR_INVALID_OBJECT</a>,
38<a href="rc.html#tm">FR_TIMEOUT</a>
39</p>
40</div>
41
42
43<div class="para desc">
44<h4>Description</h4>
45<p>The <tt>f_sync</tt> function performs the same process as <tt>f_close</tt> function but the file is left opened and can continue read/write/seek operations to the file. This is suitable for the applications that open files for a long time in write mode, such as data logger. Performing <tt>f_sync</tt> function in certain interval can minimize the risk of data loss due to a sudden blackout, wrong media removal or unrecoverable disk error. For more information, refer to <a href="appnote.html#critical">application note</a>.</p>
46<pre>
47Case 1. Normal write sequence
48
49                                Time --&gt;                                     ↓Normal shutdown
50OwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwC &lt;Power off&gt;
51
52
53Case 2. Without using f_sync()
54
55                                Time --&gt;                             ↓System crush
56O<span class="e">wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww</span>
57 |&lt;--------------- All data written will be lost ------------------&gt;|
58
59
60Case 3. Using f_sync()
61                                Time --&gt;                             ↓System crush
62OwwwwwwwwSwwwwwwwwSwwwwwwwwSwwwwwwwwSwwwwwwwwSwwwwwwwwSwwwwwwwwS<span class="e">wwwww</span>
63                            Data after last f_sync will be lost |&lt;-&gt;|
64O - f_open()
65C - f_close()
66w - f_write()
67S - f_sync()
68</pre>
69<p>However there is no sense in <tt>f_sync</tt> function jsut before <tt>f_close</tt> function, because the <tt>f_close</tt> performs <tt>f_sync</tt> in it. Actually, the differnce between these functions is that the file object is invalidated or not.</p>
70</div>
71
72
73<div class="para comp">
74<h4>QuickInfo</h4>
75<p>Available when <tt><a href="config.html#fs_readonly">FF_FS_READONLY</a> == 0</tt>.</p>
76</div>
77
78
79<div class="para ref">
80<h4>See Also</h4>
81<p><tt><a href="close.html">f_close</a></tt>, <a href="appnote.html#critical">Critical section</a></p>
82</div>
83
84
85<p class="foot"><a href="../00index_e.html">Return</a></p>
86</body>
87</html>
88