<h2>1 Background</h2><p class="western">The purpose of this document is to describe the interfacing of the Yaffs Direct Interface (YDI) as well as to provide sufficient information to allow a preliminary evaluation of Yaffs. This document tries to focus on the issues important to the system integrator without getting too detailed about how Yaffs works. Other documents provide an in-depth discussion of how Yaffs works.</p><h2 class="western">2 Licensing</h2><p class="western">Yaffs was originally released for Linux under the GNU Public License (GPL). Various embedded developers soon identified that Yaffs would be ideal for their applications, but were not able to use GPL based code in their systems. Aleph One has alternative licensing arrangements to support such applications.</p><h2 class="western">3 What are Yaffs and Yaffs Direct Interface?</h2><p class="western">Yaffs stands for <i>Yet Another Flash File System</i>. Yaffs was the first file system designed, from the ground up, for NAND storage.</p><p class="western">In 2002 Aleph One set out to identify file system options for using NAND Flash as a file system. Various file systems available at the time were evaluated and all were found lacking in one way or another. The need for a suitable NAND storage file system was identified and Yaffs was designed to fill that need.</p><p class="western">Although Yaffs was originally designed for NAND flash, it has been used successfully with NOR flash systems and even as a RAM file system. This allows high reliability file systems to be constructed using NOR flash, with a future migration path to NAND flash for higher density and performance.</p><p class="western">Yaffs was originally designed for use with the Linux operating system, but was designed in a very modular way. The operating-system-specific code was kept separate from the main Yaffs file system code. This allows Yaffs to be ported quite cleanly to other operating systems through operating system personality modules. One such personality module is the Yaffs Direct Interface (YDI) which allows Yaffs to be simply integrated with embedded systems, with or without an RTOS.</p><p class="western"><br>Yaffs has been used for many products using various operating systems including Windows CE and various RTOSs, including ThreadX, vXworks, pSOS to name just a few.</p><p class="western">Note that there is a native port to eCOS that does not use YDI. This is supported and distributed by eCocCentric.(http://www.ecoscentric.com/).</p><p class="western">Yaffs2, a more recent release of Yaffs, supports a wider range of NAND flash components including 2k page devices, and produces equivalent or better performance. It include Yaffs1 compatibility code so Yaffs1 images still work and migration is quite simple.</p><p class="western">As well as providing a NAND file system, YDI also provides a RAM emulation layer to allow Yaffs to operate as a RAM file system too. While the RAM emulation is perhaps not as efficient as a dedicated RAM file system, this does allow one well proven file system to use both RAM and flash.</p><h2 class="western">4 Why use Yaffs?</h2><p class="western">Yaffs is the first, and perhaps only, file system designed specifically for NAND flash. This means that Yaffs has been designed to work around the various limitations and quirks of NAND flash, as well as exploit the various features of NAND to achieve an effective file system.</p><p class="western">Some features to consider:</p><ul><li><p class="western">Yaffs has been well proven and has been used to ship in large volumes in several products using many different operating systems, compilers and processors.</p></li><li><p class="western">Yaffs is written in portable C and is endian neutral.</p></li><li><p class="western">Yaffs provides bad<b> </b>block handling and ECC algorithms to handle deficiencies in NAND flash.</p></li><li><p class="western">Yaffs is a log-structured file system which makes it very robust to corruptions caused by power failures etc.</p></li><li><p class="western">Yaffs has highly optimised and predictable garbage collection strategies. This makes it high performance and very deterministic when compared with similar file systems.</p></li><li><p class="western">Yaffs has a lower memory footprint than most other log-structured flash file systems.</p></li><li><p class="western">Yaffs provides a wide range of POSIX-style file system support including directories, symbolic and hard links etc. through standard file system interface calls.</p></li><li><p class="western">Yaffs is highly configurable to work with various flash geometries, various ECC options, caching options etc.</p></li><li><p class="western">Yaffs Direct Interface is simple to integrate in a system – only a few interface functions are required.</p></li><li><p class="western">Yaffs can be used with a wide range of memory technologies.</p></li></ul><h2 class="western">5 Source Code and Yaffs Resources</h2><p class="western"><font face="Liberation Serif, serif">Please note the licensing terms that apply to using the Yaffs code.</font></p><p class="western"><a href="http://www.yaffs.net/"><font face="Liberation Serif, serif">http://www.yaffs.net</font></a><font face="Liberation Serif, serif"> serves as the hub for all Yaffs information.</font></p><p class="western"><font face="Liberation Serif, serif">This document refers to the Yaffs source code extensively. and is available via the download link on this site.</font></p><p class="western"><font face="Liberation Serif, serif">There are various other documents and a Yaffs mailing list for Yaffs discussions.</font></p><p class="western"><font face="Liberation Serif, serif">Consulting services are also available.</font></p><h2 class="western">6 System Requirements</h2><p class="western">Determining minimum system requirements is often quite difficult. The following are presented as a guideline only. Contact Aleph One for more detailed analysis if required.</p><ul><li><p class="western">Yaffs is endian-neutral and works fine with little-endian and big-endian processors.</p></li><li><p class="western">Yaffs code has been used successfully with many different 32-bit and 64-bit CPUs including MIPS, 68000, ARM, ColdFire, PowerPC and x86 variants. Yaffs should work with 16-bit CPUs too, but this is generally untested and might need some tuning, depending on compiler options.</p></li><li><p class="western">Because Yaffs is log structured, RAM is required to build up runtime data structures for acceptable performance. As a rule of thumb, budget approximately 2 bytes per <i>chunk</i> of NAND flash, where a <i>chunk</i> is typically one page of NAND. For NAND with 512byte pages, budget approximately 4kbytes of RAM per 1Mbyte of NAND. For 2kbyte page devices budget approximately 1kbyte per 1Mbyte of NAND.</p></li></ul><h2 class="western">7 How to integrate Yaffs with an RTOS/Embedded system</h2><p class="western">Yaffs Direct Interface (YDI) wraps Yaffs in a way that is simple to integrate. You need to provide a few functions for Yaffs to use to talk to your hardware and OS. Yaffs provides a set of POSIX-compliant functions for applications to use to talk to it.</p><p class="western">In addition to the Yaffs core file system, the YDI has three parts which are each explained in more detail in further sections:</p><ul><li><p class="western"><b>POSIX Application Interface</b>: This is the interface that the application code uses to access the Yaffs file system. (<font face="Times New Roman"><i>open, close, read, write, </i></font>etc)</p></li><li><p class="western"><b>RTOS Integration Interface</b>: These are the functions that must be provided for Yaffs to access the RTOS system resources. (<font face="Times New Roman"><i>initialise, lock, unlock, get time, set error</i></font>)</p></li><li><p class="western"><b>Flash Configuration and Access Interface</b>: These are the functions that must be provided for Yaffs to access the NAND flash. (<i>initialise, read chunk, write chunk, erase block, </i>etc). These functions might be supplied by a chipset vendor or might need to be written by the integrator.</p></li></ul><p class="western"><img alt="Yaffs Direct Interface Layer" src="/sites/yaffs.net/files/images/Yaffs%20Direct%20Interface%20layer.gif" style="width: 340px; height: 455px; "></p><h3 class="western">7.1 Source Files</h3><p class="western">The following source files contain the core file system:</p><table cellpadding="4" cellspacing="0" width="100%"><colgroup><col width="71*"><col width="185*"></colgroup><tbody><tr valign="TOP"><td style="border-top-style: solid; border-top-color: rgb(0, 0, 0); border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: none; border-right-width: initial; border-right-color: initial; padding-top: 0.1cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0cm; " width="28%"><p class="western">yaffs_allocator.c</p></td><td style="border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: rgb(0, 0, 0); border-right-color: rgb(0, 0, 0); border-bottom-color: rgb(0, 0, 0); border-left-color: rgb(0, 0, 0); padding-top: 0.1cm; padding-right: 0.1cm; padding-bottom: 0.1cm; padding-left: 0.1cm; " width="72%"><p class="western">Allocates Yaffs object and tnode structures.</p></td></tr><tr valign="TOP"><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: none; border-right-width: initial; border-right-color: initial; padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0cm; " width="28%"><p class="western">yaffs_checkpointrw.c</p></td><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: solid; border-right-color: rgb(0, 0, 0); padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0.1cm; " width="72%"><p class="western">Streamer for writing checkpoint data</p></td></tr><tr valign="TOP"><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: none; border-right-width: initial; border-right-color: initial; padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0cm; " width="28%"><p class="western">yaffs_ecc.c</p></td><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: solid; border-right-color: rgb(0, 0, 0); padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0.1cm; " width="72%"><p class="western">ECC code</p></td></tr><tr valign="TOP"><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: none; border-right-width: initial; border-right-color: initial; padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0cm; " width="28%"><p class="western">yaffs_guts.c</p></td><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: solid; border-right-color: rgb(0, 0, 0); padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0.1cm; " width="72%"><p class="western">The major Yaffs algorithms.</p></td></tr><tr valign="TOP"><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: none; border-right-width: initial; border-right-color: initial; padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0cm; " width="28%"><p class="western">yaffs_nand.c</p></td><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: solid; border-right-color: rgb(0, 0, 0); padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0.1cm; " width="72%"><p class="western">Flash interfacing abstraction.</p></td></tr><tr valign="TOP"><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: none; border-right-width: initial; border-right-color: initial; padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0cm; " width="28%"><p class="western">yaffs_packedtags1.c<br>yaffs_packedtags2.c</p></td><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: solid; border-right-color: rgb(0, 0, 0); padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0.1cm; " width="72%"><p class="western">Tags packing code</p></td></tr><tr valign="TOP"><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: none; border-right-width: initial; border-right-color: initial; padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0cm; " width="28%"><p class="western">yaffs_qsort.c</p></td><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: solid; border-right-color: rgb(0, 0, 0); padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0.1cm; " width="72%"><p class="western">Qsort used during Yaffs2 scanning</p></td></tr><tr valign="TOP"><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: none; border-right-width: initial; border-right-color: initial; padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0cm; " width="28%"><p class="western">yaffs_tagscompat.c</p></td><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: solid; border-right-color: rgb(0, 0, 0); padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0.1cm; " width="72%"><p class="western">Tags compatibility code to support Yaffs1 mode.</p></td></tr><tr valign="TOP"><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: none; border-right-width: initial; border-right-color: initial; padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0cm; " width="28%"><p class="western">yaffs_tagsvalidity.c</p></td><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: solid; border-right-color: rgb(0, 0, 0); padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0.1cm; " width="72%"><p class="western">Tags validity checking.</p></td></tr></tbody></table><p class="western">The Yaffs direct interface is in yaffsfs.c, with the interface functions and structures defined in yaffsfd.h.</p><p class="western">Example and testing build files:</p><table cellpadding="4" cellspacing="0" width="100%"><colgroup><col width="71*"><col width="185*"></colgroup><tbody><tr valign="TOP"><td style="border-top-style: solid; border-top-color: rgb(0, 0, 0); border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: none; border-right-width: initial; border-right-color: initial; padding-top: 0.1cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0cm; " width="28%"><p class="western">dtest.c</p></td><td style="border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: rgb(0, 0, 0); border-right-color: rgb(0, 0, 0); border-bottom-color: rgb(0, 0, 0); border-left-color: rgb(0, 0, 0); padding-top: 0.1cm; padding-right: 0.1cm; padding-bottom: 0.1cm; padding-left: 0.1cm; " width="72%"><p class="western">A test harness. Also has sample code that can be used for better understanding of how some function calls work.</p></td></tr><tr valign="TOP"><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: none; border-right-width: initial; border-right-color: initial; padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0cm; " width="28%"><p class="western">yaffscfg2k.c</p></td><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: solid; border-right-color: rgb(0, 0, 0); padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0.1cm; " width="72%"><p class="western">A test configuration.</p></td></tr><tr valign="TOP"><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: none; border-right-width: initial; border-right-color: initial; padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0cm; " width="28%"><p class="western">yaffs_fileem.c<br>yaffs_fileem2k.c</p></td><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: solid; border-right-color: rgb(0, 0, 0); padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0.1cm; " width="72%"><p class="western">Nand flash simulation using a file as backing store.</p></td></tr><tr valign="TOP"><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: none; border-right-width: initial; border-right-color: initial; padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0cm; " width="28%"><p class="western">yaffs_norif1.c</p></td><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: solid; border-right-color: rgb(0, 0, 0); padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0.1cm; " width="72%"><p class="western">Nor flash simulation and interfacing example. This is configured for M18 flash.</p></td></tr><tr valign="TOP"><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: none; border-right-width: initial; border-right-color: initial; padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0cm; " width="28%"><p class="western">yaffs_ramdisk.c<br>yaffs_ramem2k.c</p></td><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: solid; border-right-color: rgb(0, 0, 0); padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0.1cm; " width="72%"><p class="western">Simulations using RAM.</p></td></tr><tr valign="TOP"><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: none; border-right-width: initial; border-right-color: initial; padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0cm; " width="28%"><p class="western">ynorsim.c</p></td><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: solid; border-right-color: rgb(0, 0, 0); padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0.1cm; " width="72%"><p class="western">Another Nor simulation.</p></td></tr></tbody></table><p class="western">Further testing files are in direct/tests and direct/python.</p><h3 class="western">7.2 Integrating the POSIX Application Interface</h3><p class="western">The application interface is defined in yaffsfs.h. These provide a POSIX file system interface. For the most part, this interface consists of the standard clib function names prefixed with <code class="western">yaffs_</code>. For example, <code class="western">yaffs_open(), yaffs_close()</code> etc.</p><p class="western"><br>&nbsp;</p><p class="western">There is a lot of flexibility in how these functions are used and the system integrator needs to determine the best strategy for the system.</p><p class="western">These functions can be used directly, with the code written using these names. For example</p><p class="code-western"><code class="western">int main(...)<br>{<br>// initialisation<br>f = yaffs_open(...);<br>yaffs_read(f,...);<br>yaffs_close(f);<br>}</code></p><p class="western">The <font face="Times New Roman">yaffs</font> functions can also be wrapped in some way to allow existing code to use yaffs without modification. For example:</p><p class="code-western"><code class="western">#define open(path, oflag, mode) yaffs_open(path, oflag, mode)<br>..<br><br>int main(...)<br>{<br>// initialisation<br>f = open(...);<br>read(f,...);<br>close(f);<br>}</code><br>&nbsp;</p><p class="western">A more complex approach that can be used if more than one file-system is used is to provide redirection functions. For example:</p><p class="code-western"><code class="western">int open(const char *path,...)<br>{<br>// Determine which file system is being used if(it_is_a_yaffs_path(path))<br>return yaffs_open(...);<br>else<br>{<br>// Do something else<br>}<br>}</code></p><p class="western">Some RTOS's provide a flexible way to integrate file systems in which case YDI can typically use these interfaces to access yaffs file systems.</p><h3 class="western">7.3 RTOS Integration Interface</h3><p class="western">Before Yaffs can be used, it needs to be integrated with the system and configured so that the correct actions are performed.</p><p class="western">To do this, you need to modify the configuration file. An example configuration file is presented in <font face="Bitstream Vera Sans"><font face="Times New Roman">yaffscfg.c and yaffscfg2k.c.</font></font></p><p class="western">This is a relatively straight forward process and defines the RTOS access functions.</p><p class="western">The RTOS access functions are:</p><ul><li><p class="western"><code class="western">void yaffsfs_SetError(int err)</code>: Called by Yaffs to set the system error.</p></li><li><p class="western"><code class="western">void yaffsfs_Lock(void)</code>: Called by Yaffs to lock Yaffs from multi-threaded access.</p></li><li><p class="western"><code class="western">void yaffsfs_Unlock(void)</code>: Called by Yaffs to unlock Yaffs.</p></li><li><p class="western"><code class="western">__u32 yaffsfs_CurrentTime(void)</code>: Get current time from RTOS.</p></li><li><p class="western"><code class="western">void yaffsfs_LocalInitialisation(void)</code>: Called to initialise RTOS context.</p></li></ul><p class="western">If Yaffs is being used in a multi-threaded environment, then typically <code class="western">yaffs_LocalInitialisation()</code> will initialise a suitable RTOS semaphore and <code class="western">yaffs_Lock()</code> and <code class="western">yaffs_Unlock()</code> will call the appropriate functions to lock and release the semaphore.</p><p class="western"><code class="western">yaffs_CurrentTime()</code> can be any time increment of use to the system. If this is not required, then it is fine to just use a function that is hard-wired to return zero.</p><p class="western">Although not shown here, Yaffs also requires memory allocation/free functions which default to <code class="western">malloc()</code> and <code class="western">free()</code>. These, and some other functions can be tuned in file <font face="Bitstream Vera Sans"><font face="Times New Roman">ydirectenv.h</font></font></p><p class="western">Before the application code uses Yaffs, the <code class="western">yaffs_StartUp()</code> function must be called and the appropriate partitions must be mounted. This is typically done in the system boot code:</p><p class="code-western"><code class="western">...</code></p><p class="code-western"><code class="western">/* System boot code: Start up Yaffs. */<br>yaffs_StartUp();<br>yaffs_mount("/boot");</code></p><p class="code-western"><code class="western">...</code></p><h2 class="western">8 Yaffs NAND Model</h2><p class="western">Before defining the flash integration interface, it is important to understand the model and corresponding nomenclature used throughout Yaffs and its documentation.</p><p class="western">Yaffs uses a fairly abstract model for NAND flash. This allows a lot of flexibility in the way it can be used.</p><p class="western">Yaffs is designed for NAND flash and makes the following assumptions and definitions:</p><ul><li><p class="western">The flash is arranged in <i><b>blocks</b></i>. Each block is the same size and comprises an integer number of chunks. Each block is treated as a single erasable item. A block contains a number of chunks.</p></li><li><p class="western">A <i><b>chunk</b></i> equates to the allocation units of flash. For Yaffs1, each chunk equates to a 512-byte or larger NAND page (that is, a 512-byte or larger data portion and a 16-byte spare area). For Yaffs2, a chunk will typically be larger (eg. on 2k page devices, a chunk will typically be a single 2k page: 2kbytes of data and 64 bytes of spare). Yaffs2 is capable of working with smaller chunk sizes by using inband tags.</p></li><li><p class="western">All accesses (reads and writes) are page chunk aligned. Some reads might only read the spare area where the tags are kept.</p></li><li><p class="western">When programming a NAND flash, only the zero bits in the pattern being programmed are relevant, and one bits are "don't care". For example, if a byte already contains the binary pattern 1010, then programming 1001 will result in the pattern which is the logical AND of these two patterns ie. 1000. This is different to NOR flash which would typically abort the attempt to convert a 0 into a 1.</p></li></ul><p class="western">Yaffs identifies blocks by their block number and chunks by the chunk Id. A chunk Id is calculated as:</p><p class="western"><code class="western">chunkId = block_id * chunks_per_block + chunk_offset_in_block</code></p><p class="western">Yaffs treats a blank (0xFF filled) block as being free or erased. Thus, the equivalent of formatting for a Yaffs partition is to erase all the blocks that are not bad.</p><p class="western">Yaffs2 has a generalised tags interface to provide better flexibility to cater for a wider range of devices with larger pages and stricter programming limitations. Yaffs2 thus handles more abstract constructs than Yaffs1 and more effort is required to interface to the NAND.</p><h3 class="western">8.1 NAND Model considerations for Yaffs1</h3><p class="western">The historical Yaffs1 tags structure was laid out in accordance with the SmartMedia specification for use with 512-byte pages. There is now much more flexibility in the way things can be configured.</p><p class="western">Yaffs1 is capable of being used with a variety of memory layouts so long as the flash supports the ability to overwrite the tags area to set the deletion marker to zero.</p><p class="western">If the yaffs_Device's useNANDECC filed is not set, then yaffs will perform the ECC calculations. If this iset then yaffs will expect the NAND driver todo any required ECC checks. On devices that are not using ECC, for example NOR, set useNANDECC=1 and then don't do any ECC anyway.</p><p class="western">The Yaffs1 flash model expects an area of 16 spare bytes, some of which are used for tags. The mapping between the spare bytes and the usage of the bytes is specified in yaffs_packedtags1.c</p><p class="western">The Yaffs1 model has been used in many NOR-based systems. One particularly instructive example is in yaffs_norif1.c which implements Yaffs1 mode on Intel M18 flash using 1k data pages and simulating a spare area on re-writable areas of flash. This does not use ECC but uses checksumming instead.</p><h3 class="western">8.2 NAND Model for Yaffs2</h3><p class="western">Yaffs2 uses a different tags layout than Yaffs1. Yaffs2 uses a yaffs_ExtendedTags structure.which is packed according to the code in yaffs_packedtags2.c.</p><p class="western">The NAND handler layer must use or populate the fields. The fields have the following meaning:</p><ul><li><p class="western"><code class="western">validMarker0</code> Set to 0xAAAAAAAA</p></li><li><p class="western"><code class="western">chunkUsed</code><font face="Courier, monospace"> </font>If 0 then this chunk is not in use</p></li><li><p class="western"><code class="western">objectId</code> The object this chunk belongs to. If 0 then this is not part of an object (ie. unused).</p></li><li><p class="western"><code class="western">chunkId</code><font face="Courier, monospace"> </font> If 0 then this is a header, else a data chunk at the specified position in the file</p></li><li><p class="western"><code class="western">byteCount</code> Number of data bytes in the chunk. Only valid for data chunks</p></li></ul><p class="western">The following fields only have meaning when we read</p><ul><li><p class="western"><code class="western">eccResult</code> <font face="Times new roman">Result of ECC check when reading</font></p></li></ul><ul><li><p class="western"><code class="western">blockBad</code> If 0 then the block is not bad.</p></li></ul><p class="western">The following fields have meaning for Yaffs1 and should be zero for Yaffs:</p><ul><li><p class="western"><code class="western">chunkDeleted</code> if non-zero, the chunk is marked deleted.</p></li><li><p class="western"><code class="western">serialNumber</code> 2-bit serial number.</p></li></ul><p class="western">The following field has meaning for Yaffs1 and should be zero for Yaffs2:</p><ul><li><p class="western"><code class="western">sequenceNumber</code> The sequence number of this block</p></li></ul><p class="western">Optional extra info if this is an object header (Yaffs2 only). Make zero for Yaffs1.</p><p class="western">If <code class="western">extraHeaderInfoAvailable</code> is set, then all the <code class="western">extraXXX</code> fields must be valid.</p><ul><li><p class="western"><code class="western">extraHeaderInfoAvailable</code> There is extra info available if this is not zero.</p></li><li><p class="western"><code class="western">extraParentObjectId</code> The parent object id.</p></li><li><p class="western"><code class="western">extraIsShrinkHeader</code> Is it a shrink header?</p></li><li><p class="western"><code class="western">extraShadows</code> Does this shadow another object?</p></li><li><p class="western"><code class="western">extraObjectType</code><font face="Courier, monospace"> </font> What object type?</p></li><li><p class="western"><code class="western">extraFileLength</code> Length if it is a file.</p></li><li><p class="western"><code class="western">extraEquivalentObjectId</code> Equivalent object Id if it is a hard link.</p></li></ul><p class="western">And finally:</p><ul><li><p class="western"><code class="western">validMarker1</code> Must be 0x55555555.</p></li></ul><p class="western">There are quite a few fields, some of which are optional. All the <code class="western">extraXXXX</code> fields are a way of stuffing more data into object header tags in a way that speeds up scanning. These are optional and should all be zero if not supported.</p><p class="western">The easiest way to process the <code class="western">yaffs_ExtendedTags</code> is to use the functions presented in yaffs_packedtags2.h to do the packing and unpacking. These are:</p><p class="western"><code class="western">yaffs_PackTags2()</code><font face="Times New Roman, serif"> and </font><code class="western">yaffs_UnpackTags2()</code><font face="Liberation Serif, serif"><font size="2">.</font></font></p><p class="western">These functions create or use a packed tags structure which can be stored in the NAND spare area. An example of how to do this is presented in yaffs_fileem2.c</p><h2 class="western">9 NAND Configuration and Access Interface</h2><p class="western">For an example of how to do the configuration, refer to yaffs_cfg.c and yaffs_cfg2k.c.</p><p class="western">This part of the configuration involves configuring the chips and suitable access functions.</p><p class="western">This is done in <code class="western">yaffs_StartUp().</code></p><p class="western">Before launching into the device configuration, it is important to understand that Yaffs supports two different modes of operation:</p><ul><li><p class="western">Yaffs1: This is the original mode of operation and is only available for 512-byte-per-page devices.</p></li><li><p class="western">Yaffs2: This mode of operation supports larger page sizes.</p></li></ul><p class="western">Most configuration options are the same for both, but they have different NAND access functions.</p><p class="western">You may have a system that uses a mix of Yaffs1 and Yaffs2 partitions.</p><h3 class="western">9.1 Common configuration items (Yaffs1 and Yaffs2)</h3><p class="western">The configuration involves two parts:</p><ul><li><p class="western">Setting up the mount point table.</p></li><li><p class="western">Setting up the devices.</p></li></ul><p class="western">A <i>yaffsfs_DeviceConfiguration</i> is an entry that has two parts: a mount point name and a pointer to a <i>yaffs_Device</i> structure. The mount point name is used to determine where the particular <i>yaffs_Device</i> may be found in the directory structure. There can be any number of mount points and they may be nested. For example:</p><p class="code-western"><code class="western">static yaffsfs_DeviceConfiguration yaffsfs_config[] = {</code></p><p class="code-western"><code class="western">{ "/", &amp;ramDev},</code></p><p class="code-western"><code class="western">{ "/flash/boot", &amp;bootDev},</code></p><p class="code-western"><code class="western">{ "/flash/flash", &amp;flashDev},</code></p><p class="code-western"><code class="western">{ "/ram2k", &amp;ram2kDev},</code></p><p class="code-western"><code class="western">{(void *)0,(void *)0} /* Terminate list */</code></p><p class="code-western"><code class="western">};</code></p><p class="western">Each logical storage entity is called a <i>yaffs_Device</i> and is probably best though of as a partition descriptor. Each <i>yaffs_Device</i> can correspond to:</p><ul><li><p class="western">A whole flash device.</p></li><li><p class="western">Part of a flash device.</p></li><li><p class="western">Something other than a flash device (e.g. perhaps a RAM emulation). During testing, this emulation capability is often employed to use a host system hard-disk file or nfs-mounted file as an alternative storage mechanism.</p></li></ul><p class="western">Two or more<var> </var><var><font face="Times, serif">yaffs_Devices</font></var><var> </var>can reside in a single physical flash device by specifying different start and end blocks. For example here is a case where a single device is split into two partitions:</p><p class="code-western"><code class="western">// /boot<br>......<br>bootDev.param.startBlock = 0; // First block.<br>bootDev.param.endBlock = 55; // Last block in 2MB.<br><br>// /disk<br>...<br>diskDev.param.startBlock = 56; // First block after 2MB<br>diskDev.param.endBlock = 1023; // Last block in 16MB</code></p><p class="western">All <i>yaffs_Device</i> structures must be configured according to the Yaffs Tuning document.</p><h3 class="western">9.2 Common Access Functions (Yaffs1 and Yaffs2)</h3><p class="western">Both Yaffs1 and Yaffs2 configurations must provide pointers to the following functions:</p><p class="code-western"><code class="western">int (*eraseBlockInNAND)(struct yaffs_DeviceStruct *dev,int blockInNAND)</code></p><p class="western">Yaffs calls this function to erase a block of flash.</p><p class="western"><font face="Courier New, monospace"><font size="2"><code class="western">int (*initialiseNAND)(struct yaffs_DeviceStruct *dev)</code></font></font></p><p class="western">Yaffs calls this function at start up before other functions get called to access the <i>yaffs_Device</i>. This allows the system integrator a control point to perform any required initialisation (eg. set up chip selects etc.).</p><h3 class="western">9.3 Yaffs1 Access Functions</h3><p class="western">For Yaffs1 partitions, the yaffs_Device configuration also specifies pointers to two further functions that Yaffs calls to access the NAND for this yaffs_Device. For a better understanding of these functions, see the section on the Yaffs NAND Model. These functions are:</p><p class="code-western"><code class="western">int (*writeChunkToNAND)(struct yaffs_DeviceStruct *dev,int chunkInNAND, const __u8 *data, yaffs_Spare *spare)</code></p><p class="western">Yaffs calls this function to write data to NAND. The <font face="Courier, monospace"><font size="2">data</font></font> pointer may be NULL if only the spare area is being written, as happens when the chunk is being deleted or retired. If the data pointer is NULL then do not write the data. The <font face="Courier, monospace"><font size="2">spare</font></font> pointer will never be NULL.</p><p class="code-western"><code class="western">int (*readChunkFromNAND)(struct yaffs_DeviceStruct *dev,int chunkInNAND, __u8 *data, yaffs_Spare *spare)</code></p><p class="western">Yaffs calls this function when reading a chunk from flash. The meanings of the arguments are obvious from the above, but note that the data and spare fields might be NULL, in which case those pointers should not be dereferenced.</p><h3 class="western">9.4 Yaffs2 Access Functions</h3><p class="western">The Yaffs2 mode of operation is far more flexible than the Yaffs1 mode of operation. That allows for far more different types of flash to be used, but slightly increases the complexity of the NAND access functions.</p><p class="western">With the Yaffs1 mode of operation, Yaffs performs bad block detection and marking and can optionally perform ECC. It can do this because it assumes that the NAND spare area is structured in a certain way. The Yaffs2 mode of operation can no longer make those assumptions which means that the system integrator must provide slightly more complex functions. However, the interface is still relatively simple, particularly if existing code is used as a basis.</p><p class="code-western"><code class="western">int (*writeChunkWithTagsToNAND) (struct yaffs_DeviceStruct * dev,</code></p><p class="code-western"><code class="western">int chunkInNAND, const __u8 * data,</code></p><p class="code-western"><code class="western">const yaffs_ExtendedTags * tags)</code></p><p class="code-western"><code class="western">int (*readChunkWithTagsFromNAND) (struct yaffs_DeviceStruct * dev,</code></p><p class="code-western"><code class="western">int chunkInNAND, __u8 * data,</code></p><p class="code-western"><code class="western">yaffs_ExtendedTags * tags)</code></p><p class="code-western"><code class="western">int (*markNANDBlockBad) (struct yaffs_DeviceStruct * dev, int blockNo);</code></p><p class="code-western"><code class="western">int (*queryNANDBlock) (struct yaffs_DeviceStruct * dev, int blockNo,</code></p><p class="code-western"><code class="western">yaffs_BlockState * state, int *sequenceNumber)</code></p><p class="western">The <code class="western">writeChunkWithTagsToNAND()</code> and <code class="western">readChunkWithTagsFromNAND()</code> functions must save or retrieve the data and extended tags. Please refer to the explanation of the Yaffs2 NAND model for a better understanding of how to handle the tags. Please note that under certain circumstances, the <font face="Courier, monospace">data</font> and <font face="Courier, monospace">tags</font> pointers may be NULL and the driver code should ignore transfers from or to pointers that are NULL.</p><p class="western">The NAND access functions must also provide a mechanism for marking and tracking bad blocks. If a bad block is detected and Yaffs decides to mark that block bad, the <code class="western">markNANDBlockBad()</code><font color="#000000"><font face="Courier, monospace"><font size="2"> </font></font></font><font color="#000000"><font face="Liberation Serif, serif">function is called.</font></font></p><p class="western">The <code class="western">queryNANDBlock()</code> function does two things:</p><ul><li><p class="western">It determines the block state</p></li><li><p class="western">If the block is in use it also retrieves the block’s sequence number.</p></li></ul><p class="western">By far the easiest way to understand this all is to refer to the example code provided.</p><h2 class="western">10 Using the POSIX file system interface</h2><p class="western">This section is directed to readers that might not be very familiar with accessing a file system via POSIX and POSIX-like interfaces.</p><h3 class="western">10.1 Difference to Windows POSIX-like interfaces</h3><p class="western">MSDOS and Windows provide a POSIX-lke interface. If you are familiar with this then that will help you. There are are however some slight differences, most importantly:</p><ul><li><p class="western">Windows has no concept of links and has a 1:1 mapping between file names and files.POSIX supports files with zero, one or many names. Refer to the sections on linking and unlinking files. For instance POSIX allows you to unlink a file (ie delete the name for a file) while it is still in use. You can continue to read/write the file but it will be deleted as soon as the last file handle to the file is closed. Windows, on the other hand, does not allow you to unlink a file while it is in use.</p></li><li><p class="western">Windows names drives with a letter. POSIX has no drive letters. The whole POSIX file system is in a single directory tree.</p></li><li><p class="western">Directories and “folders” are the same thing.</p></li></ul><h3 class="western">10.2 Fundamental concepts</h3><table cellpadding="4" cellspacing="0" width="642"><colgroup><col width="126"><col width="499"></colgroup><tbody><tr valign="TOP"><td style="border-top-style: solid; border-top-color: rgb(0, 0, 0); border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: none; border-right-width: initial; border-right-color: initial; padding-top: 0.1cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0cm; " width="126"><p class="western">File</p></td><td style="border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: rgb(0, 0, 0); border-right-color: rgb(0, 0, 0); border-bottom-color: rgb(0, 0, 0); border-left-color: rgb(0, 0, 0); padding-top: 0.1cm; padding-right: 0.1cm; padding-bottom: 0.1cm; padding-left: 0.1cm; " width="499"><p class="western">A file is an object that is stored in the file system. yaffs supports the following file types:</p><p class="western">A regular file is a sequence of bytes stored in the file system.</p><p class="western">A directory holds links to other files.</p><p class="western">A symbolic link holds a name to another file.</p><p class="western">A special file holds device ids or similar information.</p></td></tr><tr valign="TOP"><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: none; border-right-width: initial; border-right-color: initial; padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0cm; " width="126"><p class="western">Directory</p></td><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: solid; border-right-color: rgb(0, 0, 0); padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0.1cm; " width="499"><p class="western">This is a structure that holds links and allows a file to be found by name. Note that a single file may have many links(ie names) and many be found in many places in the directory structure.</p></td></tr><tr valign="TOP"><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: none; border-right-width: initial; border-right-color: initial; padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0cm; " width="126"><p class="western">Link</p></td><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: solid; border-right-color: rgb(0, 0, 0); padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0.1cm; " width="499"><p class="western">This is a name that allows the file to be found. There are two types of link: real links (sometimes called hard links) and symbolic (or soft) links.</p></td></tr><tr valign="TOP"><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: none; border-right-width: initial; border-right-color: initial; padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0cm; " width="126"><p class="western">Handle</p></td><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: solid; border-right-color: rgb(0, 0, 0); padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0.1cm; " width="499"><p class="western">A file handle provides a context from which a file can be accessed and manipulated. A handle has a current file position pointer which points to where the file is being read or written. Multiple handles can simultaneously access a single file.</p></td></tr><tr valign="TOP"><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: none; border-right-width: initial; border-right-color: initial; padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0cm; " width="126"><p class="western">File mode</p></td><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: solid; border-right-color: rgb(0, 0, 0); padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0.1cm; " width="499"><p class="western">The mode is the set of flags that define the type of file as well as the current permissions associated with the file.</p></td></tr><tr valign="TOP"><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: none; border-right-width: initial; border-right-color: initial; padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0cm; " width="126"><p class="western">Path</p></td><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: solid; border-right-color: rgb(0, 0, 0); padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0.1cm; " width="499"><p class="western">This is a string that defines the directories and file name. For example:</p><p class="western">“/data/direct-1/file1”</p></td></tr><tr valign="TOP"><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: none; border-right-width: initial; border-right-color: initial; padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0cm; " width="126"><p class="western">File metadata</p></td><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: solid; border-right-color: rgb(0, 0, 0); padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0.1cm; " width="499"><p class="western">This is the information about the file, excluding the file contents. The metadata includes the name, mode, size and other details.</p></td></tr><tr valign="TOP"><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: none; border-right-width: initial; border-right-color: initial; padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0cm; " width="126"><p class="western">Mount,<br>partition,<br>file system</p></td><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: solid; border-right-color: rgb(0, 0, 0); padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0.1cm; " width="499"><p class="western">These terms all refer to a single mounted flash area. Each mount is hooked into a common directory structure.<br>The term file system can sometimes be confusing because it is used both for a single mounted partition as well as the the file system code. In other words, we might say that both “/boot” is a file system and might also say that yaffs is a file system.</p></td></tr><tr valign="TOP"><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: none; border-right-width: initial; border-right-color: initial; padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0cm; " width="126"><p class="western">inode number</p></td><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: solid; border-right-color: rgb(0, 0, 0); padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0.1cm; " width="499"><p class="western">The inode number is a unique number that identifies the object within the mount. Note that inodes are not unique between two or more mounts. There is no way to reach a file by inode, only via its links.</p></td></tr></tbody></table><h3 class="western">10.3 Error code</h3><p class="western">Most functions result in error codes if the function does not execute successfully.In these cases yaffs calls a function called <code class="western">yaffs_SetError()</code> with the error value. This function can be configured to deliver the error into the system's error mechanism.</p><p class="western">In the case of functions that return integers, a returned value smaller than 0 indicates an error occurred. Functions returning pointers will return NULL if an error occurred.</p><h3 class="western">10.4 Links – the hard kind (not symbolic links)</h3><p class="western">At first we're just considering real links and not symbolic links. Sometimes real links are also called hard links to differentiate them from symbolic links (which are sometimes called soft links).</p><p class="western">The difference between links and files is subtle and can be confusing. Briefly:</p><ul><li><p class="western">a file is the stored object in the file system</p></li><li><p class="western">the link is how it is hooked into the directory structure.</p></li></ul><p class="western">The first link to a file is created by using the file creation calls: <code class="western">yaffs_open()</code>, <code class="western">yaffs_mknod()</code>, <code class="western">yaffs_symlink()</code> and <code class="western">yaffs_mkdir()</code>.</p><p class="western">A link can be destroyed by using the <code class="western">yaffs_unlink()</code> function. Directories are destroyed using the <code class="western">yaffs_rmdir()</code> function (oh, and the directory must be empty).</p><p class="western">Once a file is both unused (there are no handles open to it) and there are no links to it it is then deleted.</p><p class="western">A link can be renamed by using the <code class="western">yaffs_rename()</code> function.</p><p class="western">A file may have many links. These may be created using the <code class="western">yaffs_link()</code> function. All the links access the same file and there is no one link that is considered “the real link” and others being “the duplicate link”. All links to a file have the same priority. If you look at the inode number for “a” and for “b” then they will be the same because they are refering to exactly the same file.</p><p class="western">Thus:</p><ol><li><p class="western">If we start with a file called “a” and then call <code class="western">yaffs_link(“a”, “b”)</code> we now have two links to the same file. We can't tell them apart.</p></li><li><p class="western">If we now unlink “a”, the file still exists under the link “b”.</p></li><li><p class="western">If we now unlink “b” the file will no longer be linked. If there is a handle open to the file then we can still access the file through the handle and continue to read or modify the file. If there is no link to the file it is deleted.</p></li><li><p class="western">If an unlinked file was kept alive because of a handle being open, the file will not show up in the directory structure (because it has no link) and will be deleted as soon as the handle is closed (or if the file system is unmounted).</p></li></ol><p class="western">There are some limitations in how links are used:</p><ul><li><p class="western">The existing file you are linking to must exist.</p></li><li><p class="western">The file you are linking to must be in the same mount (partition) as the link you are creating.</p></li><li><p class="western">You cannot create a link to a directory because this would allow the creation of recursive loops.</p></li><li><p class="western">The new link name must not exist.</p></li></ul><h3 class="western">10.5 Symbolic links</h3><p class="western">Now that you understand how hard links work, we'll introduce symbolic (or soft) links.</p><p class="western">A symbolic link holds an alias for a different object. When you use that symbolic link in a path the alias is used instead. To that extent symbolic link and hard links are the same.</p><p class="western">You can remove symbolic links with the <code class="western">yaffs_unlink()</code> function, just like hard links.</p><p class="western">There are, however, some important differences. A symbolic link only does its linking function when the path is being evaluated and thus:</p><ul><li><p class="western">The file you are creating an alias to does not have to exist.</p></li><li><p class="western">The file you are creating an alias to does not have to be in the same mount.</p></li><li><p class="western">You can create symbolic links to directories.</p></li><li><p class="western">A symbolic link will not keep a file alive by itself. Only a hard link can do that.</p></li></ul><p class="western">Thus:</p><ol><li><p class="western">If we start with a file called “a” and then call <code class="western">yaffs_symlink(“a”, “b”)</code> we now have one links to the file called “a” and a symbolic link aliasising from “b” to “a”.</p></li><li><p class="western">If we use <code class="western">yaffs_open(“a”)</code> or <code class="western">yaffs_open(“b”)</code> they will open the same file. The path resolution mechanism substitutes in the alias and so will look up “a”. The same applies to almost all functions that takes a path, such as <code class="western">yaffs_truncate()</code>, <code class="western">yaffs_stat()</code> etc. The only exceptions are <code class="western">yaffs_lstat()</code> and <code class="western">yaffs_readlink()</code> which will treat the path as pointing to the symbolic link and not the file.</p></li><li><p class="western">You can tell “a” and “b” apart by using <code class="western">yaffs_lstat()</code>. <code class="western">yaffs_lstat(“a”)</code> will show the information for file “a”. <code class="western">yaffs_lstat(“b”)</code> will show the information for the symbolic link itself. Note the difference with hard links. With hard links <code class="western">yaffs_lstat(“a”)</code> and <code class="western">yaffs_lstat(“b”)</code> would show the same results since they are EXACTLY the same thing being referenced.</p></li><li><p class="western">If we now unlink “a”. then the file is no longer linked and will no longer be accessible from “b”. Note the difference with hard links.</p></li></ol><h3 class="western">10.6 Handle-based file handling</h3><p class="western">A handle is file accessor that allows us to access the contents of a regular file. The handle identifies the file being accessed as well as a position pointer tracking where the next read or write operation will take place.</p><p class="western">A handle is identified by an integer of value 0 or greater.</p><p class="western">A handle is created by using the <code class="western">yaffs_open()</code> call and returns the handle value. If the handle could not be created then a negative value is returned and the yaffs error code is set.</p><p class="western">A handle remains valid until the handle is closed by <code class="western">yaffs_close()</code>.</p><p class="western">The <code class="western">yaffs_open()</code> call takes three parameters:</p><ul><li><p class="western">name: Full path name of the file being opened.</p></li><li><p class="western">access flags: Flags being used to open this handle</p></li><li><p class="western">creation mode: Mode flags used when creating a file.</p></li></ul><p class="western">The access flags are one or more of:</p><table cellpadding="4" cellspacing="0" width="100%"><colgroup><col width="59*"><col width="197*"></colgroup><tbody><tr valign="TOP"><td style="border-top-style: solid; border-top-color: rgb(0, 0, 0); border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: none; border-right-width: initial; border-right-color: initial; padding-top: 0.1cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0cm; " width="23%"><p class="western"><font face="Courier, monospace"><font size="2"><code class="western">O_CREAT</code></font></font></p></td><td style="border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: rgb(0, 0, 0); border-right-color: rgb(0, 0, 0); border-bottom-color: rgb(0, 0, 0); border-left-color: rgb(0, 0, 0); padding-top: 0.1cm; padding-right: 0.1cm; padding-bottom: 0.1cm; padding-left: 0.1cm; " width="77%"><p class="western">Create file if it does not already exist.</p></td></tr><tr valign="TOP"><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: none; border-right-width: initial; border-right-color: initial; padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0cm; " width="23%"><p class="western"><font face="Courier, monospace"><font size="2"><code class="western">O_EXCL</code></font></font></p></td><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: solid; border-right-color: rgb(0, 0, 0); padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0.1cm; " width="77%"><p class="western">Only use with O_CREAT. Create file if it does not exist. If the file already exists then fail.</p></td></tr><tr valign="TOP"><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: none; border-right-width: initial; border-right-color: initial; padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0cm; " width="23%"><p class="western"><font face="Courier, monospace"><font size="2"><code class="western">O_TRUNC</code></font></font></p></td><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: solid; border-right-color: rgb(0, 0, 0); padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0.1cm; " width="77%"><p class="western">If the file exists, and opening with write access, then truncate the file to zero bytes long.</p></td></tr><tr valign="TOP"><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: none; border-right-width: initial; border-right-color: initial; padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0cm; " width="23%"><p class="western">&nbsp;</p></td><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: solid; border-right-color: rgb(0, 0, 0); padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0.1cm; " width="77%"><p class="western">&nbsp;</p></td></tr><tr valign="TOP"><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: none; border-right-width: initial; border-right-color: initial; padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0cm; " width="23%"><p class="western"><font face="Courier, monospace"><font size="2"><code class="western">O_APPEND</code></font></font></p></td><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: solid; border-right-color: rgb(0, 0, 0); padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0.1cm; " width="77%"><p class="western">Regardless of the handle position, always write to the end of the file.</p></td></tr><tr valign="TOP"><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: none; border-right-width: initial; border-right-color: initial; padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0cm; " width="23%"><p class="western">&nbsp;</p></td><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: solid; border-right-color: rgb(0, 0, 0); padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0.1cm; " width="77%"><p class="western">&nbsp;</p></td></tr><tr valign="TOP"><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: none; border-right-width: initial; border-right-color: initial; padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0cm; " width="23%"><p class="western"><font face="Courier, monospace"><font size="2"><code class="western">O_RDWR</code></font></font></p></td><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: solid; border-right-color: rgb(0, 0, 0); padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0.1cm; " width="77%"><p class="western">Open for read/write access.</p></td></tr><tr valign="TOP"><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: none; border-right-width: initial; border-right-color: initial; padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0cm; " width="23%"><p class="western"><font face="Courier, monospace"><font size="2"><code class="western">O_WRONLY</code></font></font></p></td><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: solid; border-right-color: rgb(0, 0, 0); padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0.1cm; " width="77%"><p class="western">Open for write access and no read access.</p><p class="western">&nbsp;</p></td></tr><tr valign="TOP"><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: none; border-right-width: initial; border-right-color: initial; padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0cm; " width="23%"><p class="western">&nbsp;</p></td><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: solid; border-right-color: rgb(0, 0, 0); padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0.1cm; " width="77%"><p class="western">If neither O_RDWR or O_WRONLY is set then the file will be opened for read-only access.</p></td></tr></tbody></table><p class="western">Where they are not mutually exclusive, these flags are typically combined. For example:</p><p class="western"><code class="western">O_CREAT | O_TRUNC | O_RDWR</code> : Create a new file if it does not exist otherwise if the file already exists then truncate to zero length. Typically used to overwrite a file or create if it does not already exist.</p><p class="western"><code class="western">O_CREAT | OEXCL | O_WRONLY</code> : Create a new file, opening it for write only. Fails if file already exists.</p><p class="western">There are three mode flags that can be controlled or set. These flags may be set by the open that creates the file or later by the <code class="western">yaffs_chmod()</code>.</p><table cellpadding="4" cellspacing="0" width="100%"><colgroup><col width="59*"><col width="197*"></colgroup><tbody><tr valign="TOP"><td style="border-top-style: solid; border-top-color: rgb(0, 0, 0); border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: none; border-right-width: initial; border-right-color: initial; padding-top: 0.1cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0cm; " width="23%"><p class="western"><font face="Courier New, monospace"><font size="2"><code class="western">S_IREAD</code></font></font></p></td><td style="border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: rgb(0, 0, 0); border-right-color: rgb(0, 0, 0); border-bottom-color: rgb(0, 0, 0); border-left-color: rgb(0, 0, 0); padding-top: 0.1cm; padding-right: 0.1cm; padding-bottom: 0.1cm; padding-left: 0.1cm; " width="77%"><p class="western">The file may be opened for read access.</p></td></tr><tr valign="TOP"><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: none; border-right-width: initial; border-right-color: initial; padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0cm; " width="23%"><p class="western"><font face="Courier New, monospace"><font size="2"><code class="western">S_IWRITE</code></font></font></p></td><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: solid; border-right-color: rgb(0, 0, 0); padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0.1cm; " width="77%"><p class="western">The file may be opened for write access.</p></td></tr><tr valign="TOP"><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: none; border-right-width: initial; border-right-color: initial; padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0cm; " width="23%"><p class="western"><font face="Courier New, monospace"><font size="2"><code class="western">S_IEXEC</code></font></font></p></td><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: solid; border-right-color: rgb(0, 0, 0); padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0.1cm; " width="77%"><p class="western">The file may be opened for execution. This is not enforced by yaffs.</p></td></tr></tbody></table><p class="western">Once you have opened a handle you can then do various operations on the file.</p><table cellpadding="4" cellspacing="0" width="100%"><colgroup><col width="114*"><col width="142*"></colgroup><tbody><tr valign="TOP"><td style="border-top-style: solid; border-top-color: rgb(0, 0, 0); border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: none; border-right-width: initial; border-right-color: initial; padding-top: 0.1cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0cm; " width="45%"><p class="western"><font face="Courier New, monospace"><font size="2"><code class="western">yaffs_close(handle)</code></font></font></p></td><td style="border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: rgb(0, 0, 0); border-right-color: rgb(0, 0, 0); border-bottom-color: rgb(0, 0, 0); border-left-color: rgb(0, 0, 0); padding-top: 0.1cm; padding-right: 0.1cm; padding-bottom: 0.1cm; padding-left: 0.1cm; " width="55%"><p class="western">Close the handle. It is no longer usable.</p></td></tr><tr valign="TOP"><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: none; border-right-width: initial; border-right-color: initial; padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0cm; " width="45%"><p class="western"><font face="Courier New, monospace"><font size="2"><code class="western">yaffs_fsync(handle)</code></font></font></p></td><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: solid; border-right-color: rgb(0, 0, 0); padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0.1cm; " width="55%"><p class="western">Flush out any cached writes to the file, as well as the file meta-data.</p></td></tr><tr valign="TOP"><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: none; border-right-width: initial; border-right-color: initial; padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0cm; " width="45%"><p class="western"><font face="Courier New, monospace"><font size="2"><code class="western">yaffs_datasync(handle)</code></font></font></p></td><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: solid; border-right-color: rgb(0, 0, 0); padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0.1cm; " width="55%"><p class="western">Same as yaffs_fsync() but no file metadata.</p></td></tr><tr valign="TOP"><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: none; border-right-width: initial; border-right-color: initial; padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0cm; " width="45%"><p class="western"><font face="Courier New, monospace"><font size="2"><code class="western">yaffs_flush(handle)</code></font></font></p></td><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: solid; border-right-color: rgb(0, 0, 0); padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0.1cm; " width="55%"><p class="western">Same as yaffs_fsync()</p></td></tr><tr valign="TOP"><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: none; border-right-width: initial; border-right-color: initial; padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0cm; " width="45%"><p class="western"><font face="Courier New, monospace"><font size="2"><code class="western">yaffs_dup(handle)</code></font></font></p></td><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: solid; border-right-color: rgb(0, 0, 0); padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0.1cm; " width="55%"><p class="western">Duplicates a handle.</p></td></tr><tr valign="TOP"><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: none; border-right-width: initial; border-right-color: initial; padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0cm; " width="45%"><p class="western"><font face="Courier New, monospace"><font size="2"><code class="western">yaffs_lseek(handle, offset, whence)</code></font></font></p></td><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: solid; border-right-color: rgb(0, 0, 0); padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0.1cm; " width="55%"><p class="western">Set the handle read/write position. Note that this does not modify the file. You can seek past the end of the file. This does not modify the file size.</p></td></tr><tr valign="TOP"><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: none; border-right-width: initial; border-right-color: initial; padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0cm; " width="45%"><p class="western"><font face="Courier New, monospace"><font size="2"><code class="western">yaffs_ftruncate(handle, size)</code></font></font></p></td><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: solid; border-right-color: rgb(0, 0, 0); padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0.1cm; " width="55%"><p class="western">Change the file size. It can be made bigger or smaller. This does not change the handle read/write position.</p></td></tr><tr valign="TOP"><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: none; border-right-width: initial; border-right-color: initial; padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0cm; " width="45%"><p class="western"><font face="Courier New, monospace"><font size="2"><code class="western">yaffs_fstat(handle, buf)</code></font></font></p></td><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: solid; border-right-color: rgb(0, 0, 0); padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0.1cm; " width="55%"><p class="western">Get file status.</p></td></tr><tr valign="TOP"><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: none; border-right-width: initial; border-right-color: initial; padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0cm; " width="45%"><p class="western"><font face="Courier New, monospace"><font size="2"><code class="western">yaffs_fchmod(handle, mode)</code></font></font></p></td><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: solid; border-right-color: rgb(0, 0, 0); padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0.1cm; " width="55%"><p class="western">Change the file mose.</p></td></tr><tr valign="TOP"><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: none; border-right-width: initial; border-right-color: initial; padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0cm; " width="45%"><p class="western">&nbsp;</p></td><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: solid; border-right-color: rgb(0, 0, 0); padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0.1cm; " width="55%"><p class="western">&nbsp;</p></td></tr><tr valign="TOP"><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: none; border-right-width: initial; border-right-color: initial; padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0cm; " width="45%"><p class="western"><font face="Courier New, monospace"><font size="2"><code class="western">yaffs_read(handle, buffer, nbytes)</code></font></font></p></td><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: solid; border-right-color: rgb(0, 0, 0); padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0.1cm; " width="55%"><p class="western">Read data from file at file pointer and update pointer.</p></td></tr><tr valign="TOP"><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: none; border-right-width: initial; border-right-color: initial; padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0cm; " width="45%"><p class="western"><font face="Courier New, monospace"><font size="2"><code class="western">yaffs_pread(handle, buffer, nbytes, position)</code></font></font></p></td><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: solid; border-right-color: rgb(0, 0, 0); padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0.1cm; " width="55%"><p class="western">Read data from file at specified position. Does not modify file pointer</p></td></tr><tr valign="TOP"><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: none; border-right-width: initial; border-right-color: initial; padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0cm; " width="45%"><p class="western"><font face="Courier New, monospace"><font size="2"><code class="western">yaffs_write(handle, buffer, nbytes)</code></font></font></p></td><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: solid; border-right-color: rgb(0, 0, 0); padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0.1cm; " width="55%"><p class="western">Write data to file at file pointer and update pointer.</p></td></tr><tr valign="TOP"><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: none; border-right-width: initial; border-right-color: initial; padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0cm; " width="45%"><p class="western"><font face="Courier New, monospace"><font size="2"><code class="western">yaffs_pread(handle, buffer, nbytes, position)</code></font></font></p></td><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: solid; border-right-color: rgb(0, 0, 0); padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0.1cm; " width="55%"><p class="western">Write data to file at specified position. Does not modify file pointer</p></td></tr></tbody></table><h3 class="western">10.7 Changing file size</h3><p class="code-western"><code class="western">yaffs_truncate(path, newSize)</code></p><p class="code-western"><code class="western">yaffs_ftruncate(handle, newSize)</code></p><p class="western">These change a file's size. Note that truncating does not just mean make the file smaller. The file can also be made larger.</p><p class="western">Yaffs does not store bytes that it does not need to. If you use truncate to make a file larger then this will not necessarily occupt more flash space.</p><p class="western">See also <code class="western">yaffs_lseek()</code> too. Note that <code class="western">yaffs_lseek() </code>only changes the position of the write pointer and does not impact on the file size unless the file is written.</p><h3 class="western">10.8 Getting/setting information about files</h3><p class="code-western"><code class="western">yaffs_chmod(path, mode)</code></p><p class="code-western"><code class="western">yaffs_fchmod(handle, mode)</code></p><p class="code-western">&nbsp;</p><p class="code-western"><code class="western">yaffs_access(path,amode)</code></p><p class="code-western">&nbsp;</p><p class="code-western"><code class="western">yaffs_stat(path, struct yaffs_stat *buf) </code></p><p class="code-western"><code class="western">yaffs_fstat(handle, struct yaffs_stat *buf)</code></p><p class="code-western"><code class="western">yaffs_lstat(path, struct yaffs_stat *buf)</code></p><p class="code-western"><code class="western">yaffs_readlink(path, buf, bufsize)</code></p><p class="western">The chmod calls allow you to set different mode flags for the file. These can only be used to manipulate the permissions flags and not change the mode flags relating to the type of file.</p><p class="western"><code class="western">yaffs_access() </code>tests that the file can be accessed in the specified mode. This call returns zero on success and -1 is returned</p><p class="western">amode is a bitmask of the following values:</p><table cellpadding="4" cellspacing="0" width="100%"><colgroup><col width="43*"><col width="213*"></colgroup><tbody><tr valign="TOP"><td style="border-top-style: solid; border-top-color: rgb(0, 0, 0); border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: none; border-right-width: initial; border-right-color: initial; padding-top: 0.1cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0cm; " width="17%"><p class="western"><font face="Courier New, monospace"><font size="2"><code class="western">R_OK</code></font></font></p></td><td style="border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: rgb(0, 0, 0); border-right-color: rgb(0, 0, 0); border-bottom-color: rgb(0, 0, 0); border-left-color: rgb(0, 0, 0); padding-top: 0.1cm; padding-right: 0.1cm; padding-bottom: 0.1cm; padding-left: 0.1cm; " width="83%"><p class="western">Check read is OK</p></td></tr><tr valign="TOP"><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: none; border-right-width: initial; border-right-color: initial; padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0cm; " width="17%"><p class="western"><font face="Courier New, monospace"><font size="2"><code class="western">W_OK</code></font></font></p></td><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: solid; border-right-color: rgb(0, 0, 0); padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0.1cm; " width="83%"><p class="western">Check write is OK</p></td></tr><tr valign="TOP"><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: none; border-right-width: initial; border-right-color: initial; padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0cm; " width="17%"><p class="western"><font face="Courier New, monospace"><font size="2"><code class="western">X_OK</code></font></font></p></td><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: solid; border-right-color: rgb(0, 0, 0); padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0.1cm; " width="83%"><p class="western">Check execute is OK.</p></td></tr><tr valign="TOP"><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: none; border-right-width: initial; border-right-color: initial; padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0cm; " width="17%"><p class="western"><font face="Courier New, monospace"><font size="2"><code class="western">0 (zero)</code></font></font></p></td><td style="border-top-style: none; border-top-width: initial; border-top-color: initial; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); border-left-style: solid; border-left-color: rgb(0, 0, 0); border-right-style: solid; border-right-color: rgb(0, 0, 0); padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0.1cm; " width="83%"><p class="western">Just checks the file exists</p></td></tr></tbody></table><p class="western">These can be combined.</p><p class="western">For example:</p><p class="code-western"><code class="western">if(yaffs_access(path, R_OK | W_OK) == 0)</code></p><p class="code-western"><code class="western">the file exists and can be read and written</code></p><p class="code-western"><code class="western">if(yaffs_access(path, 0) == 0)</code></p><p class="code-western"><code class="western">the file exists</code></p><p class="western"><br>&nbsp;</p><p class="western">The stat calls retrieve a yaffs_stat structure of data which is defined in yaffsfs.h. There are three versions:</p><p class="western"><code class="western">yaffs_fstat</code>: Takes a handle.</p><p class="western"><code class="western">yaffs_stat</code>: Takes a path name and follows symbolic links.</p><p class="western"><code class="western">yaffs_lstat</code>: Takes a path but does not follow symbolic links.</p><p class="western"><br>&nbsp;</p><p class="western">Thus, if path is a symbolic link, <code class="western">yaffs_fstat() </code>will give information on the file that the link points to while <code class="western">yaffs_lstat()</code> will give information about the link itself.</p><p class="western"><code class="western">yaffs_readlink()</code> will read the read the link value into the buffer provided. For example:</p><p class="code-western"><code class="western">yaffs_symlink(“target”,”/link”); /* create a link called link to target */</code></p><p class="code-western"><code class="western">yaffs_readlink(“/link”,buffer,10); /* now buffer contains “target” */</code></p><h3 class="western">10.9 Changing the directory structure and names</h3><p class="code-western"><code class="western">yaffs_open(path, flags, mode)</code></p><p class="code-western"><code class="western">yaffs_mkdir(path, mode)</code></p><p class="code-western"><code class="western">yaffs_symlink(targetPath, linkPath)</code></p><p class="code-western"><code class="western">yaffs_mknod(pathname, mode, dev)</code></p><p class="code-western">&nbsp;</p><p class="code-western"><code class="western">yaffs_link(existingPath, newath)</code></p><p class="code-western">&nbsp;</p><p class="code-western"><code class="western">yaffs_unlink(path)</code></p><p class="code-western"><code class="western">yaffs_rmdir(path)</code></p><p class="code-western">&nbsp;</p><p class="code-western"><code class="western">yaffs_rename(oldPath, newPath)</code></p><p class="western"><br>&nbsp;</p><p class="western">Files of various types, and their first link, are created via the <code class="western">yaffs_open()</code><code class="western"><font face="Liberation Serif, serif">,</font></code><font face="Courier New, monospace"><font size="2"> </font></font><code class="western">yaffs_mkdir()</code><font face="Liberation Serif, serif"><font size="2">, </font></font><code class="western">yaffs_symlink()</code> and <code class="western">yaffs_mknod()</code><font face="Liberation Serif, serif"> </font>functions.</p><p class="western"><code class="western">yaffs_link()</code> can be used to create subsequent links to files. Note that you cannot create a link to a directory.</p><p class="western"><code class="western">yaffs_rename()</code> allows you to rename a link. Note that renaming one link over another link is an atomic operation. That means that even if the operation is interrupted by a power failure, the result will either complete or not happen at all. If the target link is for a directory, then the rename will only work if the target directory is empty.</p><h3 class="western">10.10 Searching directories</h3><p class="code-western"><code class="western">yaffs_DIR *yaffs_opendir(const YCHAR *dirname) ; </code></p><p class="code-western"><code class="western">struct yaffs_dirent *yaffs_readdir(yaffs_DIR *dirp) ; </code></p><p class="code-western"><code class="western">void yaffs_rewinddir(yaffs_DIR *dirp) ; </code></p><p class="code-western"><code class="western">int yaffs_closedir(yaffs_DIR *dirp) ;</code></p><p class="western">Searching is performed by the following sequence of operations:</p><ul><li><p class="western">Open the directory for reading with <code class="western">yaffs_opendir()</code>.</p></li><li><p class="western">Iterate through the entries in the directory using <code class="western">yaffs_readdir()</code>. Each read will advance the directory read position.</p></li><li><p class="western">You can reset to the start of the directory with <code class="western">yaffs_rewinddir()</code>.</p></li><li><p class="western">Close the directory when finished with <code class="western">yaffs_closedir()</code>.</p></li></ul><h3 class="western">10.11 Mount control</h3><p class="code-western"><code class="western">yaffs_mount(path) ; </code></p><p class="code-western"><code class="western">yaffs_mount2(path, readOnly); </code></p><p class="code-western"><code class="western">yaffs_unmount(path);</code></p><p class="code-western"><code class="western">yaffs_unmount2(path, int force); </code></p><p class="code-western"><code class="western">yaffs_remount(path, force, readOnly);</code></p><p class="code-western"><code class="western">yaffs_sync(path) ;</code></p><p class="western">A partition must be mounted to be accessed. <code class="western">yaffs_mount()</code> will mount the partition for read/write access. <code class="western">yaffs_mount2()</code> can be used to control whether the access is read/write or read only.</p><p class="western">A partition can be unmounted to remove it from use. <code class="western">yaffs_unmount()</code> will fail if any files are in use whereas <code class="western">yaffs_unmount2()</code> allows you to force the unmount even if files are open.</p><p class="western"><code class="western">yaffs_remount()</code> can be used to change the access to a currently mounted partition and is equivalent to making an <code class="western">unmount2()</code> call followed by a <code class="western">mount2()</code> call.</p><p class="western"><code class="western">yaffs_sync()</code> does not change the mount status but flushes out any pending data on a partition that is mounted with write access.</p><h3 class="western">10.12 Other</h3><p class="code-western"><code class="western">yaffs_freespace(path); </code></p><p class="code-western"><code class="western">yaffs_totalspace(path); </code></p><p class="code-western"><code class="western">yaffs_inodecount(path);</code></p><p class="western">These functions provide information on the free and total space (in bytes) for the mount that the path addresses.</p><p class="western"><code class="western">yaffs_inodecount()</code> returns the number of files on the mount that the path addresses.</p><h3 class="western">11 Example: yaffs_readdir() and yaffs_stat()</h3><p class="western">This code snippet illustrates using <code class="western">yaffs_readdir()</code> and associated functions to iterate through a directory. It also shows how to use <code class="western">yaffs_lstat() </code>to get information on a file and interpret it.</p><p class="code-western"><code class="western"><font size="2" style="font-size: 10pt">void dump_directory(const char *dname) </font></code></p><p class="code-western"><code class="western"><font size="2" style="font-size: 10pt">{ </font></code></p><p class="code-western"><code class="western"><font size="2" style="font-size: 10pt">yaffs_DIR *d; </font></code></p><p class="code-western"><code class="western"><font size="2" style="font-size: 10pt">yaffs_dirent *de; </font></code></p><p class="code-western"><code class="western"><font size="2" style="font-size: 10pt">struct yaffs_stat s; </font></code></p><p class="code-western"><code class="western"><font size="2" style="font-size: 10pt">char str[100]; </font></code></p><p class="code-western">&nbsp;</p><p class="code-western"><code class="western"><font size="2" style="font-size: 10pt">d = yaffs_opendir(dname); </font></code></p><p class="code-western">&nbsp;</p><p class="code-western"><code class="western"><font size="2" style="font-size: 10pt">if(!d) </font></code></p><p class="code-western"><code class="western"><font size="2" style="font-size: 10pt">{ </font></code></p><p class="code-western"><code class="western"><font size="2" style="font-size: 10pt">printf("opendir failed\n"); </font></code></p><p class="code-western"><code class="western"><font size="2" style="font-size: 10pt">} </font></code></p><p class="code-western"><code class="western"><font size="2" style="font-size: 10pt">else </font></code></p><p class="code-western"><code class="western"><font size="2" style="font-size: 10pt">{ </font></code></p><p class="code-western"><code class="western"><font size="2" style="font-size: 10pt">while((de = yaffs_readdir(d)) != NULL) </font></code></p><p class="code-western"><code class="western"><font size="2" style="font-size: 10pt">{ </font></code></p><p class="code-western"><code class="western"><font size="2" style="font-size: 10pt">sprintf(str,"%s/%s",dname,de-&gt;d_name); </font></code></p><p class="code-western">&nbsp;</p><p class="code-western"><code class="western"><font size="2" style="font-size: 10pt">yaffs_lstat(str,&amp;s); </font></code></p><p class="code-western">&nbsp;</p><p class="code-western"><code class="western"><font size="2" style="font-size: 10pt">printf("%s inode %d length %d mode %X ",</font></code></p><p class="code-western"><code class="western"><font size="2" style="font-size: 10pt">str,s.st_ino,(int)s.st_size,s.st_mode); </font></code></p><p class="code-western"><code class="western"><font size="2" style="font-size: 10pt">switch(s.st_mode &amp; S_IFMT) </font></code></p><p class="code-western"><code class="western"><font size="2" style="font-size: 10pt">{ </font></code></p><p class="code-western"><code class="western"><font size="2" style="font-size: 10pt">case S_IFREG: printf("data file"); break; </font></code></p><p class="code-western"><code class="western"><font size="2" style="font-size: 10pt">case S_IFDIR: printf("directory"); break; </font></code></p><p class="code-western"><code class="western"><font size="2" style="font-size: 10pt">case S_IFLNK: printf("symlink --&gt;"); </font></code></p><p class="code-western"><code class="western"><font size="2" style="font-size: 10pt">if(yaffs_readlink(str,str,100) &lt; 0) </font></code></p><p class="code-western"><code class="western"><font size="2" style="font-size: 10pt">printf("no alias"); </font></code></p><p class="code-western"><code class="western"><font size="2" style="font-size: 10pt">else </font></code></p><p class="code-western"><code class="western"><font size="2" style="font-size: 10pt">printf("\"%s\"",str);</font></code></p><p class="code-western"><code class="western"><font size="2" style="font-size: 10pt">break; </font></code></p><p class="code-western"><code class="western"><font size="2" style="font-size: 10pt">default: printf("unknown"); break; </font></code></p><p class="code-western"><code class="western"><font size="2" style="font-size: 10pt">} </font></code></p><p class="code-western"><code class="western"><font size="2" style="font-size: 10pt">printf("\n"); </font></code></p><p class="code-western">&nbsp;</p><p class="code-western"><code class="western"><font size="2" style="font-size: 10pt">if((s.st_mode &amp; S_IFMT) == S_IFDIR) </font></code></p><p class="code-western"><code class="western"><font size="2" style="font-size: 10pt">dump_directory_tree_worker(str); </font></code></p><p class="code-western"><code class="western"><font size="2" style="font-size: 10pt">} </font></code></p><p class="code-western">&nbsp;</p><p class="code-western"><code class="western"><font size="2" style="font-size: 10pt">yaffs_closedir(d); </font></code></p><p class="code-western"><code class="western"><font size="2" style="font-size: 10pt">} </font></code></p><p class="code-western"><code class="western"><font size="2" style="font-size: 10pt">}&nbsp;</font></code></p><p>&nbsp;</p>