libgui 2.01
libgui is a GUI library for the GameCube, Wii, and Wii U
 
Loading...
Searching...
No Matches
FileSystemDriver.h
1/****************************************************************************
2 * Platform Abstraction Layer
3 * Daryl Borth 2026
4 * FileSystemDriver.h
5 ***************************************************************************/
6#pragma once
7#include <stddef.h>
8#include <stdio.h>
9
10#include "SmbDriver.h"
11#include "Mutex.h"
12
13#define MAX_STORAGE_DEVICES 16
14
19{
20 DEVICE_AUTO = 0,
21 DEVICE_SD,
22 DEVICE_USB,
23 DEVICE_USB2,
24 DEVICE_USB3,
25 DEVICE_DVD,
26 DEVICE_SMB,
30 DEVICE_SD_GCLOADER,
31 DEVICE_LENGTH
32};
33
37{
38 int id;
39 char prefix[32];
40 char name[20];
41 char volumeLabel[16];
42 bool removable;
45};
46
49enum class MountResult
50{
51 Success,
54};
55
61{
62 public:
63 virtual ~FileSystemDriver() = default;
64
66 virtual void init() = 0;
68 virtual void shutdown() = 0;
69
71 virtual int enumerateStorageDevices(StorageDevice outDevices[MAX_STORAGE_DEVICES]) = 0;
72
75 virtual MountResult mountStorageDevice(int deviceId) = 0;
76
79 virtual const char * mountResultMessage(int deviceId, MountResult result) = 0;
80
84 virtual void invalidateStorageDevice(int deviceId) = 0;
85
92 virtual void pollStorageDevices(int removedIds[MAX_STORAGE_DEVICES], int & outRemovedCount, bool & deviceListChanged) = 0;
93
95 virtual bool hasRemovableStorageDevices() const = 0;
96
100 virtual bool isDevicePresent(int deviceId) const = 0;
101
104 virtual const char * getDevicePrefix(int device) const = 0;
105
110 virtual const char * getMountPath(int device) const = 0;
111
114 template<size_t N>
115 void getPath(char (&out)[N], int device, const char * suffix) const
116 {
117 getPath(out, N, device, suffix);
118 }
119
121 template<size_t N>
122 void getPath(char (&out)[N], int device, const char * folder, const char * file) const
123 {
124 getPath(out, N, device, folder, file);
125 }
126
130 void getPath(char * out, size_t outSize, int device, const char * suffix) const
131 {
132 const char * mp = getMountPath(device);
133 snprintf(out, outSize, "%s%s", mp ? mp : "", suffix ? suffix : "");
134 }
135
137 void getPath(char * out, size_t outSize, int device, const char * folder, const char * file) const
138 {
139 snprintf(out, outSize, "%s%s/%s", getMountPath(device), folder ? folder : "", file ? file : "");
140 }
141
145 virtual const int * getValidLoadDevices(int & outCount) const = 0;
150 virtual const int * getValidSaveDevices(int & outCount) const = 0;
151
153 virtual SmbDriver * getSmb() = 0;
154};
155
158inline const char * FindFirstMountedPath(FileSystemDriver * fs, const int * candidates, int count)
159{
160 for(int i = 0; i < count; i++)
161 {
162 const char * path = fs->getMountPath(candidates[i]);
163 if(path && path[0] != '\0')
164 return path;
165 }
166 return "";
167}
Storage device enumeration/mount/poll backend for the SD/USB/DVD file browser.
virtual const char * mountResultMessage(int deviceId, MountResult result)=0
A short, user-displayable reason for a non-Success MountResult (eg.
virtual const char * getMountPath(int device) const =0
devoptab-style mount path for device (eg.
virtual void pollStorageDevices(int removedIds[MAX_STORAGE_DEVICES], int &outRemovedCount, bool &deviceListChanged)=0
Called once per device-checking thread cycle.
virtual bool hasRemovableStorageDevices() const =0
Whether the device-checking thread should run on this platform.
void getPath(char *out, size_t outSize, int device, const char *suffix) const
Explicit-size equivalents of the two templates above, for call sites where the destination buffer arr...
void getPath(char(&out)[N], int device, const char *suffix) const
Writes getMountPath(device) + suffix into out (bounds-checked to sizeof(out) via the array-reference ...
virtual const int * getValidLoadDevices(int &outCount) const =0
Devices (Device enum values, in priority order) that are offered when choosing where to load from on ...
virtual SmbDriver * getSmb()=0
virtual MountResult mountStorageDevice(int deviceId)=0
Attempts to mount deviceId exactly once.
virtual const int * getValidSaveDevices(int &outCount) const =0
Devices (Device enum values, in priority order) that are offered when choosing where to save to on th...
virtual const char * getDevicePrefix(int device) const =0
The devoptab prefix this device would use (eg.
virtual bool isDevicePresent(int deviceId) const =0
Lightweight, cached hardware-presence check for a single device - does NOT mount and does no invasive...
virtual void init()=0
Initializes the driver and auto-mounts devices flagged autoMountAtStartup.
void getPath(char *out, size_t outSize, int device, const char *folder, const char *file) const
Joins folder and file with '/' after the mount path, as in the template above.
virtual int enumerateStorageDevices(StorageDevice outDevices[MAX_STORAGE_DEVICES])=0
Fills outDevices (size MAX_STORAGE_DEVICES) and returns the device count.
virtual void invalidateStorageDevice(int deviceId)=0
Marks deviceId as needing a fresh mount next time mountStorageDevice() is called, eg.
void getPath(char(&out)[N], int device, const char *folder, const char *file) const
Joins a folder and a filename with '/' after the mount path.
virtual void shutdown()=0
Unmounts every device and releases the driver's resources.
Network-share driver.
Definition SmbDriver.h:43
Device
Storage device kind, shared by every platform's FileSystemDriver All platforms are limited to exactly...
MountResult
Result of a single mount attempt.
@ DEVICE_SD_SLOTA
GameCube memory card slot A.
@ DEVICE_SD_SLOTB
GameCube memory card slot B.
@ DEVICE_SD_PORT2
GameCube SD Gecko in memory card slot B.
@ MountFailed
present, but couldn't be mounted (eg.
@ DeviceNotFound
not physically present / not inserted
Description of one storage device: id, display name, mount prefix, volume label and flags such as rem...
bool autoMountAtStartup
silently attempted at boot
bool removable
can this device disappear at runtime?
int id
Device enum value (DEVICE_SD, DEVICE_USB, ...)
bool alwaysListed
show in a device listing unconditionally, regardless of isDevicePresent()
char volumeLabel[16]
Volume label of the mounted filesystem, or empty if unknown.
char prefix[32]
devoptab mount prefix, eg.
char name[20]
Short display name for device lists.