diff --git a/include/fat.h b/include/fat.h index 44ceef6f..b610a9de 100644 --- a/include/fat.h +++ b/include/fat.h @@ -22,6 +22,7 @@ extern "C" { /// This function calls fatInit() with the default cache size (5 pages = 20 KB). /// /// @return It returns true on success, false on error. +WARN_UNUSED_RESULT bool fatInitDefault(void); /// This function initializes the FAT filesystem with a default cache size. @@ -53,6 +54,7 @@ bool fatInitDefault(void); /// /// @return /// It returns true on success, false on error. +WARN_UNUSED_RESULT bool fatInit(int32_t cache_size_pages, bool set_as_default_device); /// This function returns the default current working directory. diff --git a/include/filesystem.h b/include/filesystem.h index 1a2b00b5..ec1cb866 100644 --- a/include/filesystem.h +++ b/include/filesystem.h @@ -30,6 +30,7 @@ extern "C" { /// /// @return /// It returns true on success, false on error. +WARN_UNUSED_RESULT bool nitroFSInit(const char *basepath); /// Exits NitroFS. diff --git a/source/arm9/libc/nitrofs.c b/source/arm9/libc/nitrofs.c index 6f216794..5b96472c 100644 --- a/source/arm9/libc/nitrofs.c +++ b/source/arm9/libc/nitrofs.c @@ -640,20 +640,27 @@ bool nitroFSInit(const char *basepath) // Try to open the basepath file. if (basepath) { - fatInitDefault(); - nitrofs_local.file = fopen(basepath, "r"); - - // Initialize the FAT lookup cache for NitroFS files. - // NitroFS files inherently do a lot of seeking, so it's almost always - // beneficial. At the same time, for a defragmented drive, this should - // only occupy a few dozen bytes. - // - // FIXME: Move this to the DLDI driver space and remove the 2KB - // size limit. - if (!nitrofs_local.file) - basepath = NULL; + if (fatInitDefault()) + { + nitrofs_local.file = fopen(basepath, "r"); + + // Initialize the FAT lookup cache for NitroFS files. + // + // NitroFS files inherently do a lot of seeking, so it's almost + // always beneficial. At the same time, for a defragmented drive, + // this should only occupy a few dozen bytes. + // + // FIXME: Move this to the DLDI driver space and remove the 2KB + // size limit. + if (nitrofs_local.file == NULL) + basepath = NULL; + else + fatInitLookupCacheFile(nitrofs_local.file, 2048); + } else - fatInitLookupCacheFile(nitrofs_local.file, 2048); + { + basepath = NULL; + } } // Read FNT/FAT offset/size information.