1<?xml version="1.0" encoding="utf-8"?> 2<html xml:lang="en-US" lang="en-US"> 3<head> 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 5 <meta http-equiv="Content-Style-Type" content="text/css" /> 6 <link rel="stylesheet" href="../../../css/page.css" type="text/css" /> 7<title>File System: Error Handling</title> 8</head> 9<body> 10<h1>File System: Error Handling</h1> 11 12<h2>Table of Contents</h2> 13 <ul> 14<li><a href="#Summary">Overview</a></li> 15 <ul> 16<li><a href="#Summary_Result">Result Handling</a></li> 17<li><a href="#Summary_Error">Errors That Must Not Be Allowed to Occur in Retail Products</a></li> 18<li><a href="#Summary_Api">Functions for File and Directory Operations</a></li> 19<li><a href="#Summary_FatalError">Handling Fatal Errors</a></li> 20 </ul> 21<li><a href="#Mounting">Handling Mount Errors</a></li> 22 <ul> 23<li><a href="#Mounting_RomArchive">ROM Archives</a></li> 24<li><a href="#Mounting_SaveDataArchive">Save Data Archives</a></li> 25<li><a href="#Mounting_SaveDataArchive_Other">Save Data Archives (Other Programs)</a></li> 26<li><a href="#Mounting_ExtSaveDataArchive">Expanded Save Data Archives</a></li> 27<li><a href="#Mounting_SdmcWriteOnlyArchive">Write-only SDMC Archives</a></li> 28 </ul> 29<li><a href="#FileAndDirectory">Handling Errors During File and Directory Operations</a></li> 30 <ul> 31<li><a href="#FileAndDirectory_RomArchive">ROM Archives</a></li> 32<li><a href="#FileAndDirectory_SaveDataArchive">Save Data Archives</a></li> 33<li><a href="#FileAndDirectory_ExtSaveDataArchive">Expanded Save Data Archives</a></li> 34<li><a href="#FileAndDirectory_SdmcWriteOnlyArchive">Write-only SDMC Save Data Archives</a></li> 35 </ul> 36<li><a href="#History">Revision History</a></li> 37 </ul> 38 39<a name="Summary"><h2>Overview</h2></a> 40 <div class="section"> 41This page describes error handling for the file system. 42 43<a name="Summary_Result"><h3>Result Handling</h3></a> 44 <div class="section"> 45FS functions return many different types of <CODE>Result</CODE> values. These are handled by the following mechanism rather than one value at a time. The following example shows how to handle all errors belonging to the <CODE><a href="../../../nn/fs/ResultNotFound/Overview.html">ResultNotFound</a></CODE> category. <code><pre> 46if(result <= nn::fs::ResultNotFound()) 47{ 48 // This can catch nn::fs::ResultMediaNotFound as well. 49} 50</pre></code>The <CODE>Result</CODE> objects returned by <CODE>fs</CODE> functions are forbidden from using the arithmetic operators <CODE>==</CODE> or <CODE>!=</CODE>. Using these causes a build error. Also note that the following two examples are equivalent. <code><pre> 51if(nn::fs::ResultNotFound::Includes(result)) 52{ 53 ... 54} 55</pre></code> <code><pre> 56if(nn::fs::ResultNotFound() >= result) 57{ 58 ... 59} 60</pre></code> 61<p><font color="red">Do not directly handle any <CODE>Result</CODE> values that are not mentioned in the Function Reference Manual.</font></p> 62 </div> 63 64<a name="Summary_Error"><h3>Errors That Must Not Be Allowed to Occur in Retail Products</h3></a> 65 <div class="section"> 66The following <CODE>Result</CODE> values indicate errors that are caused by application bugs and other such problems. You must fix your program so that these do not occur in retail products. 67 <ul> 68<li><a href="../../../nn/fs/ResultOutOfResource/Overview.html"><CODE>ResultOutOfResource</CODE></a></li> 69<li><a href="../../../nn/fs/ResultAccessDenied/Overview.html"><CODE>ResultAccessDenied</CODE></a></li> 70<li><a href="../../../nn/fs/ResultInvalidArgument/Overview.html"><CODE>ResultInvalidArgument</CODE></a></li> 71<li><a href="../../../nn/fs/ResultNotInitialized/Overview.html"><CODE>ResultNotInitialized</CODE></a></li> 72<li><a href="../../../nn/fs/ResultAlreadyInitialized/Overview.html"><CODE>ResultAlreadyInitialized</CODE></a></li> 73<li><a href="../../../nn/fs/ResultUnsupportedOperation/Overview.html"><CODE>ResultUnsupportedOperation</CODE></a></li> 74 </ul> 75The <CODE>Result</CODE> values listed above may be caused by user operations or it may be impossible to get rid of them entirely during development. You must handle errors that can be caused by the user. Some functions may also specify errors that must not occur in retail products, even though the corresponding <CODE>Result</CODE> values are not among those listed above. For more information, see the documentation for each of these functions in the Function Reference Manual. 76 </div> 77 78<a name="Summary_Api"><h3>Functions for File and Directory Operations</h3></a> 79 <div class="section"> 80There are two types of functions used to perform file and directory operations: <CODE>Try</CODE> functions (which have the prefix <CODE>Try</CODE> added to the function name), and non-<CODE>Try</CODE> functions (which do not contain this prefix). <CODE>Try</CODE> functions return a <CODE>Result</CODE> as the return value, unless a fatal internal error occurs. Instead of returning <CODE>Results</CODE>, non-<CODE>Try</CODE> functions are implemented to display a fatal error screen whenever an internal error returns, regardless of whether the error is fatal. Control does not return from the function in this case.<br /><br />Internal errors never occur for ROM archives because of their characteristics. For ROM archives, implementation omissions in error handling can be avoided by using the non-<CODE>Try</CODE> functions. (During development, make sure to eliminate situations in which an error could occur because of an attempt to open a nonexistent file.)<br /> <br />For archives other than ROM archives, you must always check for errors that can result from the user's operations. One typical example is removal of the Game Card by the user, which can lead to corrupted files. As a result, <CODE>Try</CODE> functions should always be used for error handling. Do not use non-<CODE>Try</CODE> functions because they can easily jump to fatal error screens as a result of user operations. 81 </div> 82 83<a name="Summary_FatalError"><h3>Handling Fatal Errors</h3></a> 84 <div class="section"> 85You are allowed to use the following macro to jump to the fatal error screen when a file system API function returns an error that you believe to be fatal, or there is a system issue that your application cannot handle.<BR><BR>Note, however, that applications must handle all errors other than those given in the following examples. Do not call this function in locations other than given in examples in order to prevent unnecessary transition to the fatal error screen. 86<pre> 87NN_ERR_THROW_FATAL_ALL(result); 88</pre> 89See the <a href="../../../introduction/ErrorHandling.html">Error Handling</a> page for details about this macro. 90 </div> 91 </div> 92 93<a name="Mounting"><h2>Handling Mount Errors</h2></a> 94 <div class="section"> 95The following simplified C++ code provides guidelines for handling mount errors. 96 97<a name="Mounting_RomArchive"><h3>ROM Archives</h3></a> 98 <div class="section"> 99<code><pre> 100// An error will cause an internal jump to the fatal error screen. 101// The application does not need to perform error handling. 102// NOTE: When developing an application, confirm that you are passing enough working memory as an argument. 103// Also check your Omakefile and RSF file settings to determine whether a ROMFS is created at build time. 104nn::fs::MountRom(); 105</pre></code> 106 </div> 107 108<a name="Mounting_SaveDataArchive"><h3>Save Data Archives</h3></a> 109 <div class="section"> 110<code><pre> 111nn::Result result = nn::fs::MountSaveData(); 112 113if(result.IsFailure()) 114{ 115 if(result <= nn::fs::ResultNotFormatted()) 116 { 117 // Formatting required. 118 // CAUSE: Unformatted save data region. 119 // NOTE: You must always format a save data region before mounting it for the first time. 120 result = nn::fs::FormatSaveData(); 121 } 122 else if(result <= nn::fs::ResultBadFormat()) 123 { 124 // Formatting required. 125 // CAUSE: Invalid file format. 126 result = nn::fs::FormatSaveData(); 127 } 128 else if(result <= nn::fs::ResultVerificationFailed()) 129 { 130 // Formatting required. 131 // CAUSE: Corrupted or tampered-with save data. 132 // (Supplement) This may occur whether or not there is a duplication. 133 result = nn::fs::FormatSaveData(); 134 } 135 else if(result <= nn::fs::ResultOperationDenied()) 136 { 137 // As of CTR-SDK 2.1, this error is handled by the system. Treat it as an unexpected error. 138 } 139 else 140 { 141 // Unexpected error if other than the above. 142 NN_ERR_THROW_FATAL_ALL(result); 143 } 144 145 // Troubleshooting after formatting 146 if(result.IsFailure()) 147 { 148 // Here, the act of formatting save data never fails. 149 // NOTE: When developing your application, confirm that the maxFiles and maxDirectories arguments are not too big. 150 // Also confirm that the content of the RSF file is correct. 151 // NOTE: Do not format the region while it is mounted, or access save data from another thread during formatting. 152 NN_ERR_THROW_FATAL_ALL(result); 153 } 154 else 155 { 156 // Remount 157 result = nn::fs::MountSaveData(); 158 if(result.IsFailure()) 159 { 160 // The same as when making the first call. 161 // NOTE: Do not format the region while it is mounted, or access save data from another thread during formatting. 162 } 163 } 164} 165</pre></code> 166 </div> 167 168<a name="Mounting_SaveDataArchive_Other"><h3>Save Data Archives (Other Programs)</h3></a> 169 <div class="section"> 170<code><pre> 171nn::Result result = nn::fs::MountSaveData(archiveName, uniqueId, variation); 172 173if(result.IsFailure()) 174{ 175 if(result <= nn::fs::ResultNotFound()) 176 { 177 // Stop access. 178 // Reason: Target save data not found. 179 } 180 else if(result <= nn::fs::ResultNotFormatted() || result <= nn::fs::ResultBadFormat()) 181 { 182 // Stop access. 183 // Reason: Target save data not formatted correctly. 184 // Comment: To use the save data it needs to be formatted by the program to which it belongs. 185 } 186 else if(result <= nn::fs::ResultVerificationFailed()) 187 { 188 // Stop access. 189 // Reason: Target save data is corrupt. 190 // Comment: To use the save data it needs to be formatted by the program to which it belongs. 191 } 192 else if(result <= nn::fs::ResultOperationDenied()) 193 { 194 // Stop access. 195 // Reason: Cannot access the target media. 196 // Comment: This might be resolved by removing and re-inserting the target media. 197 } 198 else 199 { 200 // Unexpected error if other than the above. 201 // Do not call "NN_ERR_THROW_FATAL" macros. 202 } 203} 204</pre></code> 205 </div> 206 207<a name="Mounting_ExtSaveDataArchive"><h3>Expanded Save Data Archives</h3></a> 208 <div class="section"> 209<code><pre> 210nn::Result result = nn::fs::MountExtSaveData(); 211 212if(result.IsFailure()) 213{ 214 if(result <= nn::fs::ResultNotFound()) 215 { 216 if(result <= nn::fs::ResultMediaNotFound()) 217 { 218 // An SD Card has not been inserted. 219 // Note: This error is also returned if the SD Card is damaged or if some medium other than an SD Card is inserted. 220 // In such cases, an insertion event registered by <CODE>RegisterSdmcInsertedEvent</CODE> is signaled. 221 } 222 else 223 { 224 // The specified expanded save data does not exist and must be created. 225 // NOTE: Confirm that the ID you specified is correct when developing your application. 226 result = nn::fs::CreateExtSaveData(); 227 } 228 } 229 else if(result <= nn::fs::ResultNotFormatted()) 230 { 231 // You must recreate the expanded save data. 232 // CAUSE: Failed to create expanded save data. 233 result = nn::fs::DeleteExtSaveData(); 234 if(result.IsSuccess()) 235 { 236 result = nn::fs::CreateExtSaveData(); 237 } 238 } 239 else if(result <= nn::fs::ResultBadFormat()) 240 { 241 // You must format the SD Card. 242 } 243 else if(result <= nn::fs::ResultVerificationFailed()) 244 { 245 // You must recreate the expanded save data. 246 // CAUSE: The save data has been corrupted or tampered with. 247 result = nn::fs::DeleteExtSaveData(); 248 if(result.IsSuccess()) 249 { 250 result = nn::fs::CreateExtSaveData(); 251 } 252 } 253 else if(result <= nn::fs::ResultOperationDenied()) 254 { 255 if(result <= nn::fs::ResultWriteProtected()) 256 { 257 // The SD Card is write-protected. 258 // NOTE: This occurs if the data recovery sequence is run during a mount operation. 259 } 260 else if(result <= nn::fs::ResultMediaAccessError()) 261 { 262 // This error is only returned when the cause is hardware related, such as a poor connection. 263 // In such cases, recovery may be possible by re-inserting the SD Card, restarting the system, or some other action. 264 } 265 else 266 { 267 // The file or directory on the SD card may be read-only. 268 // NOTE: This occurs if the data recovery sequence is run during a mount operation. 269 } 270 } 271 else 272 { 273 // Unexpected error if other than the above. Failed to recognize this expanded save data or SD Card. 274 // Do not call "NN_ERR_THROW_FATAL" macros. 275 } 276 277 // Troubleshooting after data has been created. 278 if(result.IsFailure()) 279 { 280 if(result <= nn::fs::ResultNotEnoughSpace()) 281 { 282 // The SD Card does not have the necessary free space. 283 } 284 else if(result <= nn::fs::ResultNotFormatted()) 285 { 286 // An error has occurred, interrupting the process of data creation. 287 } 288 else if(result <= nn::fs::ResultOperationDenied()) 289 { 290 if(result <= nn::fs::ResultWriteProtected()) 291 { 292 // The SD Card is write-protected. 293 } 294 else if(result <= nn::fs::ResultMediaAccessError()) 295 { 296 // This error is only returned when the cause is hardware related, such as a poor connection. 297 // In such cases, recovery may be possible by retrying, re-inserting the Game Card, restarting the system, or some other action. 298 } 299 else 300 { 301 // The directory on the SD Card may be read-only. 302 // NOTE: This occurs if the data recovery sequence is run during a mount operation. 303 } 304 } 305 else 306 { 307 // Failed to recognize this expanded save data or SD Card. 308 // Handle corresponding errors here together. Do not jump to the fatal error screen.) 309 // NOTE: When developing your application, confirm that valid values are passed to iconData and iconDataSize. 310 } 311 } 312 else 313 { 314 // Remount 315 result = nn::fs::MountExtSaveData(); 316 if(result.IsFailure()) 317 { 318 // The same as when making the first call. 319 // (Supplement) As long as the SD Card is not removed, mount operations carried out immediately after the data is created will never fail. 320 } 321 } 322} 323</pre></code> 324 </div> 325 326<a name="Mounting_SdmcWriteOnlyArchive"><h3>Write-only SDMC Archives</h3></a> 327 <div class="section"> 328<code><pre> 329nn::Result result = nn::fs::MountSdmcWriteOnly(); 330 331if(result.IsFailure()) 332{ 333 if(result <= nn::fs::ResultMediaNotFound()) 334 { 335 // An SD Card has not been inserted. 336 // NOTE: This error is also returned if the SD Card is damaged or if some medium other than an SD Card is inserted. 337 // In such cases, an insertion event registered by <CODE>RegisterSdmcInsertedEvent</CODE> is signaled. 338 } 339 else if(result <= nn::fs::ResultBadFormat()) 340 { 341 // You must format the SD Card. 342 } 343 else if(result <= nn::fs::ResultOperationDenied()) 344 { 345 if(result <= nn::fs::ResultWriteProtected()) 346 { 347 // This error will not be returned when mounted. Check separately by calling the <a href="../../../nn/fs/IsSdmcWritable.html">nn::fs::IsSdmcWritable</a> function. 348 } 349 else if(result <= nn::fs::ResultMediaAccessError()) 350 { 351 // This error is only returned when the cause is hardware related, such as a poor connection. 352 // In such cases, recovery may be possible by re-inserting the SD Card, restarting the system, or some other action. 353 } 354 else 355 { 356 // Failed to recognize this SD Card. 357 // Handle corresponding errors here together. Do not jump to the fatal error screen.) 358 } 359 } 360 else 361 { 362 // Failed to recognize this SD Card. 363 // Handle corresponding errors here together. Do not jump to the fatal error screen.) 364 } 365} 366</pre></code> 367 </div> 368 </div> 369 370<a name="FileAndDirectory"><h2>Handling Errors During File and Directory Operations</h2></a> 371 <div class="section"> 372The following simplified C++ code provides a guideline for handling errors during file and directory operations.<br /><br /><br /> There are two types of functions used to perform file and directory operations: <CODE>Try</CODE> functions (which have the prefix <CODE>Try</CODE> added to the function name), and non-<CODE>Try</CODE> functions (which do not contain this prefix). For details, see <a href="#Summary_Api">Functions for File and Directory Operations</a>. 373 374<a name="FileAndDirectory_RomArchive"><h3>ROM Archives</h3></a> 375 <div class="section"> 376<code><pre> 377// Because errors are handled internally by non-<CODE>Try</CODE> functions, you do not need to receive <CODE>Result</CODE> values. 378nn::fs::XXX(); 379</pre></code> 380 </div> 381 382<a name="FileAndDirectory_SaveDataArchive"><h3>Save Data Archives</h3></a> 383 <div class="section"> 384<code><pre> 385// We need to use Try functions with save data archive. 386result = nn::fs::TryXXX(); 387 388if(result.IsFailure()) 389{ 390 if(result <= nn::fs::ResultNotFound()) 391 { 392 // The specified path does not exist. 393 // Note: This error is returned when creating a file or directory and the archive name is wrong or a directory in the path does not exist. 394 } 395 else if(result <= nn::fs::ResultAlreadyExists()) 396 { 397 // The specified path already exists. 398 // NOTE: This error is not returned when files and directories are deleted. 399 } 400 else if(result <= nn::fs::ResultVerificationFailed()) 401 { 402 // If there is automatic redundancy, you must reformat because otherwise the save data will not be completely consistent. 403 // If there is no automatic redundancy, you must delete and recreate this file or directory. 404 // CAUSE: The save data has been corrupted or tampered with. 405 // NOTE: This state will never be caused by user operations (such as removing a card or turning off the system while data is being written) when there is automatic redundancy (unless intentionally tampered with). 406 // If there is no automatic redundancy, this error can occur even through normal user operations. 407 // If this is not resolved, you must format the save data. 408 // NOTE: This error is returned when reading a region that has never been written to. 409 // Be careful after executing the functions <CODE>nn::fs::TryCreateFile</CODE> and <CODE>nn::fs::FileStream::TrySetSize</CODE>. 410 } 411 else if(result <= nn::fs::ResultOperationDenied()) 412 { 413 if(result <= nn::fs::ResultMediaAccessError()) 414 { 415 // As of CTR-SDK 2.1, this error is handled by the system. Treat it as an unexpected error. 416 NN_ERR_THROW_FATAL_ALL(result); 417 } 418 else 419 { 420 // Access was denied for some reason. 421 // EXAMPLE: You attempted to delete a file that was open elsewhere. 422 // You attempted to move a file or directory so that it would span archives. 423 // You attempted to delete the root directory. 424 // NOTE: You do not need handling for the above situations if, by design, they will not occur. 425 } 426 } 427 else if(result <= nn::fs::ResultNotEnoughSpace()) 428 { 429 // There is no available space in the archive or on the storage media. 430 // NOTE: This error may occur when creating a file or directory, or changing the file size. 431 // If this error occurs when you create a file, delete the file because it might be corrupted. 432 // If this error occurs when you change the size of a file, the file may have grown to the maximum possible size. 433 } 434 else 435 { 436 // Unexpected error if other than the above. 437 NN_ERR_THROW_FATAL_ALL(result); 438 } 439} 440</pre></code> 441 </div> 442 443<a name="FileAndDirectory_ExtSaveDataArchive"><h3>Expanded Save Data Archives</h3></a> 444 <div class="section"> 445<code><pre> 446result = nn::fs::TryXXX(); 447 448if(result.IsFailure()) 449{ 450 if(result <= nn::fs::ResultNotFound()) 451 { 452 if(result <= nn::fs::ResultMediaNotFound()) 453 { 454 // An SD Card has not been inserted. 455 // NOTE: This error is also returned if the SD Card is damaged or if some medium other than an SD Card is inserted. 456 // In such cases, an insertion event registered by <CODE>RegisterSdmcInsertedEvent</CODE> is signaled. 457 } 458 else 459 { 460 // The specified path does not exist. 461 // NOTE: If this error is returned when opening the file, it may have been deleted from the SD Card using a PC or the like. 462 // NOTE: Expanded save data can also be accessed from other applications, 463 // so handling is not required for this error. 464 } 465 } 466 else if(result <= nn::fs::ResultAlreadyExists()) 467 { 468 // The specified path already exists. 469 // NOTE: This error is not returned when directories are deleted. 470 // If this error is returned when creating a file, the file may have been deleted from the SD Card using a PC or the like. 471 // NOTE: Expanded save data can also be accessed from other applications, 472 // so handling is required for this error. 473 } 474 else if(result <= nn::fs::ResultVerificationFailed()) 475 { 476 // You must delete and recreate this file or directory. 477 // CAUSE: The expanded save data has been corrupted or tampered with. 478 // NOTE: If this is not resolved, you need to recreate the expanded save data. 479 // NOTE: This error is returned when reading a region that has never been written to. 480 // Be careful after executing the functions <CODE>nn::fs::TryCreateFile</CODE> and <CODE>nn::fs::FileStream::TrySetSize</CODE>. 481 } 482 else if(result <= nn::fs::ResultArchiveInvalidated()) 483 { 484 // You must remount the archive. 485 // CAUSE: The SD Card was removed, making the archive invalid. 486 // NOTE: Close all open files, call the nn::fs::Unmount function, and then remount the archive. 487 } 488 else if(result <= nn::fs::ResultOperationDenied()) 489 { 490 if(result <= nn::fs::ResultWriteProtected()) 491 { 492 // The SD Card is write-locked. 493 // NOTE: This error occurs when you write to an SD Card. This does not occur when you simply open a file. 494 } 495 else if(result <= nn::fs::ResultMediaAccessError()) 496 { 497 // This error is only returned when the cause is hardware related, such as a poor connection. 498 // In such cases, recovery may be possible by re-inserting the SD Card, restarting the system, or some other action. 499 } 500 else 501 { 502 // Access was denied for some reason other than those above. 503 // EXAMPLES: You attempted to write to a file that is read-only. 504 // You attempted to delete a file that was open elsewhere. 505 // You attempted to move a file or directory so that it would span archives. 506 // You attempted to delete the root directory. 507 // (Note) Because the content of expanded save data can be modified even by other applications (depending on operations), 508 // or a user may have spoofed data on the SD card using a PC, this error must always be handled 509 } 510 } 511 else if(result <= nn::fs::ResultNotEnoughSpace()) 512 { 513 // There is no available space in the archive or on the storage media. 514 // NOTE: This error may occur when creating a file or directory, or changing the file size. 515 // If this error occurs when you create a file, delete the file because it might be corrupted. 516 // If this error occurs when you change the size of a file, the file may have grown to the maximum possible size. 517 } 518 else 519 { 520 // Failed to access this expanded save data or SD Card. 521 // Handle corresponding errors here together. Do not jump to the fatal error screen.) 522 } 523} 524</pre></code> 525 </div> 526 527<a name="FileAndDirectory_SdmcWriteOnlyArchive"><h3>Write-only SDMC Archives</h3></a> 528 <div class="section"> 529<code><pre> 530result = nn::fs::TryXXX(); 531 532if(result.IsFailure()) 533{ 534 if(result <= nn::fs::ResultNotFound()) 535 { 536 if(result <= nn::fs::ResultMediaNotFound()) 537 { 538 // An SD Card has not been inserted. 539 // NOTE: An SD Card may have been removed after the archive was mounted. 540 } 541 else 542 { 543 // The specified path does not exist. 544 // NOTE: You must handle this error, because it is possible for users to manipulate data on SD Cards. 545 } 546 } 547 else if(result <= nn::fs::ResultAlreadyExists()) 548 { 549 // The specified path already exists. 550 // NOTE: This error is not returned when files and directories are deleted. 551 // NOTE: You must handle this error, because it is possible for users to manipulate data on SD Cards. 552 } 553 else if(result <= nn::fs::ResultArchiveInvalidated()) 554 { 555 // You must remount the archive. 556 // CAUSE: The SD Card was removed, making the archive invalid. 557 // NOTE: Close all open files, call the nn::fs::Unmount function, and then remount the archive. 558 } 559 else if(result <= nn::fs::ResultOperationDenied()) 560 { 561 if(result <= nn::fs::ResultWriteProtected()) 562 { 563 // The SD Card is write-locked. 564 // NOTE: This error occurs when you write to an SD Card. This does not occur when you simply open a file. 565 } 566 else if(result <= nn::fs::ResultMediaAccessError()) 567 { 568 // This error is only returned when the cause is hardware related, such as a poor connection. 569 // In such cases, recovery may be possible by re-inserting the SD Card, restarting the system, or some other action. 570 } 571 else 572 { 573 // Access was denied for some reason other than those above. 574 // EXAMPLES: You attempted to write to a file that is read-only. 575 // You attempted to delete a file that was open elsewhere. 576 // You attempted to move a file or directory so that it would span archives. 577 // You attempted to delete the root directory. 578 // NOTE: You must handle this error, because it is possible for users to manipulate data on SD Cards. 579 } 580 } 581 else if(result <= nn::fs::ResultNotEnoughSpace()) 582 { 583 // There is no available space in the archive or on the storage media. 584 // NOTE: This error may occur when creating a file or directory, or changing the file size. 585 // If this error occurs when you create a file, delete the file because it might be corrupted. 586 // If this error occurs when you change the size of a file, the file may have grown to the maximum possible size. 587 } 588 else 589 { 590 // Failed to access this SD Card. 591 // Handle corresponding errors here together. Do not jump to the fatal error screen.) 592 } 593} 594</pre></code> 595 </div> 596 </div> 597 598<a name="History"><h2>Revision History</h2></a> 599 <div class="section"> 600 <dl class="history"> 601 <dt>2012/04/26</dt> 602<dd>Revised the method for handling operations on files/directories for save data archives.</dd> 603 <dt>2012/02/16</dt> 604<dd>Added the section <B>Save Data Archives (Other Programs)</B>.</dd> 605 <dt>2011/06/14</dt> 606<dd>Added the fact that <CODE>ResultVerificationFailed</CODE> may occur when mounting duplicated save data.</dd> 607 <dt>2011/06/14</dt> 608<dd>Added write-only SDMC archives.</dd> 609<dd>Added note about handling fatal errors.</dd> 610 <dt>2011/03/14</dt> 611<dd>Removed <CODE>ResultMediaAccessError</CODE> from the results when mounting save data and when operating on files and directories.</dd> 612 <dt>2011/03/07</dt> 613<dd>Deleted <CODE>ResultArchiveInvalidated</CODE> from the errors that can occur in functions to create or delete expanded save data.</dd> 614 <dt>2011/02/28</dt> 615<dd>Revised error handling for mounting ROM archives in accordance with changes to API.</dd> 616 <dt>2011/02/07</dt> 617<dd>Changed how mounting expanded save data is handled from recreating the archive using <CODE>ResultBadFormat</CODE> to formatting the SD card.</dd> 618<dd>Deleted <CODE>ResultBadFormat</CODE> from how manipulating expanded save data files and directories are handled.</dd> 619<dd>Revised code so that unexpected errors now result in <CODE>NN_ERR_THROW_FATAL_ALL</CODE>.</dd> 620 <dt>2011/01/05</dt> 621<dd>Deleted <CODE>ResultArchiveInvalidated</CODE> from the errors that can occur when mounting the expanded save data.</dd> 622<dd>Changed the <CODE>Result</CODE> from <CODE>ResultMediaAccessError</CODE> to <CODE>ResultMediaNotFound</CODE> when a damaged SD Card is inserted.</dd> 623 <dt>2010/12/14</dt> 624<dd>Added errors that must not be allowed to occur in retail products.</dd> 625<dd>Added <CODE>ResultNotFormatted</CODE> and <CODE>ResultArchiveInvalidated</CODE> to error handling when expanded save data is created.</dd> 626 <dt>2010/12/13</dt> 627<dd>Split up error handling for file and directory operations by archive type.</dd> 628<dd>Changed how <CODE>ResultOperationDenied</CODE> is handled when expanded save data is mounted.</dd> 629 <dt>2010/12/09</dt> 630<dd>Added <B>Functions for File and Directory Operations</B>.</dd> 631 <dt>2010/12/02</dt> 632<dd>Removed <CODE>ResultNotFound</CODE> from save data error handling.</dd> 633 <dt>2010/11/31</dt> 634<dd>Added <CODE>ResultNotEnoughSpace</CODE> to the errors occurring during file operations.</dd> 635 <dt>2010/11/25</dt> 636<dd>Added <CODE>ResultNotFormatted</CODE> to error handling for expanded save data.</dd> 637 <dt>2010/11/13</dt> 638<dd>Initial version.</dd> 639 </dl> 640 </div> 641 642<hr><p>CONFIDENTIAL</p></body> 643</html>