libgui 2.01
libgui is a GUI library for the GameCube, Wii, and Wii U
 
Loading...
Searching...
No Matches
WiiFileSystemDriver.cpp
1/****************************************************************************
2 * Platform Abstraction Layer (OGC driver)
3 * Daryl Borth 2026
4 * WiiFileSystemDriver.cpp
5 *
6 * Wii storage device enumeration + mounting: SD, up to 3 concurrent USB
7 * mass storage devices (via WiiUsbMulti / IOS58), and DVD. SD and USB are
8 * hot-pluggable and polled every cycle (see OgcFatSlotDescriptor::pollable
9 * in the table below); DVD deliberately is not - see
10 * OgcFileSystemDriver's class comment.
11 ***************************************************************************/
12#include <sdcard/wiisd_io.h>
13#include <ogc/usb.h>
14#include <ogc/usbstorage.h>
15#include <di/di.h>
16
17#include "WiiFileSystemDriver.h"
18#include "WiiUsbMulti.h"
19
20static DISC_INTERFACE * GetDiscSd() { return &__io_wiisd; }
21static DISC_INTERFACE * GetDiscUsb1() { return WiiUsbMulti::getInterface(0); }
22static DISC_INTERFACE * GetDiscUsb2() { return WiiUsbMulti::getInterface(1); }
23static DISC_INTERFACE * GetDiscUsb3() { return WiiUsbMulti::getInterface(2); }
24
25static const OgcFatSlotDescriptor wiiFatSlots[] =
26{
27 { DEVICE_SD, GetDiscSd, "sd", "sd:/", "SD Card", "SD card not found!", true, true, true },
28 { DEVICE_USB, GetDiscUsb1, "usb", "usb:/", "USB Mass Storage", "USB drive not found!", true, true, true },
29 { DEVICE_USB2, GetDiscUsb2, "usb2", "usb2:/", "USB Mass Storage 2", "USB drive 2 not found!", true, true, true },
30 { DEVICE_USB3, GetDiscUsb3, "usb3", "usb3:/", "USB Mass Storage 3", "USB drive 3 not found!", true, true, true },
31};
32
34{
35 DI_Init();
36 USB_Initialize();
37 USBStorage_Initialize();
38 WiiUsbMulti::init();
39 WiiUsbMulti::scan(); // populate initial slot state before the auto-mount pass below
40
41 fatSlots = wiiFatSlots;
42 fatSlotCount = sizeof(wiiFatSlots) / sizeof(wiiFatSlots[0]);
43 dvdDisc = &__io_wiidvd;
44 unsupportedFormatMessage = "Unsupported format - FAT32 is recommended.";
45
46 smbDriver.init();
47
49}
50
52{
53 WiiUsbMulti::shutdown();
54 USBStorage_Deinitialize();
55 DI_Close();
56}
57
59{
60 // Rescan attached USB mass storage devices and capture topology
61 // changes - this must run before the shared per-slot presence check
62 // in OgcFileSystemDriver::pollStorageDevices(), since GetDiscUsb1/2/3()
63 // above resolve through WiiUsbMulti::getInterface(), which this updates.
64 return WiiUsbMulti::scan();
65}
66
68{
69 // A drive inserted between poll cycles has no open WiiUsbMulti slot yet
70 if(deviceId == DEVICE_USB || deviceId == DEVICE_USB2 || deviceId == DEVICE_USB3)
71 WiiUsbMulti::scan();
72}
73
74const int * WiiFileSystemDriver::getValidLoadDevices(int & outCount) const
75{
76 static const int devices[] = { DEVICE_AUTO, DEVICE_SD, DEVICE_USB, DEVICE_USB2, DEVICE_USB3, DEVICE_DVD, DEVICE_SMB };
77 outCount = sizeof(devices) / sizeof(devices[0]);
78 return devices;
79}
80
81const int * WiiFileSystemDriver::getValidSaveDevices(int & outCount) const
82{
83 static const int devices[] = { DEVICE_AUTO, DEVICE_SD, DEVICE_USB, DEVICE_USB2, DEVICE_USB3, DEVICE_SMB };
84 outCount = sizeof(devices) / sizeof(devices[0]);
85 return devices;
86}
const OgcFatSlotDescriptor * fatSlots
Table of FAT slots this platform supports; set by the concrete driver.
void initFatSlotsAndAutoMount()
Runs the shared boot-time pass: probe every pollable fatSlots[] entry once for isPresentCache,...
const char * unsupportedFormatMessage
Text returned by mountResultMessage() when a present device fails to mount.
int fatSlotCount
Number of entries in fatSlots.
DISC_INTERFACE * dvdDisc
Disc interface used to mount the DVD drive, or nullptr if the platform has none.
OgcSmbDriver smbDriver
The network-share driver returned by getSmb()
void shutdownPlatform() override
Platform-specific extra teardown beyond the shared per-slot fatUnmount() pass (eg.
void prepareMount(int deviceId) override
Platform-specific work that must run immediately before a user-initiated mount attempt on deviceId,...
const int * getValidSaveDevices(int &outCount) const override
Devices (Device enum values, in priority order) that are offered when choosing where to save to on th...
void init() override
Initializes the driver and auto-mounts devices flagged autoMountAtStartup.
const int * getValidLoadDevices(int &outCount) const override
Devices (Device enum values, in priority order) that are offered when choosing where to load from on ...
bool pollPlatformExtra() override
Platform-specific extra polling that must run before the shared per-slot presence check (eg.
One hot-pluggable FAT-formatted slot, shared shape between GameCube (SD Gecko A/B/port2,...