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

Utilities for working with Controller Pak file systems. More...

Go to the source code of this file.

Data Structures

struct  cpakfs_path_strings_t
 Structure holding parsed components of a Controller Pak file path. More...
 

Macros

#define FS_BLOCK_DIVIDER   (8 * 32)
 Divider constant for file system block calculations.
 
#define MAX_NUM_NOTES   16
 Maximum number of notes (files) supported on a Controller Pak.
 

Functions

int get_block_size_from_fs_path (const char *filename_cpak)
 Get the block size from a Controller Pak file system path.
 
void unmount_all_cpakfs (void)
 Unmount all Controller Pak file systems.
 
int mount_cpakfs (int controller)
 Mount the Controller Pak file system for a given controller.
 
bool has_cpak (int controller)
 Check if a Controller Pak is present in the given controller.
 
int get_file_size_from_fs_path (const char *filename_cpak)
 Get the file size from a Controller Pak file system path.
 
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 file_exists_full (const char *full_mounted_path)
 Check if a file exists at the given full mounted path.
 
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 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.
 

Variables

const char *const CPAK_MOUNT_ARRAY [4]
 Array of Controller Pak mount point strings (e.g., "cpak1:/").
 

Detailed Description

Utilities for working with Controller Pak file systems.


Data Structure Documentation

◆ cpakfs_path_strings_t

struct cpakfs_path_strings_t

Structure holding parsed components of a Controller Pak file path.

This struct contains the game code, publisher code, filename, and extension parsed from a Controller Pak file path.

Data Fields
char gamecode[5]

Game code (4 chars + null terminator)

char pubcode[5]

Publisher code (up to 4 chars + null terminator)

char filename[17]

Filename (up to 16 chars + null terminator)

char ext[5]

Extension (up to 4 chars + null terminator)

Function Documentation

◆ 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.

◆ 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.

◆ 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_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.

◆ 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.

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

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.

◆ 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.

◆ 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.

◆ 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.

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.

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.

Variable Documentation

◆ CPAK_MOUNT_ARRAY

const char* const CPAK_MOUNT_ARRAY[4]
extern

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

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