<h1>How to control debugging in yaffs</h1>

<p>YAFFS provides a debugging mechanism which can be controlled at runtime if you have access to /proc, normally via a shell. If you need to trace things before you get to a shell, then you can set default trace options at compile time.</p>

<h2>Available Trace Flags</h2>
<table>
 <tr>
  <th>name</th><th>C #define</th><th>bitmask value</th>
 </tr>
 <tr>
  <td>error </td>       <td>YAFFS_TRACE_ERROR </td>           <td>0x00000001</td>
 </tr>
 <tr>
  <td>os </td>          <td>YAFFS_TRACE_OS </td>              <td>0x00000002</td>
 </tr>
 <tr>
  <td>allocate </td>    <td>YAFFS_TRACE_ALLOCATE </td>        <td>0x00000004</td>
 </tr>
 <tr>
  <td>scan </td>        <td>YAFFS_TRACE_SCAN </td>            <td>0x00000008</td>
 </tr>
 <tr>
  <td>bad_blocks </td>  <td>YAFFS_TRACE_BAD_BLOCKS </td>      <td>0x00000010</td>                                                     
 </tr>
 <tr>
  <td>erase </td>       <td>YAFFS_TRACE_ERASE </td>           <td>0x00000020</td>                                                      
 </tr>
 <tr>
  <td>gc </td>          <td>YAFFS_TRACE_GC </td>              <td>0x00000040</td>                                                      
 </tr>
 <tr>
  <td>write </td>       <td>YAFFS_TRACE_WRITE </td>           <td>0x00000080</td>                                                      
 </tr>
 <tr>
  <td>tracing </td>     <td>YAFFS_TRACE_TRACING </td>         <td>0x00000100</td>                                                      
 </tr>
 <tr>
  <td>deletion </td>    <td>YAFFS_TRACE_DELETION </td>        <td>0x00000200</td>                                                      
 </tr>
 <tr>
  <td>buffers </td>     <td>YAFFS_TRACE_BUFFERS </td>         <td>0x00000400</td>                                                      
 </tr>
 <tr>
  <td>nandaccess </td>  <td>YAFFS_TRACE_NANDACCESS </td>      <td>0x00000800</td>                                                      
 </tr>
 <tr>
  <td>gc_detail </td>   <td>YAFFS_TRACE_GC_DETAIL </td>       <td>0x00001000</td>                                                      
 </tr>
 <tr>
  <td>scan_debug </td>  <td>YAFFS_TRACE_SCAN_DEBUG </td>      <td>0x00002000</td>                                                      
 </tr>
 <tr>
  <td>mtd </td>         <td>YAFFS_TRACE_MTD </td>             <td>0x00004000</td>                                                      
 </tr>
 <tr>
  <td>always </td>      <td>YAFFS_TRACE_ALWAYS </td>          <td>0x40000000</td>                                                      
 </tr>
 <tr>
  <td>bug </td>         <td>YAFFS_TRACE_BUG </td>             <td>0x80000000</td>
 </tr>
</table>

<h2>Flag meanings</h2>
<p>The flags cover possible debugging messages from various aspects of the filesystem - initial scanning, mtd interface, writing, nand access, garbage collection, OS interaction etc. Turning on everything results an awful lot of trace info, so it is usually best to just enable a few relevant flags.</p>

<h2>Setting flags at runtime</h2>
<p>The flags can be set or cleared by echoing the name of the flag into /proc/yaffs with a '+' or '-':<br />                                                                                                                                                                         
  <tt>echo +os-write &gt; /proc/yaffs</tt></p>
                                                                                                                                             <p>It can be set to to all or none using '=', and then flags can be added or removed:<br />
  <tt>echo =none+os+write &gt; /proc/yaffs</tt></p>

<p>And you can use numerical values, if you are so inclined (using standard C format):<br />
  <tt>echo 0xf00001 &gt; /proc/yaffs</tt></p>
                                                                                                                                          <p>So<br />
  <tt>echo all &gt; /proc/yaffs</tt><br />
will turn all tracing on</p>

<p><b>Note</b> that you only see the output showing you the current trace state if the 'always' (YAFFS_TRACE_ALWAYS) flag is set, so to see what you are doing do this:<br />
  <tt>echo +always &gt; /proc/yaffs</tt></p>                                                                                                                                                                                   

<h2>Setting flags at compile time</h2>

<p>Flags can be set in the code at compile-time by setting <tt>yaffs_traceMask</tt> in <tt>yaffs_fs.c</tt> (add new flags to <tt>always</tt> and <tt>bad_blocks</tt> which are set by default)</p>