xref: /third_party/FatFs/documents/doc/sync.html (revision e6865dcd)
1e6865dcdSopenharmony_ci<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2e6865dcdSopenharmony_ci<html lang="en">
3e6865dcdSopenharmony_ci<head>
4e6865dcdSopenharmony_ci<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
5e6865dcdSopenharmony_ci<meta http-equiv="Content-Style-Type" content="text/css">
6e6865dcdSopenharmony_ci<link rel="up" title="FatFs" href="../00index_e.html">
7e6865dcdSopenharmony_ci<link rel="alternate" hreflang="ja" title="Japanese" href="../ja/sync.html">
8e6865dcdSopenharmony_ci<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
9e6865dcdSopenharmony_ci<title>FatFs - f_sync</title>
10e6865dcdSopenharmony_ci</head>
11e6865dcdSopenharmony_ci
12e6865dcdSopenharmony_ci<body>
13e6865dcdSopenharmony_ci
14e6865dcdSopenharmony_ci<div class="para func">
15e6865dcdSopenharmony_ci<h2>f_sync</h2>
16e6865dcdSopenharmony_ci<p>The f_sync function flushes the cached information of a writing file.</p>
17e6865dcdSopenharmony_ci<pre>
18e6865dcdSopenharmony_ciFRESULT f_sync (
19e6865dcdSopenharmony_ci  FIL* <span class="arg">fp</span>     <span class="c">/* [IN] File object */</span>
20e6865dcdSopenharmony_ci);
21e6865dcdSopenharmony_ci</pre>
22e6865dcdSopenharmony_ci</div>
23e6865dcdSopenharmony_ci
24e6865dcdSopenharmony_ci<div class="para arg">
25e6865dcdSopenharmony_ci<h4>Parameter</h4>
26e6865dcdSopenharmony_ci<dl class="par">
27e6865dcdSopenharmony_ci<dt>fp</dt>
28e6865dcdSopenharmony_ci<dd>Pointer to the open file object to be flushed.</dd>
29e6865dcdSopenharmony_ci</dl>
30e6865dcdSopenharmony_ci</div>
31e6865dcdSopenharmony_ci
32e6865dcdSopenharmony_ci
33e6865dcdSopenharmony_ci<div class="para ret">
34e6865dcdSopenharmony_ci<h4>Return Values</h4>
35e6865dcdSopenharmony_ci<p>
36e6865dcdSopenharmony_ci<a href="rc.html#ok">FR_OK</a>,
37e6865dcdSopenharmony_ci<a href="rc.html#de">FR_DISK_ERR</a>,
38e6865dcdSopenharmony_ci<a href="rc.html#ie">FR_INT_ERR</a>,
39e6865dcdSopenharmony_ci<a href="rc.html#io">FR_INVALID_OBJECT</a>,
40e6865dcdSopenharmony_ci<a href="rc.html#tm">FR_TIMEOUT</a>
41e6865dcdSopenharmony_ci</p>
42e6865dcdSopenharmony_ci</div>
43e6865dcdSopenharmony_ci
44e6865dcdSopenharmony_ci
45e6865dcdSopenharmony_ci<div class="para desc">
46e6865dcdSopenharmony_ci<h4>Description</h4>
47e6865dcdSopenharmony_ci<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>
48e6865dcdSopenharmony_ci<pre>
49e6865dcdSopenharmony_ciCase 1. Normal write sequence
50e6865dcdSopenharmony_ci
51e6865dcdSopenharmony_ci                                Time --&gt;                                     ↓Normal shutdown
52e6865dcdSopenharmony_ciOwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwC &lt;Power off&gt;
53e6865dcdSopenharmony_ci
54e6865dcdSopenharmony_ci
55e6865dcdSopenharmony_ciCase 2. Without using f_sync()
56e6865dcdSopenharmony_ci
57e6865dcdSopenharmony_ci                                Time --&gt;                             ↓System crush
58e6865dcdSopenharmony_ciO<span class="e">wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww</span>
59e6865dcdSopenharmony_ci |&lt;--------------- All data written will be lost ------------------&gt;|
60e6865dcdSopenharmony_ci
61e6865dcdSopenharmony_ci
62e6865dcdSopenharmony_ciCase 3. Using f_sync()
63e6865dcdSopenharmony_ci                                Time --&gt;                             ↓System crush
64e6865dcdSopenharmony_ciOwwwwwwwwSwwwwwwwwSwwwwwwwwSwwwwwwwwSwwwwwwwwSwwwwwwwwSwwwwwwwwS<span class="e">wwwww</span>
65e6865dcdSopenharmony_ci                            Data after last f_sync will be lost |&lt;-&gt;| 
66e6865dcdSopenharmony_ciO - f_open()
67e6865dcdSopenharmony_ciC - f_close()
68e6865dcdSopenharmony_ciw - f_write()
69e6865dcdSopenharmony_ciS - f_sync()
70e6865dcdSopenharmony_ci</pre>
71e6865dcdSopenharmony_ci<p>However there is no sense in <tt>f_sync</tt> function immediataly before <tt>f_close</tt> function because it performs <tt>f_sync</tt> function in it. In other words, the differnce between those functions is that the file object is invalidated or not.</p>
72e6865dcdSopenharmony_ci</div>
73e6865dcdSopenharmony_ci
74e6865dcdSopenharmony_ci
75e6865dcdSopenharmony_ci<div class="para comp">
76e6865dcdSopenharmony_ci<h4>QuickInfo</h4>
77e6865dcdSopenharmony_ci<p>Available when <tt><a href="config.html#fs_readonly">FF_FS_READONLY</a> == 0</tt>.</p>
78e6865dcdSopenharmony_ci</div>
79e6865dcdSopenharmony_ci
80e6865dcdSopenharmony_ci
81e6865dcdSopenharmony_ci<div class="para ref">
82e6865dcdSopenharmony_ci<h4>See Also</h4>
83e6865dcdSopenharmony_ci<p><tt><a href="close.html">f_close</a></tt>, <a href="appnote.html#critical">Critical section</a></p>
84e6865dcdSopenharmony_ci</div>
85e6865dcdSopenharmony_ci
86e6865dcdSopenharmony_ci<p class="foot"><a href="../00index_e.html">Return</a></p>
87e6865dcdSopenharmony_ci</body>
88e6865dcdSopenharmony_ci</html>
89