N64FlashcartMenu
Loading...
Searching...
No Matches
cpakfs_utils.c File Reference

Implementation of Controller Pak file system utilities. More...

Functions

bool has_cpak (int controller)
 Check if a Controller Pak is present in the given controller.
 
int get_block_size_from_fs_path (const char *filename_cpak)
 Get the block size from a Controller Pak file system path.
 
int get_file_size_from_fs_path (const char *filename_cpak)
 Get the file size from a Controller Pak file system path.
 
void unmount_all_cpakfs ()
 Unmount all Controller Pak file systems.
 
int inc_index_note (int current_index)
 Increment a note index, wrapping around MAX_NUM_NOTES.
 
int dec_index_note (int current_index)
 Decrement a note index, wrapping around MAX_NUM_NOTES.
 
int mount_cpakfs (int controller)
 Mount the Controller Pak file system for a given controller.
 
int extract_title_from_absolute_path (const char *path, char *outbuf, size_t outbuf_size)
 Extract the title from an absolute file path.
 
int parse_cpakfs_fullname (const char *fullname, cpakfs_path_strings_t *out)
 Parse a Controller Pak full filename into its components.
 
int pick_unique_fullname_with_mount (const char *mount_prefix, const char *desired_name, char *out_fullpath, size_t outsz, int(*exists_fullpath)(const char *fullpath))
 Pick a unique full filename with mount prefix, avoiding collisions.
 
int file_exists_full (const char *full_mounted_path)
 Check if a file exists at the given full mounted path.
 

Variables

const char *const CPAK_MOUNT_ARRAY [4]
 Array of Controller Pak mount point strings.
 

Detailed Description

Implementation of Controller Pak file system utilities.

Function Documentation

◆ has_cpak()

bool has_cpak ( int controller)

Check if a Controller Pak is present in the given controller.

Parameters
controllerThe controller index (0-3).
Returns
true if a Controller Pak is present, false otherwise.

◆ get_block_size_from_fs_path()

int get_block_size_from_fs_path ( const char * filename_cpak)

Get the block size from a Controller Pak file system path.

Parameters
filename_cpakThe Controller Pak file path.
Returns
The block size, or -1 on error.

◆ get_file_size_from_fs_path()

int get_file_size_from_fs_path ( const char * filename_cpak)

Get the file size from a Controller Pak file system path.

Parameters
filename_cpakThe Controller Pak file path.
Returns
The file size in bytes, or -1 on error.

◆ inc_index_note()

int inc_index_note ( int current_index)

Increment a note index, wrapping around MAX_NUM_NOTES.

Parameters
current_indexThe current note index.
Returns
The incremented note index.

◆ dec_index_note()

int dec_index_note ( int current_index)

Decrement a note index, wrapping around MAX_NUM_NOTES.

Parameters
current_indexThe current note index.
Returns
The decremented note index.

◆ mount_cpakfs()

int mount_cpakfs ( int controller)

Mount the Controller Pak file system for a given controller.

Parameters
controllerThe controller index (0-3).
Returns
0 on success, -1 on failure.

◆ extract_title_from_absolute_path()

int extract_title_from_absolute_path ( const char * path,
char * outbuf,
size_t outbuf_size )

Extract the title from an absolute file path.

The title is the filename up to the first underscore or dot, or the whole filename if neither is present.

Parameters
pathThe absolute file path.
outbufOutput buffer for the title.
outbuf_sizeSize of the output buffer.
Returns
0 on success, negative value on error.

◆ parse_cpakfs_fullname()

int parse_cpakfs_fullname ( const char * fullname,
cpakfs_path_strings_t * out )

Parse a Controller Pak full filename into its components.

Parameters
fullnameThe full filename string.
outOutput struct for parsed components.
Returns
0 on success, negative value on error.

◆ pick_unique_fullname_with_mount()

int pick_unique_fullname_with_mount ( const char * mount_prefix,
const char * desired_name,
char * out_fullpath,
size_t outsz,
int(* exists_fullpath )(const char *fullpath) )

Pick a unique full filename with mount prefix, avoiding collisions.

This function attempts to find a unique filename by incrementing the extension in base36 if needed.

Parameters
mount_prefixThe mount prefix (e.g., "cpak1:/").
desired_nameThe desired base filename.
out_fullpathOutput buffer for the unique full path.
outszSize of the output buffer.
exists_fullpathFunction pointer to check if a full path exists.
Returns
0 on success, negative value on error.

◆ file_exists_full()

int file_exists_full ( const char * full_mounted_path)

Check if a file exists at the given full mounted path.

Parameters
full_mounted_pathThe full mounted file path.
Returns
1 if the file exists, 0 otherwise.

Variable Documentation

◆ CPAK_MOUNT_ARRAY

const char* const CPAK_MOUNT_ARRAY[4]
Initial value:
= {
"cpak1:/", "cpak2:/", "cpak3:/", "cpak4:/"
}

Array of Controller Pak mount point strings.

Array of Controller Pak mount point strings (e.g., "cpak1:/").