From fdff5b78dedf9ec73eab571acd64addb7b4a64b2 Mon Sep 17 00:00:00 2001 From: Extrems Date: Fri, 8 Nov 2024 17:52:41 -0500 Subject: [PATCH] Pass DISC_INTERFACE to interface --- gc/di/di.h | 2 +- gc/iso9660.h | 4 ++-- gc/ogc/disc_io.h | 16 ++++++++-------- libdi/di.c | 14 +++++++------- libiso9660/iso9660.c | 20 ++++++++++---------- libogc/dvd.c | 30 +++++++++++++++--------------- libogc/gcsd.c | 44 ++++++++++++++++++++++---------------------- libogc/usbstorage.c | 14 +++++++------- libogc/wiisd.c | 24 ++++++++++++------------ 9 files changed, 84 insertions(+), 84 deletions(-) diff --git a/gc/di/di.h b/gc/di/di.h index 53752ef7..a67cfe07 100644 --- a/gc/di/di.h +++ b/gc/di/di.h @@ -88,7 +88,7 @@ typedef int(*read_func)(void*,uint32_t,uint32_t); typedef int(*read_func_async)(void*,uint32_t,uint32_t,ipccallback); extern int di_fd; -extern const DISC_INTERFACE __io_wiidvd; +extern DISC_INTERFACE __io_wiidvd; int DI_Init(void); void DI_LoadDVDX(bool load); diff --git a/gc/iso9660.h b/gc/iso9660.h index 498cf9ae..3d95e4e7 100644 --- a/gc/iso9660.h +++ b/gc/iso9660.h @@ -16,8 +16,8 @@ extern "C" { #endif -bool ISO9660_Mount(const char* name, const DISC_INTERFACE* disc_interface); -bool ISO9660_Unmount(const char* name); +bool ISO9660_Mount(const char *name, DISC_INTERFACE *disc_interface); +bool ISO9660_Unmount(const char *name); const char *ISO9660_GetVolumeLabel(const char *name); #ifdef __cplusplus diff --git a/gc/ogc/disc_io.h b/gc/ogc/disc_io.h index 6dfebab8..722991f5 100644 --- a/gc/ogc/disc_io.h +++ b/gc/ogc/disc_io.h @@ -46,12 +46,14 @@ typedef uint64_t sec_t; -typedef bool (* FN_MEDIUM_STARTUP)(void) ; -typedef bool (* FN_MEDIUM_ISINSERTED)(void) ; -typedef bool (* FN_MEDIUM_READSECTORS)(sec_t sector, sec_t numSectors, void* buffer) ; -typedef bool (* FN_MEDIUM_WRITESECTORS)(sec_t sector, sec_t numSectors, const void* buffer) ; -typedef bool (* FN_MEDIUM_CLEARSTATUS)(void) ; -typedef bool (* FN_MEDIUM_SHUTDOWN)(void) ; +typedef struct DISC_INTERFACE_STRUCT DISC_INTERFACE ; + +typedef bool (* FN_MEDIUM_STARTUP)(DISC_INTERFACE* disc) ; +typedef bool (* FN_MEDIUM_ISINSERTED)(DISC_INTERFACE* disc) ; +typedef bool (* FN_MEDIUM_READSECTORS)(DISC_INTERFACE* disc, sec_t sector, sec_t numSectors, void* buffer) ; +typedef bool (* FN_MEDIUM_WRITESECTORS)(DISC_INTERFACE* disc, sec_t sector, sec_t numSectors, const void* buffer) ; +typedef bool (* FN_MEDIUM_CLEARSTATUS)(DISC_INTERFACE* disc) ; +typedef bool (* FN_MEDIUM_SHUTDOWN)(DISC_INTERFACE* disc) ; struct DISC_INTERFACE_STRUCT { unsigned long ioType ; @@ -64,6 +66,4 @@ struct DISC_INTERFACE_STRUCT { FN_MEDIUM_SHUTDOWN shutdown ; } ; -typedef struct DISC_INTERFACE_STRUCT DISC_INTERFACE ; - #endif // define OGC_DISC_IO_INCLUDE diff --git a/libdi/di.c b/libdi/di.c index 9b0bf694..8ea38fb0 100644 --- a/libdi/di.c +++ b/libdi/di.c @@ -915,7 +915,7 @@ int DI_ReadDiscID(uint64_t *id) return(ret == 1)? 0 : -ret; } -static bool diio_Startup(void) +static bool diio_Startup(DISC_INTERFACE *disc) { u64 t1,t2; @@ -939,7 +939,7 @@ static bool diio_Startup(void) return false; } -static bool diio_IsInserted(void) +static bool diio_IsInserted(DISC_INTERFACE *disc) { u32 val; @@ -953,7 +953,7 @@ static bool diio_IsInserted(void) return false; } -static bool diio_ReadSectors(sec_t sector,sec_t numSectors,void *buffer) +static bool diio_ReadSectors(DISC_INTERFACE *disc, sec_t sector, sec_t numSectors, void *buffer) { if((uint32_t)sector != sector) return false; @@ -966,23 +966,23 @@ static bool diio_ReadSectors(sec_t sector,sec_t numSectors,void *buffer) return false; } -static bool diio_WriteSectors(sec_t sector,sec_t numSectors,const void *buffer) +static bool diio_WriteSectors(DISC_INTERFACE *disc, sec_t sector, sec_t numSectors, const void *buffer) { return false; } -static bool diio_ClearStatus(void) +static bool diio_ClearStatus(DISC_INTERFACE *disc) { return true; } -static bool diio_Shutdown(void) +static bool diio_Shutdown(DISC_INTERFACE *disc) { DI_StopMotor(); return true; } -const DISC_INTERFACE __io_wiidvd = { +DISC_INTERFACE __io_wiidvd = { DEVICE_TYPE_WII_DVD, FEATURE_MEDIUM_CANREAD | FEATURE_WII_DVD, diio_Startup, diff --git a/libiso9660/iso9660.c b/libiso9660/iso9660.c index f689d357..f11b22c3 100644 --- a/libiso9660/iso9660.c +++ b/libiso9660/iso9660.c @@ -79,7 +79,7 @@ typedef struct dentry_s typedef struct iso9660mount_s { - const DISC_INTERFACE *disc_interface; + DISC_INTERFACE *disc_interface; u8 read_buffer[BUFFER_SIZE] __attribute__((aligned(32))); u8 cluster_buffer[BUFFER_SIZE] __attribute__((aligned(32))); u32 cache_start; @@ -118,7 +118,7 @@ static int __read(MOUNT_DESCR *mdescr, void *ptr, u64 offset, size_t len) u32 end_sector = (offset + len - 1) / SECTOR_SIZE; u32 sectors = MIN(BUFFER_SIZE / SECTOR_SIZE, end_sector - sector + 1); u32 sector_offset = offset % SECTOR_SIZE; - const DISC_INTERFACE *disc = mdescr->disc_interface; + DISC_INTERFACE *disc = mdescr->disc_interface; len = MIN(BUFFER_SIZE - sector_offset, len); if (mdescr->cache_sectors && sector >= mdescr->cache_start && (sector + sectors) <= (mdescr->cache_start + mdescr->cache_sectors)) @@ -127,7 +127,7 @@ static int __read(MOUNT_DESCR *mdescr, void *ptr, u64 offset, size_t len) return len; } - if (!disc->readSectors(sector, BUFFER_SIZE / SECTOR_SIZE, mdescr->read_buffer)) + if (!disc->readSectors(disc, sector, BUFFER_SIZE / SECTOR_SIZE, mdescr->read_buffer)) { mdescr->cache_sectors = 0; return -1; @@ -847,11 +847,11 @@ static void cleanup_recursive(PATH_ENTRY *entry) static struct pvd_s* read_volume_descriptor(MOUNT_DESCR *mdescr, u8 descriptor) { u8 sector; - const DISC_INTERFACE *disc = mdescr->disc_interface; + DISC_INTERFACE *disc = mdescr->disc_interface; for (sector = 16; sector < 32; sector++) { - if (!disc->readSectors(sector, 1, mdescr->read_buffer)) + if (!disc->readSectors(disc, sector, 1, mdescr->read_buffer)) return NULL; if (!memcmp(mdescr->read_buffer + 1, "CD001\1", 6)) { @@ -928,7 +928,7 @@ static bool read_directories(MOUNT_DESCR *mdescr) return true; } -static MOUNT_DESCR *_ISO9660_mdescr_constructor(const DISC_INTERFACE *disc_interface) +static MOUNT_DESCR *_ISO9660_mdescr_constructor(DISC_INTERFACE *disc_interface) { MOUNT_DESCR *mdescr = NULL; @@ -951,7 +951,7 @@ static MOUNT_DESCR *_ISO9660_mdescr_constructor(const DISC_INTERFACE *disc_inter return mdescr; } -bool ISO9660_Mount(const char* name, const DISC_INTERFACE *disc_interface) +bool ISO9660_Mount(const char *name, DISC_INTERFACE *disc_interface) { char *nameCopy; devoptab_t *devops = NULL; @@ -961,10 +961,10 @@ bool ISO9660_Mount(const char* name, const DISC_INTERFACE *disc_interface) if (!name || strlen(name) > 8 || !disc_interface) return false; - if (!disc_interface->startup()) + if (!disc_interface->startup(disc_interface)) return false; - if (!disc_interface->isInserted()) + if (!disc_interface->isInserted(disc_interface)) return false; sprintf(devname, "%s:", name); @@ -1002,7 +1002,7 @@ bool ISO9660_Mount(const char* name, const DISC_INTERFACE *disc_interface) } -bool ISO9660_Unmount(const char* name) +bool ISO9660_Unmount(const char *name) { devoptab_t *devops; MOUNT_DESCR *mdescr; diff --git a/libogc/dvd.c b/libogc/dvd.c index a1f18b46..e1ab6879 100644 --- a/libogc/dvd.c +++ b/libogc/dvd.c @@ -3558,7 +3558,7 @@ u32 DVD_SetAutoInvalidation(u32 auto_inv) return ret; } -static bool __gcdvd_Startup(void) +static bool __gcdvd_Startup(DISC_INTERFACE *disc) { DVD_Init(); @@ -3574,7 +3574,7 @@ static bool __gcdvd_Startup(void) return true; } -static bool __gcdvd_IsInserted(void) +static bool __gcdvd_IsInserted(DISC_INTERFACE *disc) { u32 status = 0; DVD_LowGetStatus(&status, NULL); @@ -3585,7 +3585,7 @@ static bool __gcdvd_IsInserted(void) return false; } -static bool __gcdvd_ReadSectors(sec_t sector,sec_t numSectors,void *buffer) +static bool __gcdvd_ReadSectors(DISC_INTERFACE *disc,sec_t sector,sec_t numSectors,void *buffer) { dvdcmdblk blk; @@ -3599,24 +3599,24 @@ static bool __gcdvd_ReadSectors(sec_t sector,sec_t numSectors,void *buffer) return true; } -static bool __gcdvd_WriteSectors(sec_t sector,sec_t numSectors,const void *buffer) +static bool __gcdvd_WriteSectors(DISC_INTERFACE *disc,sec_t sector,sec_t numSectors,const void *buffer) { return false; } -static bool __gcdvd_ClearStatus(void) +static bool __gcdvd_ClearStatus(DISC_INTERFACE *disc) { return true; } -static bool __gcdvd_Shutdown(void) +static bool __gcdvd_Shutdown(DISC_INTERFACE *disc) { dvdcmdblk blk; DVD_StopMotor(&blk); return true; } -static bool __gcode_Startup(void) +static bool __gcode_Startup(DISC_INTERFACE *disc) { dvdcmdblk blk; @@ -3629,16 +3629,16 @@ static bool __gcode_Startup(void) return false; if(__dvd_driveinfo.pad[1] == 'w') - __io_gcode.features |= FEATURE_MEDIUM_CANWRITE; + disc->features |= FEATURE_MEDIUM_CANWRITE; else - __io_gcode.features &= ~FEATURE_MEDIUM_CANWRITE; + disc->features &= ~FEATURE_MEDIUM_CANWRITE; __dvd_gcode_writebufsize = __dvd_driveinfo.pad[3] + 1; return true; } -static bool __gcode_IsInserted(void) +static bool __gcode_IsInserted(DISC_INTERFACE *disc) { if(DVD_LowGetCoverStatus() == 1) return false; @@ -3646,7 +3646,7 @@ static bool __gcode_IsInserted(void) return true; } -static bool __gcode_ReadSectors(sec_t sector,sec_t numSectors,void *buffer) +static bool __gcode_ReadSectors(DISC_INTERFACE *disc,sec_t sector,sec_t numSectors,void *buffer) { dvdcmdblk blk; @@ -3660,11 +3660,11 @@ static bool __gcode_ReadSectors(sec_t sector,sec_t numSectors,void *buffer) return true; } -static bool __gcode_WriteSectors(sec_t sector,sec_t numSectors,const void *buffer) +static bool __gcode_WriteSectors(DISC_INTERFACE *disc,sec_t sector,sec_t numSectors,const void *buffer) { dvdcmdblk blk; - if(!(__io_gcode.features & FEATURE_MEDIUM_CANWRITE)) return false; + if(!(disc->features & FEATURE_MEDIUM_CANWRITE)) return false; if((u32)sector != sector) return false; if((u32)numSectors != numSectors) return false; if(!SYS_IsDMAAddress(buffer)) return false; @@ -3675,12 +3675,12 @@ static bool __gcode_WriteSectors(sec_t sector,sec_t numSectors,const void *buffe return true; } -static bool __gcode_ClearStatus(void) +static bool __gcode_ClearStatus(DISC_INTERFACE *disc) { return true; } -static bool __gcode_Shutdown(void) +static bool __gcode_Shutdown(DISC_INTERFACE *disc) { return true; } diff --git a/libogc/gcsd.c b/libogc/gcsd.c index 8f022d2a..ad2e8c3f 100644 --- a/libogc/gcsd.c +++ b/libogc/gcsd.c @@ -123,108 +123,108 @@ static bool __gcsd_shutdown(int n) } -static bool __gcsda_startup(void) +static bool __gcsda_startup(DISC_INTERFACE *disc) { bool ret; ret = __gcsd_startup(0); if(sdgecko_getDevice(0) == EXI_DEVICE_0) { - __io_gcsda.features |= FEATURE_GAMECUBE_SLOTA; - __io_gcsda.features &= ~FEATURE_GAMECUBE_PORT1; + disc->features |= FEATURE_GAMECUBE_SLOTA; + disc->features &= ~FEATURE_GAMECUBE_PORT1; } else { - __io_gcsda.features |= FEATURE_GAMECUBE_PORT1; - __io_gcsda.features &= ~FEATURE_GAMECUBE_SLOTA; + disc->features |= FEATURE_GAMECUBE_PORT1; + disc->features &= ~FEATURE_GAMECUBE_SLOTA; } return ret; } -static bool __gcsda_isInserted(void) +static bool __gcsda_isInserted(DISC_INTERFACE *disc) { return __gcsd_isInserted(0); } -static bool __gcsda_readSectors(sec_t sector, sec_t numSectors, void *buffer) +static bool __gcsda_readSectors(DISC_INTERFACE *disc, sec_t sector, sec_t numSectors, void *buffer) { return __gcsd_readSectors(0, sector, numSectors, buffer); } -static bool __gcsda_writeSectors(sec_t sector, sec_t numSectors, const void *buffer) +static bool __gcsda_writeSectors(DISC_INTERFACE *disc, sec_t sector, sec_t numSectors, const void *buffer) { return __gcsd_writeSectors(0, sector, numSectors, buffer); } -static bool __gcsda_clearStatus(void) +static bool __gcsda_clearStatus(DISC_INTERFACE *disc) { return __gcsd_clearStatus(0); } -static bool __gcsda_shutdown(void) +static bool __gcsda_shutdown(DISC_INTERFACE *disc) { return __gcsd_shutdown(0); } -static bool __gcsdb_startup(void) +static bool __gcsdb_startup(DISC_INTERFACE *disc) { return __gcsd_startup(1); } -static bool __gcsdb_isInserted(void) +static bool __gcsdb_isInserted(DISC_INTERFACE *disc) { return __gcsd_isInserted(1); } -static bool __gcsdb_readSectors(sec_t sector, sec_t numSectors, void *buffer) +static bool __gcsdb_readSectors(DISC_INTERFACE *disc, sec_t sector, sec_t numSectors, void *buffer) { return __gcsd_readSectors(1, sector, numSectors, buffer); } -static bool __gcsdb_writeSectors(sec_t sector, sec_t numSectors, const void *buffer) +static bool __gcsdb_writeSectors(DISC_INTERFACE *disc, sec_t sector, sec_t numSectors, const void *buffer) { return __gcsd_writeSectors(1, sector, numSectors, buffer); } -static bool __gcsdb_clearStatus(void) +static bool __gcsdb_clearStatus(DISC_INTERFACE *disc) { return __gcsd_clearStatus(1); } -static bool __gcsdb_shutdown(void) +static bool __gcsdb_shutdown(DISC_INTERFACE *disc) { return __gcsd_shutdown(1); } -static bool __gcsd2_startup(void) +static bool __gcsd2_startup(DISC_INTERFACE *disc) { return __gcsd_startup(2); } -static bool __gcsd2_isInserted(void) +static bool __gcsd2_isInserted(DISC_INTERFACE *disc) { return __gcsd_isInserted(2); } -static bool __gcsd2_readSectors(sec_t sector, sec_t numSectors, void *buffer) +static bool __gcsd2_readSectors(DISC_INTERFACE *disc, sec_t sector, sec_t numSectors, void *buffer) { return __gcsd_readSectors(2, sector, numSectors, buffer); } -static bool __gcsd2_writeSectors(sec_t sector, sec_t numSectors, const void *buffer) +static bool __gcsd2_writeSectors(DISC_INTERFACE *disc, sec_t sector, sec_t numSectors, const void *buffer) { return __gcsd_writeSectors(2, sector, numSectors, buffer); } -static bool __gcsd2_clearStatus(void) +static bool __gcsd2_clearStatus(DISC_INTERFACE *disc) { return __gcsd_clearStatus(2); } -static bool __gcsd2_shutdown(void) +static bool __gcsd2_shutdown(DISC_INTERFACE *disc) { return __gcsd_shutdown(2); } diff --git a/libogc/usbstorage.c b/libogc/usbstorage.c index 8dd13d7d..f69eadab 100644 --- a/libogc/usbstorage.c +++ b/libogc/usbstorage.c @@ -858,7 +858,7 @@ The following is for implementing a DISC_INTERFACE as used by libfat */ -static bool __usbstorage_Startup(void) +static bool __usbstorage_Startup(DISC_INTERFACE *disc) { if(USB_Initialize() < 0 || USBStorage_Initialize() < 0) return false; @@ -866,7 +866,7 @@ static bool __usbstorage_Startup(void) return true; } -static bool __usbstorage_IsInserted(void) +static bool __usbstorage_IsInserted(DISC_INTERFACE *disc) { usb_device_entry *buffer; u8 device_count; @@ -969,7 +969,7 @@ static bool __usbstorage_IsInserted(void) return __mounted; } -static bool __usbstorage_ReadSectors(sec_t sector, sec_t numSectors, void *buffer) +static bool __usbstorage_ReadSectors(DISC_INTERFACE *disc, sec_t sector, sec_t numSectors, void *buffer) { s32 retval; @@ -981,7 +981,7 @@ static bool __usbstorage_ReadSectors(sec_t sector, sec_t numSectors, void *buffe return retval >= 0; } -static bool __usbstorage_WriteSectors(sec_t sector, sec_t numSectors, const void *buffer) +static bool __usbstorage_WriteSectors(DISC_INTERFACE *disc, sec_t sector, sec_t numSectors, const void *buffer) { s32 retval; @@ -993,12 +993,12 @@ static bool __usbstorage_WriteSectors(sec_t sector, sec_t numSectors, const void return retval >= 0; } -static bool __usbstorage_ClearStatus(void) +static bool __usbstorage_ClearStatus(DISC_INTERFACE *disc) { return true; } -static bool __usbstorage_Shutdown(void) +static bool __usbstorage_Shutdown(DISC_INTERFACE *disc) { if (__vid != 0 || __pid != 0) USBStorage_Close(&__usbfd); @@ -1008,7 +1008,7 @@ static bool __usbstorage_Shutdown(void) void USBStorage_Deinitialize(void) { - __usbstorage_Shutdown(); + __usbstorage_Shutdown(&__io_usbstorage); LWP_CloseQueue(__usbstorage_waitq); __inited = false; } diff --git a/libogc/wiisd.c b/libogc/wiisd.c index b94ae898..ea9975da 100644 --- a/libogc/wiisd.c +++ b/libogc/wiisd.c @@ -377,7 +377,7 @@ static s32 __sd0_getcid(void) } -static bool __sd0_initio(void) +static bool __sd0_initio(DISC_INTERFACE *disc) { s32 ret; s32 tries; @@ -391,9 +391,9 @@ static bool __sd0_initio(void) return false; if(!(status & SDIO_STATUS_CARD_LOCKED)) - __io_wiisd.features |= FEATURE_MEDIUM_CANWRITE; + disc->features |= FEATURE_MEDIUM_CANWRITE; else - __io_wiisd.features &= ~FEATURE_MEDIUM_CANWRITE; + disc->features &= ~FEATURE_MEDIUM_CANWRITE; if(!(status & SDIO_STATUS_CARD_INITIALIZED)) { @@ -511,7 +511,7 @@ static bool sdio_Deinitialize(void) return true; } -static bool sdio_Startup(void) +static bool sdio_Startup(DISC_INTERFACE *disc) { if(__sdio_initialized==1) return true; @@ -522,15 +522,15 @@ static bool sdio_Startup(void) return false; } - if(__sd0_initio()==false) { + if(__sd0_initio(disc)==false) { sdio_Deinitialize(); return false; } __sdio_initialized = 1; return true; } - -static bool sdio_Shutdown(void) + +static bool sdio_Shutdown(DISC_INTERFACE *disc) { if(__sd0_initialized==0) return false; @@ -540,7 +540,7 @@ static bool sdio_Shutdown(void) return true; } -static bool sdio_ReadSectors(sec_t sector, sec_t numSectors,void* buffer) +static bool sdio_ReadSectors(DISC_INTERFACE *disc, sec_t sector, sec_t numSectors, void *buffer) { s32 ret; u32 sec; @@ -574,14 +574,14 @@ static bool sdio_ReadSectors(sec_t sector, sec_t numSectors,void* buffer) return (ret>=0); } -static bool sdio_WriteSectors(sec_t sector, sec_t numSectors,const void* buffer) +static bool sdio_WriteSectors(DISC_INTERFACE *disc, sec_t sector, sec_t numSectors, const void *buffer) { s32 ret; u32 sec; u32 secs_to_write; u8 *src = (u8*)buffer; - if(!(__io_wiisd.features & FEATURE_MEDIUM_CANWRITE)) return false; + if(!(disc->features & FEATURE_MEDIUM_CANWRITE)) return false; if((u32)sector != sector) return false; if((u32)numSectors != numSectors) return false; if(!SYS_IsDMAAddress(buffer)) return false; @@ -609,12 +609,12 @@ static bool sdio_WriteSectors(sec_t sector, sec_t numSectors,const void* buffer) return (ret>=0); } -static bool sdio_ClearStatus(void) +static bool sdio_ClearStatus(DISC_INTERFACE *disc) { return true; } -static bool sdio_IsInserted(void) +static bool sdio_IsInserted(DISC_INTERFACE *disc) { return ((__sdio_getstatus() & SDIO_STATUS_CARD_INSERTED) == SDIO_STATUS_CARD_INSERTED);