1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> 4<LINK rel="stylesheet" type="text/css" href="../CSS/revolution.css"> 5<base target="main"> 6<title>NAND Function Introduction</title> 7</head> 8 9<body> 10 11<h1>NAND Function Introduction</h1> 12 13<h2>Introduction</h2> 14<p> 15The NAND library provides functions to access the NAND flash memory built into the Wii console. NAND flash memory has the following characteristics: 16<ul> 17<li>Nonvolatile memory 18<li>Fast read, but slightly slow write 19<li>Random access 20<li>Concept of bit error 21<li>Concept of bad blocks 22<li>Concept of wear and tear because of writing 23</ul> 24</p> 25 26<p> 27The NAND memory capacity of the Wii console is 512 MB. However, not all of the 512 MB space can be used by the application program, as some of the space will be taken by the system files written at the factory or for permanently reserved system needs. 28</p> 29 30<p> 31The NAND library provides a file system with the following characteristics. 32<ul> 33<li>Similar architecture to UNIX file systems. 34<li>Hierarchical file system. 35<li>Access control with three permission levels (Owner/Group/Other). (Group is a permission that corresponds to a company. It can be used when you want to allow access for titles from the same company.) 36<li>Single-bit error correction is done in the file system. 37<li>Bad block processing is done in the file system. 38<li>Ability of the file system to withstand sudden power shutdown. (The entire file system will not be damaged even if power is shut down while writing data or updating the FAT.) 39<li>Up to twelve characters for the file name/directory name. 40<li>Supports both absolute path specification and relative path specification. 41<li>The path delimiter text character is "<CODE>/</CODE>". 42<li>The maximum path length is 64 characters (including the NULL character). 43<li>A directory structure up to eight levels deep can be created. 44<li>The size of the file system block (FS block) is 16 KB. (In other words, even a 1-byte file takes a region of 16 KB.) 45<li>Maximum number of files/directories to be created is approximately 6000. 46</ul> 47</p> 48 49<p> 50We have prepared sample demo programs that demonstrate how to use the NAND library under the path <code>$REVOLUTION_SDK_ROOT/build/demos/nanddemo/</code>. Function declarations are in the <code>$REVOLUTION_SDK_ROOT/include/revolution/nand.h</code> header file. 51</p> 52 53 54<h2>Banners</h2> 55<p> 56You must create a banner file in order to create an application save file in the Wii console NAND memory. In the Wii Menu, home directories without a banner file are deleted. <font color=#ff0000>If creating multiple files that include a banner file, be sure to create the banner file last. </font>If the banner file is created first, and then an accident such as a power interruption occurs, the home directory would have a banner file, but some of the save files might not be there. This could confuse players because it would appear from the save data screen in the Wii Menu that the application had no problem creating the save files, when in fact there was a problem. See the <I>Guidelines For Creating Wii Save Data</I> for details.<br> 57</p> 58<p> 59The structure <a href="./NANDBanner.html"><CODE>NANDBanner</CODE></a> and functions <a href="./NANDInitBanner.html"><CODE>NANDInitBanner</CODE></a>, <a href="./NANDGetIconSpeed.html"><CODE>NANDGetIconSpeed</CODE></a> and <a href="./NANDSetIconSpeed.html"><CODE>NANDSetIconSpeed</CODE></a> have been prepared to simplify the process of creating banners. Also, reference the banner sample demo program. 60</p> 61 62<h2>Function which determines whether the file/directory can be newly created</h2> 63<p> 64As mentioned before, the Wii console NAND memory has the capacity of 512MB, but not all can be used by the application program. The memory will include system programs such as system feature applications, reserve area for bad blocks, and free space reserved for system use. Do not conclude whether a new file/directory can be created solely based on free space in the file system (Use of <CODE>NANDFreeBlocks[Async]</CODE> is not recommended).<br>When the application attempts to create files/directories in the home directory, based on the responses from the functions below, determine whether to go ahead and create the new files/directories or to perform some process such as displaying a message indicating insufficient memory space. 65</p> 66 67<h3>NANDCheck[Async]</h3> 68<p> 69<a href="./NANDCheck.html"><CODE>NANDCheck</CODE></a> and <a href="./NANDCheckAsync.html"><CODE>NANDCheckAsync</CODE></a> function "reports" the number of file system blocks and inodes that the application is about to consume. If the application is creating a new file/directory under the home directory, call the <a href="./NANDCheck.html"><CODE>NANDCheck</CODE></a> or the <a href="./NANDCheckAsync.html"><CODE>NANDCheckAsync</CODE></a> function first. The total number of file system blocks and inodes for the file/directory that the application will create is passed to the <a href="./NANDCheck.html"><CODE>NANDCheck</CODE></a> and the <a href="./NANDCheckAsync.html"><CODE>NANDCheckAsync</CODE></a> functions. The system will calculate whether a sufficient space to fulfill the request is available in the file system, and gives the verdict to the application program. 70</p> 71 72<h3>Determining whether multiple files/directories can be created</h3> 73<p> 74If the application requires multiple files/directories, sum the total number of file system blocks and i-nodes consumed by each, and then branch to either Create file/directory group or Create no files/directories, based on the result from a call to <CODE>NANDCheck[Async]()</CODE>. Do not call <CODE>NANDCheck[Async]</CODE> for each file/directory to be created. If you call <CODE>NANDCheck[Async]()</CODE> multiple times to create multiple files/directories, you may not be able to create all of the required files/directories, depending on the available space in Wii console NAND memory. 75</p> 76 77<dl><dd><pre><code> 78// Correct sequence (pseudo-code) 79NANDCheck(FileA+FileB+FileC); // Check A & B & C at once. 80if(success){ 81createFileA(); 82createFileB(); 83createFileC(); 84} 85</code></pre></dd></dl> 86 87<dl><dd><pre><code> 88// Incorrect sequence (pseudo-code) 89NANDCheck(FileA); // Check A 90if(success){ 91createFileA(); 92} 93 94NANDCheck(FileB); // Check B 95if(success){ 96createFileB(); 97} 98 99NANDCheck(FileC) // Check C 100if(success){ 101createFileC() 102} 103</code></pre></dd></dl> 104 105<p> 106The number of file system blocks (FS blocks) consumed by a given file is rounded up to be an integer value of the file size divided by 16 KB. Thus, an 8 KB file consumes one FS block, and a 40 KB consumes three FS blocks. Accordingly, if an application needs to create two files, one 8 KB and one 40 KB, that file group consumes four KS blocks (1 + 3 = 4). Do not calculate this as (40+8)/16 = 3 and call <CODE>NANDCheck[Async]()</CODE> with the assumption that three FS blocks will be consumed. 107</p> 108 109<h2>Function that obtains available space for an application</h2> 110<p> 111The <a href="./NANDCheck.html"><CODE>NANDCheck</CODE></a> and the <a href="./NANDCheckAsync.html"><CODE>NANDCheckAsync</CODE></a> functions determine whether files/directories can be created, but they are not suited to determine exactly how much free space is available. If you want to inform the player how much free space is available for the application to use in Wii console NAND memory, use the <a href="./NANDGetAvailableArea.html"><CODE>NANDGetAvailableArea</CODE></a> or the <a href="./NANDGetAvailableAreaAsync.html"><CODE>NANDGetAvailableAreaAsync</CODE></a> function. These functions obtain the number of file system blocks and inodes that the application can consume. 112</p> 113 114<h2>Process Flow</h2> 115<p> 116First, call <a href="./NANDInit.html"><CODE>NANDInit</CODE></a> function to initialize the NAND library before using NAND functions (<B>Note:</B> Starting with RevolutionSDK2.1, the NANDInit function is automatically called from the system). If the application is creating a new file/directory apart from <CODE>/tmp</CODE>, first call <a href="./NANDCheck.html"><CODE>NANDCheck</CODE></a> or <a href="./NANDCheckAsync.html"><CODE>NANDCheckAsync</CODE></a> to verify that the file system has sufficient free space and i-nodes for the application program before calling <a href="./NANDCreate.html"><CODE>NANDCreate</CODE></a> functions. 117</p> 118<p> 119Refer to <a href="./sequence.html">NAND Processing Sequence</a> for an example of process flow including the error processing. 120</p> 121 122<h2>Directory Structure</h2> 123<p> 124Although a number of directories are available for the file system in the Wii console NAND memory, the application programmer should be aware of the following: 125<table border="1"> 126 <tbody> 127 <tr> 128<td bgcolor="#C0C0C0">Path</td> 129<td bgcolor="#C0C0C0">Description</td> 130 </tr> 131 <tr> 132<td>/title/<title-id(Hi)>/<title-id(Low)>/data</td> 133<td>This is the application home directory. The home directory is provided automatically by the system. Save application save data and others in this directory.</td> 134 </tr> 135 <tr> 136<td>/tmp</td> 137<td>Temporary directory. Files and directories stored under this directory are deleted when the system starts up.</td> 138 </tr> 139 <tr> 140<td>/tmp/sys</td> 141<td>This directory is reserved for use by the system as a temporary directory. Avoid having application programs access this directory directly. Doing so can lead to system instability.</td> 142 </tr> 143 </tbody> 144</table> 145</p> 146 147<h2>Application Save Data</h2> 148<p> 149Use the NAND library to save application data. For programmers, the NAND flash memory is simpler to use than the CARD library, as it is built into the Revolution console. Refer to the gamesave sample demo program for more information on saving data. 150</p> 151<p> 152When the NAND library is initialized, the current directory is automatically set as the home directory. This directory is hardwired in software in the development device environment and is common to all applications. However, a unique home directory is provided for each application on the production units. 153</p> 154 155<h2>Synchronous and Asynchronous Functions</h2> 156<p> 157Certain NAND functions provide both synchronous and asynchronous access to the Wii console NAND memory.<br>Synchronous functions block the current thread until the process completes and control is transferred to other executable threads. Asynchronous functions return immediately. If a request starts normally, a callback function is called at the completion of the process, and a result code and a command block are passed. The callback function and the command block are specified when the asynchronous function is called. If the asynchronous function call ends in an error (that is, if the result code is other than a normal exit), the specified callback function will not be called. Asynchronous functions contain the suffix <B><CODE>Async</CODE></B>. 158</p> 159 160<h2>inode</h2> 161<p> 162File management is done through inodes in the NAND library file system. To create a new file or a directory, one available inode is required for each file/directory. The number of available inodes can be checked using the <a href="./NANDFreeBlocks.html"><CODE>NANDFreeBlocks</CODE></a> function or the <a href="./NANDFreeBlocksAsync.html"><CODE>NANDFreeBlocksAsync</CODE></a> function.<br>However, the values obtained by these functions are the available inode counts for the entire file system. In actuality, there are free inodes which needs to be always reserved for the system, so please do not determine whether a new file/directory can be created solely based on the value obtained by these functions. When creating a new file/directory apart from /tmp, please follow the result of <a href="./NANDCheck.html"><CODE>NANDCheck</CODE></a> and <a href="./NANDCheckAsync.html"><CODE>NANDCheckAsync</CODE></a> functions. 163</p> 164 165<h2>Result Code List</h2> 166<table> 167 <tbody> 168 <tr> 169<td bgcolor="#C0C0C0">Return Values</td> 170<td bgcolor="#C0C0C0">Description</td> 171 </tr> 172 <tr> 173<td>NAND_RESULT_OK</td> 174<td>Function completes successfully.</td> 175 </tr> 176 <tr> 177<td>NAND_RESULT_ACCESS</td> 178<td>The are no permission/access privileges for accessing files or directories.</td> 179 </tr> 180 <tr> 181<td>NAND_RESULT_ALLOC_FAILED</td> 182<td>The library failed internally to secure the memory needed for receiving a large volume of requests at one time. However, if you wait some time and call the NAND function again, the process might succeed.</td> 183 </tr> 184 <tr> 185<td>NAND_RESULT_AUTHENTICATION</td> 186<td>Data authentication failed. Data may have been destroyed due to a hardware problem, or data in the Wii console NAND memory may have been falsified in some illegal manner.</td> 187 </tr> 188 <tr> 189<td>NAND_RESULT_BUSY</td> 190<td>Busy state (the queue holding requests is full). If you wait some time and call the NAND function again, the process might succeed.</td> 191 </tr> 192 <tr> 193<td>NAND_RESULT_CORRUPT</td> 194<td>Wear in the FAT region has caused irreparable damage to Wii console NAND memory.</td> 195 </tr> 196 <tr> 197<td>NAND_RESULT_ECC_CRIT</td> 198<td>Indicates that a fatal ECC error has been detected (that is, data error correction is not possible). This code might be returned when the Wii console NAND memory is severely worn because the number of write/delete cycles has exceeded the device guaranteed performance.</td> 199 </tr> 200 <tr> 201<td>NAND_RESULT_EXISTS</td> 202<td>File or directory with the same name already exists.</td> 203 </tr> 204 <tr> 205<td>NAND_RESULT_INVALID</td> 206<td>Input parameter or the function call is invalid. This code is returned when an incorrect argument is passed to a NAND function, an attempt is made to close a file twice, or an attempt is made to use NANDSimpleSafe[Close] to close a file that was opened by NANDOpen[Async] (or visa-versa).</td> 207 </tr> 208 <tr> 209<td>NAND_RESULT_MAXBLOCKS</td> 210<td>All of the FS blocks in the file system have been used, so there is no free space. This code is also returned when, due to device wear, the number of bad blocks has reached the upper limit.</td> 211 </tr> 212 <tr> 213<td>NAND_RESULT_MAXDEPTH</td> 214<td>A directory structure deeper than this cannot be created (8 levels maximum).</td> 215 </tr> 216 <tr> 217<td>NAND_RESULT_MAXFD</td> 218<td>No more files can be opened because all of the file descriptor entries have been used. Reduce the number of files you open at one time.</td> 219 </tr> 220 <tr> 221<td>NAND_RESULT_MAXFILES</td> 222<td>No more files/directories can be created as the file system's inodes are used up.</td> 223 </tr> 224 <tr> 225<td>NAND_RESULT_NOEXISTS</td> 226<td>The specified file or directory does not exist.</td> 227 </tr> 228 <tr> 229<td><S>NAND_RESULT_NOTEMPTY</S></td> 230<td><S>File is not empty.</S></td> 231 </tr> 232 <tr> 233<td>NAND_RESULT_OPENFD</td> 234<td>The file descriptor has been left open. This code is returned when an attempt is made to delete a file that has not yet been closed. (The NANDSafeClose[Async] function may potentially return this code to execute a Delete operation internal to the function.)</td> 235 </tr> 236 <tr> 237<td>NAND_RESULT_UNKNOWN</td> 238<td>Unknown error. When this code is returned, there is a high probability that there is some problem with the SDK. If possible, report the issue to Nintendo.</td> 239 </tr> 240 <tr> 241<td>NAND_RESULT_FATAL_ERROR</td> 242<td>The error code for program-design flaws (for example, the library is not initialized, etc.).</td> 243 </tr> 244 </tbody> 245</table> 246 247<p> 248Of these, the following are result codes that might be returned by asynchronous function calls. Also, with the exception of certain asynchronous functions (<a href="./NANDSafeOpenAsync.html"><CODE>NANDSafeOpenAsync</CODE></a>, <a href="./NANDSafeCloseAsync.html"><CODE>NANDSafeCloseAsync</CODE></a>), the specified callback function will not receive <CODE>NAND_RESULT_ALLOC_FAILED or NAND_RESULT_BUSY</CODE>. 249<ul> 250<CODE> 251<li>NAND_RESULT_OK 252<li>NAND_RESULT_ACCESS 253<li>NAND_RESULT_ALLOC_FAILED 254<li>NAND_RESULT_BUSY 255<li>NAND_RESULT_INVALID 256<li>NAND_RESULT_FATAL_ERROR</CODE> 257</ul> 258</p> 259 260<p> 261<font color=#ff000000>Starting from SDK Version 2.3 (firmware Version 12.0.2), most synchronous NAND functions can return <CODE>NAND_RESULT_ALLOC_FAILED</CODE> and <CODE>NAND_RESULT_BUSY</CODE>. These result codes may be returned when a synchronous NAND API is called while the queue for receiving requests is full (for example, due to a succession of calls to asynchronous NAND functions over a short period of time).</font> 262</p> 263 264<h2>Result Code Handling</h2> 265<p> 266The following table indicates the guidelines for handling result codes. Also refer to the <a href="./sequence.html">NAND Processing Sequence</a> page. 267</p> 268<table border="1"> 269 <tr> 270<th ROWSPAN="3">A. Items that applications must support</th> 271<td>NAND_RESULT_AUTHENTICATION</td> 272 </tr> 273 <tr> 274<td>NAND_RESULT_CORRUPT</td> 275 </tr> 276 <tr> 277<td>NAND_RESULT_ECC_CRIT</td> 278 </tr> 279 <tr> 280<th ROWSPAN="5">B. Items that applications must support for which a bug report to Nintendo is expected (if possible)</th> 281<td>NAND_RESULT_ALLOC_FAILED</td> 282 </tr> 283 <tr> 284<td>NAND_RESULT_BUSY</td> 285 </tr> 286 <tr> 287<td>NAND_RESULT_MAXBLOCKS</td> 288 </tr> 289 <tr> 290<td>NAND_RESULT_MAXFILES</td> 291 </tr> 292 <tr> 293<td>NAND_RESULT_UNKNOWN</td> 294 </tr> 295 <tr> 296<th ROWSPAN="9">C. Must be removed during the development or hidden from the player</th> 297<td>NAND_RESULT_ACCESS</td> 298 </tr> 299 <tr> 300<td>NAND_RESULT_EXISTS</td> 301 </tr> 302 <tr> 303<td>NAND_RESULT_INVALID</td> 304 </tr> 305 <tr> 306<td>NAND_RESULT_MAXDEPTH</td> 307 </tr> 308 <tr> 309<td>NAND_RESULT_MAXFD</td> 310 </tr> 311 <tr> 312<td>NAND_RESULT_NOEXISTS</td> 313 </tr> 314 <tr> 315<td>NAND_RESULT_NOTEMPTY</td> 316 </tr> 317 <tr> 318<td>NAND_RESULT_OPENFD</td> 319 </tr> 320 <tr> 321<td>NAND_RESULT_FATAL_ERROR</td> 322 </tr> 323</table> 324<p> 325Result codes that are classified as (A) are the codes that may be caused by issues such as wear to the Wii console NAND memory.<br>Result codes that are classified as (B) are the codes that should not appear as long as the Wii system is running normally. If result codes in this category appear, please send a bug report to Nintendo if possible, as there is a chance of a defect in either RevolutionSDK or the Wii console/Wii development console.<br>Result codes that are classified as (C) are the codes that mainly suggest coding errors by the application programmers.<br> 326</p> 327 328<h2>Notes</h2> 329<h3>Precautions when Writing Data</h3> 330<p> 331The file system used to manage the Wii console NAND memory has been designed to survive unexpected power shutdowns. There is no worry of the entire file system crashing even if the power shuts down in the middle of FAT update in the internal NAND memory. The system will instead restart from a FAT state immediately before the update. However, care must be taken regarding write timing. Assume that the following operations have been performed on a given file. 332</p> 333<ol> 334<li>Open() 335<li>Read() 336<li>Write() 337<li>Write() 338<li>Write() 339<li>Close() 340</ol> 341<p> 342Write() alone does not update the FAT in the built-in flash memory. (The FAT in memory is updated.) Even if power shuts down midway through the execution of Write(), file contents will start from the state in effect before Write() was invoked. However, if an operation that involves updating the FAT in built-in flash memory occurs between instances of Write(), the data written by Write() up to that point will be reflected in built-in flash memory. For example, if another thread or process executes Create() immediately after the Write() on line three has finished executing, the FAT in built-in flash memory will be updated. If the power goes out immediately after this Create() function has finished executing, only the data written due to the Write() in line three will be reflected in the file. Although even this behavior may not be a problem depending on the data structure recorded for the file, if any of the of Write() on lines three, four or five are left out, problems will result if data consistency is lost. 343</p> 344<p> 345One method of avoiding inconsistency of data due to this type of FAT update timing is to use a temporary file. First, copy the target file to /tmp and then perform all subsequent reads and writes on the file copied to /tmp. Finally, after the copied file is closed, Move() can be used to overwrite the original file, thus avoiding inconsistency of data described previously. This algorithm is implemented using the functions <a href="./NANDSimpleSafeOpen.html"><CODE>NANDSimpleSafeOpen</CODE></a>/<a href="./NANDSimpleSafeOpenAsync.html"><CODE>NANDSimpleSafeOpenAsync</CODE></a> and <a href="./NANDSimpleSafeClose.html"><CODE>NANDSimpleSafeClose</CODE></a>/<a href="./NANDSimpleSafeCloseAsync.html"><CODE>NANDSimpleSafeCloseAsync</CODE></a>. The sample demo "safe" is provided to demonstrate the atomic nature of updating files using these functions. 346</p> 347 348<h3>About the NANDSimpleSafe Functions</h3> 349<p> 350The NANDSimpleSafe functions have been prepared to resolve problems with the NANDSafe functions. (There was no recovery method if a function call terminated in an error.) If a NANDSimpleSafe type function ends in an error, call NANDSimpleSafeCancel[Async]. This function will try to release resources used by the NANDSimpleSafe type function. 351</p> 352<p> 353Although <code>NANDSimpleSafeOpen[Async]</code> and <code>NANDSimpleSafeClose[Async]</code> guarantee the atomicity of file updates, to achieve it they incur a higher cost than the ordinary <code>NANDOpen[Async]</code> and <code>NANDClose[Async]</code>. When using these functions, note the following points: 354<ul> 355<li>Unlike the NANDSafe functions, <font color="ff0000">when the NANDSimpleSafe functions are used it is no longer possible to open multiple files that have the same file name at the same time.</font> (NAND_RESULT_EXISTS will return.) Careful attention is required when an application manages save files by creating directory structures such as <CODE>~/userA/save.dat, ~/userB/save.dat</CODE>. 356<li>Compared to the NANDSafe functions, <font color="ff0000">there are stricter restrictions on the buffer size required to copy files. Be sure to specify a size that is a multiple of <code>NAND_FSBLOCK_SIZE</code>(16KB).</font> 357<li><font color="ff0000">Do not use NANDSimpleSafe functions in combination with NANDSafe functions. </font> If these functions are used in combination, operations are not guaranteed . 358<li>A buffer for copying files must be allocated. 359<li>The <CODE>/tmp/sys</CODE> directory is created when <code>NANDSimpleSafeOpen[Async]</code> is executed for the first time. 360<li>Because <code>NANDSimpleSafeOpen[Async]</code> copies original files, it consumes time as well as the storage space under <code>/tmp</code> corresponding to file size. 361<li>When copying files, <code>NANDSimpleSafeOpen[Async]</code> will use one inode in <code>/tmp</code> to create a copy of the original file under <code>/tmp/sys</code>. Furthermore, it generates one FAT update. 362<li>When <code>NANDSimpleSafeClose[Async]</code> executes, it generates two file closures and a file move. (However, <code>/tmp/sys</code> is not removed once it is created.) The function thus generates three FAT updates. 363</ul> 364</p> 365 366<h3>Disadvantages of NANDSafe Functions</h3> 367<p> 368(Use of NANDSafe functions is not recommended. Instead, use the new <code>NANDSimpleSafe</code> functions instead.)<br> 369</p> 370<p> 371<SPAN STYLE="text-decoration: line-through">Although <code>NANDSafeOpen[Async]</code> and <code>NANDSafeClose[Async]</code> guarantee the atomicity of file updates, to achieve it they incur a higher cost than the ordinary <code>NANDOpen[Async]</code> and <code>NANDClose[Async]</code>. Note the following when using these functions. 372<ul> 373<li>A buffer for copying files must be allocated. 374<li>The directory <code>/tmp/sys</code> is created when <code>NANDSafeOpen[Async]</code> is executed for the first time. 375<li>Because <code>NANDSafeOpen[Async]</code> copies original files, it consumes time and storage space under <code>/tmp</code> in accordance with file size. 376<li><code>NANDSafeOpen[Async]</code> will use two inodes for copying because first a unique directory will be created under <code>/tmp/sys</code>, and next the copied file will be created under the directory. Furthermore, it generates two FAT updates. 377<li>When <code>NANDSafeClose[Async]</code> executes, it generates two file closes, a file move, and deletes a created directory. (However, <code>/tmp/sys</code> is not removed once created.) The function therefore generates four FAT updates. 378</ul> 379</SPAN> 380</p> 381 382<h3>Allowable Characters in File and Directory Names</h3> 383<p> 384The characters that can be used in file and directory names are limited to the alphanumeric characters <code>[0-9a-zA-Z]</code> and a few symbols <code>[-_.]</code>. 385</p> 386 387<h3>Buffer Alignment</h3> 388<p> 389The buffers used for reading and writing data and the buffers used for getting directory lists must be 32-byte aligned. Furthermore, the buffer for data read/directory list retrieval must be a multiple of 32 bytes. 390</p> 391<p> 392<font color=#ff0000>Performance is slightly enhanced by using 64-byte alignment for the buffer used to read/write data.</font> 393</p> 394 395<h3>File/Directory Properties</h3> 396<p> 397You can set properties for files/directories. However, as of 2006/06/16, no decision has been made regarding what type of properties to provide. Although arguments for specifying attributes are included with functions that create files/directories and functions that change properties, at present, do not specify any value other than zero for these arguments. 398</p> 399 400<h3>Prohibition on Frequent Read Access</h3> 401<p> 402As a characteristic of NAND flash devices, <font color=#ff0000>if read access is repeated frequently several hundred thousand times or more on a given region without performing an erase or write operation, data may become corrupted in the periphery of that region.</font>If it is necessary to read data saved in Wii console NAND memory repeatedly, first load a good chunk of data in MEM1 or MEM2, and then read data from MEM1 or MEM2 to reduce the number of read access operations on Wii console NAND memory.<br> For example, the following types of Read access are prohibited. 403<ul> 404<li>Performing a Read access to Wii console NAND memory every time data for a single character of a font is required 405<li>Periodically performing a Read access to Wii console NAND memory at an interval of every frame or every second 406<li>Performing Read access to Wii console NAND memory every time a character moves 407</ul> 408</p> 409 410<h3>Wear on the Wii console NAND memory</h3> 411<p> 412Write operations will wear out the Wii console NAND memory, so please avoid frequent writing (do not use as virtual memory). When performing auto-save, please limit its frequency to less than once per minute. If you use the NANDSimpleSafe functions to perform auto-save, you must increase the interval between auto-saves (less than once every four minutes on average) to avoid wear and tear on the FAT, because the process of opening and closing files generates four FAT updates. The limitations become even more severe when performing auto-save using the (unrecommended) NANDSafe line of functions. Because the NANDSafe functions perform six FAT updates during the process of opening and closing files, you need to increase the interval between automatic saves (less than once every six minutes on average) to avoid wear and tear on the FAT. 413</p> 414 415<h3>Fluctuations in Access Time</h3> 416<p> 417Due to the characteristics of the NAND flash device, the time required to access data may vary even though the amount of data being read/written is the same. For this reason, do not write game programs that depend on access time. 418</p> 419 420<h3>Reset/shutdown processes</h3> 421<p> 422We recommend the reset/shutdown function to not be called until all Wii console NAND memory operations issued by the application program is completed.<br>The reset/shutdown function will execute without waiting for the NAND function issued by the application to close. The file system managing the Wii console NAND memory will guarantee the security of the entire file system against accidents (such as power outage), but will not guarantee for the data that was in the middle of write operation. Also refer to <a href="../os/Reset/intro.html">Reset Function/Shutdown Function</a> regarding reset/shutdown operations. 423</p> 424 425<h3>Regarding Data Tampering</h3> 426<p> 427The file system managing the Wii console NAND memory is strong by design against data tampering or prying. For this reason, there is no need to perform any special encryptions from the application program side when storing data into the Wii console NAND memory. 428</p> 429 430<h3>Periodic Access from the System</h3> 431<p> 432<font color="ff0000">Starting with SDK 2.1 patch 1 (2006/08/30), the system now periodically accesses the Wii console NAND memory. </font>There will be a file write once per minute, and a file open/close once every five minutes (FAT will also be updated at the close). For this reason, a single file descriptor will always be consumed. Also, when the system access timing and the application access timing overlaps, it may take longer than normal for the process to complete. 433</p> 434 435<h2>Limitations on Use</h2> 436<p> 437The following restrictions will apply regarding the use of Wii console NAND memory. Note that the files/directories created under <code>/tmp/sys</code> will also be subject to these restrictions. If the application is updating 1MB save file using NANDSafe type function, the upper limit of the file capacity that can be freely created in /tmp by the application will decrease to 39MB. 438<table border="1"> 439 <tbody> 440 <tr> 441<td bgcolor="#C0C0C0">Coverage</td> 442<td bgcolor="#C0C0C0">Upper Limit</td> 443 </tr> 444 <tr> 445<td>Maximum file storage capacity of the home directory</td> 446<td>16 MB</td> 447 </tr> 448 <tr> 449<td>Number of files/directories that can be created in the home directory</td> 450 <td>32</td> 451 </tr> 452 <tr> 453<td>Maximum storage capacity of file that can be created in <code>/tmp</code></td> 454<td>40 MB</td> 455 </tr> 456 <tr> 457<td>Number of files/directories that can be created in <code>/tmp</code></td> 458 <td>64</td> 459 </tr> 460 </tbody> 461</table> 462</p> 463 464<H2>Revision History</H2> 465<p> 4662007/05/E Added a note about guidelines for handling result codes.<br>2007/05/M Added a brief explanation about the Group permission.<br>2007/05/M Added a note about the frequency of calls to the <CODE>NANDSimpleSafe</CODE> functions.<br>2007/05/09 Noted that a callback function is not called when an asynchronous function call ends in an error.<br>2007/05/09 Added a description of the <CODE>NANDSimpleSafe</CODE> line of functions. Noted that the use of <CODE>NANDSafe</CODE> functions is not recommended.<br>2007/02/xx Added the result code <CODE>NAND_RESULT_MAXDEPTH</CODE>.<br>2007/02/xx Added a supplement about the <CODE>NAND_RESULT_OPENFD</CODE> result code.<br>2006/12/18 Added a description of the prohibition on frequent Read access.<br>2006/11/30 Added text about result codes.<br>2006/11/30 Added text mentioning that many synchronous functions can return <CODE>NAND_RESULT_ALLOC_FAILED</CODE> and <CODE>NAND_RESULT_BUSY</CODE>.<br>2006/11/30 Deleted text about <CODE>NANDGetAvailableArea[Async]</CODE> as an alternative to <CODE>NANDCheck[Async]</CODE>.<br>2006/11/10 Supplemented the information about banner files and <CODE>NANDCheck[Async]</CODE>.<br>2006/10/25 Explained NANDGetAvailableArea[Async].<br>2006/10/25 Standardized terminology.<br>2006/10/25 Added information about periodic access from the system.<br>2006/09/28 Explained implementation details about the <CODE>NANDSafe</CODE> type function. Clarified the operational restrictions.<br>2006/09/25 Specified the home directory location.<br>2006/09/19 Added details about the result code that <CODE>NANDSafeOpenAsync</CODE> and <CODE>NANDSafeCloseAsync</CODE> function callbacks may receive.<br>2006/09/19 Added information about banner files.<br>2006/08/30 Added information that <CODE>NANDInit</CODE> is now automatically called from the system.<br>2006/08/30 Added information about <CODE>NANDCheck</CODE>.<br>2006/08/30 Fixed spelling errors in the result code.<br>2006/08/15 Revised the table on operational limitations.<br>2006/08/15 Added a description of the <CODE>NANDSafe</CODE> line of functions.<br>2006/08/15 Described the maximum allowable depth of the directory hierarchy.<br>2006/08/15 Deleted the <CODE>NAND_RESULT_INIT_FAILED</CODE> result code.<br>2006/08/15 Added description of characters allowed in file/directory names.<br>2006/08/15 Revised description of /tmp/sys.<br>2006/08/15 Revised description of maximum path length.<br>2006/08/15 Added precautions regarding writing data.<br>2006/08/15 Added a description of the <CODE>NAND_RESULT_AUTHENTICATION</CODE> result code.<br>2006/06/16 Initial version. <BR> 467</p> 468 469 470</body> 471</html> 472