Skip to content

Commit

Permalink
chore: Warn about unused resulted values that really should be used
Browse files Browse the repository at this point in the history
If the developer doesn't check whether FAT or NitroFS have been
initialized correctly, it won't be possible to show a sensible error
message to the user of the application when something fails later. It
is very important to verify that they have been initialized correctly
and to show a message to the user so that they know what happened.
  • Loading branch information
AntonioND committed Nov 6, 2024
1 parent e9bfb29 commit 9340e73
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
2 changes: 2 additions & 0 deletions include/fat.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions include/filesystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
33 changes: 20 additions & 13 deletions source/arm9/libc/nitrofs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 9340e73

Please sign in to comment.