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