<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns="http://www.w3.org/TR/REC-html40">

<head>
<meta http-equiv=Content-Type content="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 11 (filtered medium)">
<style>
<!--
 /* Font Definitions */
 @font-face
        {font-family:Batang;
        panose-1:2 3 6 0 0 1 1 1 1 1;}
@font-face
        {font-family:"\@Batang";
        panose-1:2 3 6 0 0 1 1 1 1 1;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman";}
h1
        {margin-top:0in;
        margin-right:0in;
        margin-bottom:0in;
        margin-left:.5in;
        margin-bottom:.0001pt;
        text-indent:-.25in;
        page-break-after:avoid;
        mso-list:l0 level1 lfo8;
        font-size:12.0pt;
        font-family:"Times New Roman";
        text-decoration:underline;}
h2
        {margin-top:0in;
        margin-right:0in;
        margin-bottom:0in;
        margin-left:1.0in;
        margin-bottom:.0001pt;
        text-indent:-.25in;
        page-break-after:avoid;
        mso-list:l0 level2 lfo8;
        font-size:12.0pt;
        font-family:"Times New Roman";}
h3
        {margin-top:0in;
        margin-right:0in;
        margin-bottom:0in;
        margin-left:1.5in;
        margin-bottom:.0001pt;
        text-indent:-9.0pt;
        mso-list:l0 level3 lfo8;
        font-size:12.0pt;
        font-family:"Times New Roman";
        font-weight:normal;}
a:link, span.MsoHyperlink
        {color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {color:purple;
        text-decoration:underline;}
p.MsoPlainText, li.MsoPlainText, div.MsoPlainText
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:10.0pt;
        font-family:"Courier New";}
p.Code, li.Code, div.Code
        {margin-top:0in;
        margin-right:0in;
        margin-bottom:0in;
        margin-left:.5in;
        margin-bottom:.0001pt;
        font-size:10.0pt;
        font-family:"Courier New";}
p.Appendix1, li.Appendix1, div.Appendix1
        {margin:0in;
        margin-bottom:.0001pt;
        page-break-after:avoid;
        font-size:12.0pt;
        font-family:"Times New Roman";
        font-weight:bold;
        text-decoration:underline;}
p.Appendix2, li.Appendix2, div.Appendix2
        {margin:0in;
        margin-bottom:.0001pt;
        page-break-after:avoid;
        font-size:12.0pt;
        font-family:"Times New Roman";
        font-weight:bold;}
p.Appendix3, li.Appendix3, div.Appendix3
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman";}
@page Section1
        {size:8.5in 11.0in;
        margin:1.0in 65.95pt 1.0in 65.95pt;}
div.Section1
        {page:Section1;}
 /* List Definitions */
 @list l0
        {mso-list-id:944188057;
        mso-list-template-ids:-42284356;}
@list l0:level1
        {mso-level-style-link:"Heading 1";
        mso-level-tab-stop:.25in;
        mso-level-number-position:left;
        margin-left:0in;
        text-indent:0in;
        mso-ansi-font-weight:bold;
        mso-ansi-font-style:normal;
        text-decoration:none;
        text-underline:none;}
@list l0:level2
        {mso-level-style-link:"Heading 2";
        mso-level-legal-format:yes;
        mso-level-text:"%1\.%2\.";
        mso-level-tab-stop:.5in;
        mso-level-number-position:left;
        margin-left:.5in;
        text-indent:-.5in;
        font-family:"Times New Roman";
        font-variant:normal !important;
        mso-hide:none;
        text-transform:none;
        position:relative;
        top:0pt;
        mso-text-raise:0pt;
        letter-spacing:0pt;
        mso-font-kerning:0pt;
        text-effect:none;
        text-shadow:none;
        text-effect:none;
        text-effect:none;
        font-emphasize:none;
        mso-ansi-font-weight:normal;
        mso-bidi-font-weight:normal;
        mso-ansi-font-style:normal;
        mso-bidi-font-style:normal;
        text-decoration:none;
        text-underline:none;
        text-decoration:none;
        text-line-through:none;
        vertical-align:baseline;}
@list l0:level3
        {mso-level-style-link:"Heading 3";
        mso-level-text:"%1\.%2\.%3\.";
        mso-level-tab-stop:.5in;
        mso-level-number-position:left;
        margin-left:.5in;
        text-indent:-.5in;
        font-family:"Times New Roman";
        font-variant:normal !important;
        mso-hide:none;
        text-transform:none;
        position:relative;
        top:0pt;
        mso-text-raise:0pt;
        letter-spacing:0pt;
        mso-font-kerning:0pt;
        text-effect:none;
        text-shadow:none;
        text-effect:none;
        text-effect:none;
        font-emphasize:none;
        mso-ansi-font-weight:normal;
        mso-bidi-font-weight:normal;
        mso-ansi-font-style:normal;
        mso-bidi-font-style:normal;
        text-decoration:none;
        text-underline:none;
        text-decoration:none;
        text-line-through:none;
        vertical-align:baseline;}
@list l0:level4
        {mso-level-text:"%1\.%2\.%3\.%4\.";
        mso-level-tab-stop:1.45in;
        mso-level-number-position:left;
        margin-left:1.45in;
        text-indent:-.75in;}
@list l0:level5
        {mso-level-text:"%1\.%2\.%3\.%4\.%5\.";
        mso-level-tab-stop:1.55in;
        mso-level-number-position:left;
        margin-left:1.55in;
        text-indent:-.55in;}
@list l0:level6
        {mso-level-text:"%1\.%2\.%3\.%4\.%5\.%6\.";
        mso-level-tab-stop:1.9in;
        mso-level-number-position:left;
        margin-left:1.9in;
        text-indent:-.65in;}
@list l0:level7
        {mso-level-text:"%1\.%2\.%3\.%4\.%5\.%6\.%7\.";
        mso-level-tab-stop:2.25in;
        mso-level-number-position:left;
        margin-left:2.25in;
        text-indent:-.75in;}
@list l0:level8
        {mso-level-text:"%1\.%2\.%3\.%4\.%5\.%6\.%7\.%8\.";
        mso-level-tab-stop:2.6in;
        mso-level-number-position:left;
        margin-left:2.6in;
        text-indent:-.85in;}
@list l0:level9
        {mso-level-text:"%1\.%2\.%3\.%4\.%5\.%6\.%7\.%8\.%9\.";
        mso-level-tab-stop:3.0in;
        mso-level-number-position:left;
        margin-left:3.0in;
        text-indent:-1.0in;}
ol
        {margin-bottom:0in;}
ul
        {margin-bottom:0in;}
-->
</style>

</head>

<body lang=EN-US link=blue vlink=purple>

<div class=Section1>

<p class=MsoPlainText><font size=1 face=Arial><span style='font-size:9.0pt;
font-family:Arial'>It turns out that this bug was fixed last year<o:p></o:p></span></font></p>

<p class=MsoPlainText><font size=1 face=Arial><span style='font-size:9.0pt;
font-family:Arial'><o:p> </o:p></span></font></p>

<p class=MsoPlainText style='margin-left:.5in'><font size=1 face=Arial><span
style='font-size:9.0pt;font-family:Arial'>author    Sebastian
Huber                 2017-09-06
12:30:00 (UTC)<o:p></o:p></span></font></p>

<p class=MsoPlainText style='margin-left:.5in'><font size=1 face=Arial><span
style='font-size:9.0pt;font-family:Arial'>committer              Sebastian
Huber                 2017-09-06
12:40:38 (UTC)<o:p></o:p></span></font></p>

<p class=MsoPlainText style='margin-left:.5in'><font size=1 face=Arial><span
style='font-size:9.0pt;font-family:Arial'>dosfs: Fix fat_file_update()<o:p></o:p></span></font></p>

<p class=MsoPlainText style='margin-left:.5in'><font size=1 face=Arial><span
style='font-size:9.0pt;font-family:Arial'>Do not update the non-existant
meta-data of the root directory.<o:p></o:p></span></font></p>

<p class=MsoPlainText style='margin-left:.5in'><font size=1 face=Arial><span
style='font-size:9.0pt;font-family:Arial'>Close #2944.<o:p></o:p></span></font></p>

<p class=MsoPlainText style='margin-left:.5in'><font size=1 face=Arial><span
style='font-size:9.0pt;font-family:Arial'><o:p> </o:p></span></font></p>

<p class=MsoPlainText><font size=1 face=Arial><span style='font-size:9.0pt;
font-family:Arial'>Apparently I have been working with an old snapshot of
dosfs.  I hate it when that happens!<o:p></o:p></span></font></p>

<p class=MsoPlainText><font size=1 face=Arial><span style='font-size:9.0pt;
font-family:Arial'><o:p> </o:p></span></font></p>

<p class=MsoPlainText><font size=1 face=Arial><span style='font-size:9.0pt;
font-family:Arial'>Sorry for not checking before posting a question.<o:p></o:p></span></font></p>

<p class=MsoPlainText><font size=1 face=Arial><span style='font-size:9.0pt;
font-family:Arial'><o:p> </o:p></span></font></p>

<p class=MsoPlainText><font size=1 face=Arial><span style='font-size:9.0pt;
font-family:Arial'>Cliff<o:p></o:p></span></font></p>

<p class=MsoPlainText><font size=1 face=Arial><span style='font-size:9.0pt;
font-family:Arial'><o:p> </o:p></span></font></p>

<p class=MsoPlainText><font size=1 face=Arial><span style='font-size:9.0pt;
font-family:Arial'>-----Original Message-----<br>
From: Chris Johns<o:p></o:p></span></font></p>

<p class=MsoPlainText><font size=1 face=Arial><span style='font-size:9.0pt;
font-family:Arial'>Sent: Tuesday, October 02, 2018 6:32 PM<br>
To: Cliff Geschke; <br>
Subject: Re: How to sync a dos file system externally</span></font><font
size=1 face=Arial><span style='font-size:9.0pt;font-family:Arial'><o:p></o:p></span></font></p>

<p class=MsoPlainText><font size=1 face=Arial><span style='font-size:9.0pt;
font-family:Arial'><o:p> </o:p></span></font></p>

<p class=MsoPlainText><font size=1 face=Arial><span style='font-size:9.0pt;
font-family:Arial'>On 03/10/2018 04:56, Cliff Geschke wrote:<o:p></o:p></span></font></p>

<p class=MsoPlainText><font size=1 face=Arial><span style='font-size:9.0pt;
font-family:Arial'>> I have implemented a dos file system (msdos_*) on a
flash device.<o:p></o:p></span></font></p>

<p class=MsoPlainText><font size=1 face=Arial><span style='font-size:9.0pt;
font-family:Arial'><o:p> </o:p></span></font></p>

<p class=MsoPlainText><font size=1 face=Arial><span style='font-size:9.0pt;
font-family:Arial'>Is the flash device a chip you have direct access too? The
reason I ask is if<o:p></o:p></span></font></p>

<p class=MsoPlainText><font size=1 face=Arial><span style='font-size:9.0pt;
font-family:Arial'>possible using JFFS2 (a journaling file system) or even
YAFFS (commercial<o:p></o:p></span></font></p>

<p class=MsoPlainText><font size=1 face=Arial><span style='font-size:9.0pt;
font-family:Arial'>license maybe needed) is a better solution.<o:p></o:p></span></font></p>

<p class=MsoPlainText><font size=1 face=Arial><span style='font-size:9.0pt;
font-family:Arial'><o:p> </o:p></span></font></p>

<p class=MsoPlainText><font size=1 face=Arial><span style='font-size:9.0pt;
font-family:Arial'>> Because it is possible for the user to power down the
system unexpectedly, I<o:p></o:p></span></font></p>

<p class=MsoPlainText><font size=1 face=Arial><span style='font-size:9.0pt;
font-family:Arial'>> want to sync the file system to the flash device after
a 3 second idle time. <o:p></o:p></span></font></p>

<p class=MsoPlainText><font size=1 face=Arial><span style='font-size:9.0pt;
font-family:Arial'>> How do I externally force a sync on msdos from another
thread?<o:p></o:p></span></font></p>

<p class=MsoPlainText><font size=1 face=Arial><span style='font-size:9.0pt;
font-family:Arial'><o:p> </o:p></span></font></p>

<p class=MsoPlainText><font size=1 face=Arial><span style='font-size:9.0pt;
font-family:Arial'>The following test ...<o:p></o:p></span></font></p>

<p class=MsoPlainText><font size=1 face=Arial><span style='font-size:9.0pt;
font-family:Arial'><o:p> </o:p></span></font></p>

<p class=MsoPlainText><font size=1 face=Arial><span style='font-size:9.0pt;
font-family:Arial'> https://git.rtems.org/rtems/tree/testsuites/fstests/fsdosfssync01/init.c<o:p></o:p></span></font></p>

<p class=MsoPlainText><font size=1 face=Arial><span style='font-size:9.0pt;
font-family:Arial'><o:p> </o:p></span></font></p>

<p class=MsoPlainText><font size=1 face=Arial><span style='font-size:9.0pt;
font-family:Arial'>shows how to purge a disk at the block layer. Wrap something
like this is the<o:p></o:p></span></font></p>

<p class=MsoPlainText><font size=1 face=Arial><span style='font-size:9.0pt;
font-family:Arial'>way to purge the cache.<o:p></o:p></span></font></p>

<p class=MsoPlainText><font size=1 face=Arial><span style='font-size:9.0pt;
font-family:Arial'><o:p> </o:p></span></font></p>

<p class=MsoPlainText><font size=1 face=Arial><span style='font-size:9.0pt;
font-family:Arial'>> A related problem is that I use FTP (ftpd.c) to
externally read/write files on<o:p></o:p></span></font></p>

<p class=MsoPlainText><font size=1 face=Arial><span style='font-size:9.0pt;
font-family:Arial'>> the msdos formatted flash.  I have the idle
timeout set to 3 minutes for the FTP<o:p></o:p></span></font></p>

<p class=MsoPlainText><font size=1 face=Arial><span style='font-size:9.0pt;
font-family:Arial'>> connection.  After 3 minutes, ftpd issues a
chdir("/") which eventually calls<o:p></o:p></span></font></p>

<p class=MsoPlainText><font size=1 face=Arial><span style='font-size:9.0pt;
font-family:Arial'>> msdos_free_node_info() that calls fat_file_close() and
may try to write out data<o:p></o:p></span></font></p>

<p class=MsoPlainText><font size=1 face=Arial><span style='font-size:9.0pt;
font-family:Arial'>> to the flash.  This is a problem because if the
power is turned off at that time<o:p></o:p></span></font></p>

<p class=MsoPlainText><font size=1 face=Arial><span style='font-size:9.0pt;
font-family:Arial'>> the flash is corrupted.<o:p></o:p></span></font></p>

<p class=MsoPlainText><font size=1 face=Arial><span style='font-size:9.0pt;
font-family:Arial'>> <o:p></o:p></span></font></p>

<p class=MsoPlainText><font size=1 face=Arial><span style='font-size:9.0pt;
font-family:Arial'>> So whatever method I use to sync msdos needs to update
and write out the fat so<o:p></o:p></span></font></p>

<p class=MsoPlainText><font size=1 face=Arial><span style='font-size:9.0pt;
font-family:Arial'>> that the subsequent msdos_free_node_info() does
nothing.<o:p></o:p></span></font></p>

<p class=MsoPlainText><font size=1 face=Arial><span style='font-size:9.0pt;
font-family:Arial'><o:p> </o:p></span></font></p>

<p class=MsoPlainText><font size=1 face=Arial><span style='font-size:9.0pt;
font-family:Arial'>I should point out there is a finite chance the disk can
still become corrupted.<o:p></o:p></span></font></p>

<p class=MsoPlainText><font size=1 face=Arial><span style='font-size:9.0pt;
font-family:Arial'>How small the window becomes depends on the system design,
for example how often<o:p></o:p></span></font></p>

<p class=MsoPlainText><font size=1 face=Arial><span style='font-size:9.0pt;
font-family:Arial'>the disk is updated, power supply power down storage vs
media write time,<o:p></o:p></span></font></p>

<p class=MsoPlainText><font size=1 face=Arial><span style='font-size:9.0pt;
font-family:Arial'>non-bricking read-only partitions, etc.<o:p></o:p></span></font></p>

<p class=MsoPlainText><font size=1 face=Arial><span style='font-size:9.0pt;
font-family:Arial'><o:p> </o:p></span></font></p>

<p class=MsoPlainText><font size=1 face=Arial><span style='font-size:9.0pt;
font-family:Arial'>I suspect triggering a timer to purge the cache as shown
above is no different<o:p></o:p></span></font></p>

<p class=MsoPlainText><font size=1 face=Arial><span style='font-size:9.0pt;
font-family:Arial'>to lowering the `swapout` task's period. It has been a while
since I looked over<o:p></o:p></span></font></p>

<p class=MsoPlainText><font size=1 face=Arial><span style='font-size:9.0pt;
font-family:Arial'>this code. The libblock cache implements separate threads to
"sync" the cache to<o:p></o:p></span></font></p>

<p class=MsoPlainText><font size=1 face=Arial><span style='font-size:9.0pt;
font-family:Arial'>the media on a periodic basis. The cache's configuration
lets you set the<o:p></o:p></span></font></p>

<p class=MsoPlainText><font size=1 face=Arial><span style='font-size:9.0pt;
font-family:Arial'>period. The values are documented here:<o:p></o:p></span></font></p>

<p class=MsoPlainText><font size=1 face=Arial><span style='font-size:9.0pt;
font-family:Arial'><o:p> </o:p></span></font></p>

<p class=MsoPlainText><font size=1 face=Arial><span style='font-size:9.0pt;
font-family:Arial'>https://docs.rtems.org/doxygen/branches/master/group__rtems__bdbuf.html#define-members<o:p></o:p></span></font></p>

<p class=MsoPlainText><font size=1 face=Arial><span style='font-size:9.0pt;
font-family:Arial'><o:p> </o:p></span></font></p>

<p class=MsoPlainText><font size=1 face=Arial><span style='font-size:9.0pt;
font-family:Arial'>This however raises a difficult question which is documented
in the code in a<o:p></o:p></span></font></p>

<p class=MsoPlainText><font size=1 face=Arial><span style='font-size:9.0pt;
font-family:Arial'>comment:<o:p></o:p></span></font></p>

<p class=MsoPlainText><font size=1 face=Arial><span style='font-size:9.0pt;
font-family:Arial'><o:p> </o:p></span></font></p>

<p class=MsoPlainText><font size=1 face=Arial><span style='font-size:9.0pt;
font-family:Arial'> https://git.rtems.org/rtems/tree/cpukit/libblock/src/bdbuf.c#n1013<o:p></o:p></span></font></p>

<p class=MsoPlainText><font size=1 face=Arial><span style='font-size:9.0pt;
font-family:Arial'><o:p> </o:p></span></font></p>

<p class=MsoPlainText><font size=1 face=Arial><span style='font-size:9.0pt;
font-family:Arial'>It is difficult when using a timer to know if the purge is
100% safe. If you can<o:p></o:p></span></font></p>

<p class=MsoPlainText><font size=1 face=Arial><span style='font-size:9.0pt;
font-family:Arial'>arrange the purge call to happen after you know the update
has finished it<o:p></o:p></span></font></p>

<p class=MsoPlainText><font size=1 face=Arial><span style='font-size:9.0pt;
font-family:Arial'>lowers the chance the disk maybe become corrupted.<o:p></o:p></span></font></p>

<p class=MsoPlainText><font size=1 face=Arial><span style='font-size:9.0pt;
font-family:Arial'><o:p> </o:p></span></font></p>

<p class=MsoPlainText><font size=1 face=Arial><span style='font-size:9.0pt;
font-family:Arial'>Chris<o:p></o:p></span></font></p>

</div>

</body>

</html>