1 <!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
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=
"up" title=
"FatFs" href=
"../00index_e.html">
7 <link rel=
"alternate" hreflang=
"ja" title=
"Japanese" href=
"../ja/sync.html">
8 <link rel=
"stylesheet" href=
"../css_e.css" type=
"text/css" media=
"screen" title=
"ELM Default">
9 <title>FatFs - f_sync
</title>
14 <div class=
"para func">
16 <p>The f_sync function flushes the cached information of a writing file.
</p>
19 FIL*
<span class=
"arg">fp
</span> <span class=
"c">/* [IN] File object */
</span>
24 <div class=
"para arg">
28 <dd>Pointer to the open file object to be flushed.
</dd>
33 <div class=
"para ret">
34 <h4>Return Values
</h4>
36 <a href=
"rc.html#ok">FR_OK
</a>,
37 <a href=
"rc.html#de">FR_DISK_ERR
</a>,
38 <a href=
"rc.html#ie">FR_INT_ERR
</a>,
39 <a href=
"rc.html#io">FR_INVALID_OBJECT
</a>,
40 <a href=
"rc.html#tm">FR_TIMEOUT
</a>
45 <div class=
"para desc">
47 <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>
49 Case
1. Normal write sequence
51 Time --
> ↓Normal shutdown
52 OwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwC
<Power off
>
55 Case
2. Without using f_sync()
57 Time --
> ↓System crush
58 O
<span class=
"e">wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww
</span>
59 |
<--------------- All data written will be lost ------------------
>|
62 Case
3. Using f_sync()
63 Time --
> ↓System crush
64 OwwwwwwwwSwwwwwwwwSwwwwwwwwSwwwwwwwwSwwwwwwwwSwwwwwwwwSwwwwwwwwS
<span class=
"e">wwwww
</span>
65 Data after last f_sync will be lost |
<-
>|
71 <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>
75 <div class=
"para comp">
77 <p>Available when
<tt><a href=
"config.html#fs_readonly">FF_FS_READONLY
</a> ==
0</tt>.
</p>
81 <div class=
"para ref">
83 <p><tt><a href=
"close.html">f_close
</a></tt>,
<a href=
"appnote.html#critical">Critical section
</a></p>
86 <p class=
"foot"><a href=
"../00index_e.html">Return
</a></p>