diff --git a/libusbhsfs b/libusbhsfs index 2c6eaf1..d02e10f 160000 --- a/libusbhsfs +++ b/libusbhsfs @@ -1 +1 @@ -Subproject commit 2c6eaf1396f06629241d94c8cec79fc49ee24c5c +Subproject commit d02e10f3c38ee54b8b2f72343a61d8626a27d1c3 diff --git a/source/title.h b/source/title.h index 61c9174..4f5586f 100644 --- a/source/title.h +++ b/source/title.h @@ -86,7 +86,7 @@ NcmContentMetaDatabase *titleGetNcmDatabaseByStorageId(u8 storage_id); /// Returns a pointer to a ncm storage handle using a NcmStorageId value. NcmContentStorage *titleGetNcmStorageByStorageId(u8 storage_id); -/// Returns a pointer to a dynamically allocated buffer of pointers to TitleApplicationMetadata entries, as well as their count. The allocated buffer must be freed by the calling function. +/// Returns a pointer to a dynamically allocated array of pointers to TitleApplicationMetadata entries, as well as their count. The allocated buffer must be freed by the calling function. /// If 'is_system' is true, TitleApplicationMetadata entries from available system titles (NcmStorageId_BuiltInSystem) will be returned. /// Otherwise, TitleApplicationMetadata entries from user applications with available content data (NcmStorageId_Any) will be returned. /// Returns NULL if an error occurs. @@ -104,7 +104,7 @@ bool titleGetUserApplicationData(u64 app_id, TitleUserApplicationData *out); /// Orphan titles are patches or add-on contents with no NsApplicationControlData available for their parent user application ID. bool titleAreOrphanTitlesAvailable(void); -/// Returns a pointer to a dynamically allocated buffer of pointers to TitleInfo entries from orphan titles, as well as their count. The allocated buffer must be freed by the calling function. +/// Returns a pointer to a dynamically allocated array of pointers to TitleInfo entries from orphan titles, as well as their count. The allocated buffer must be freed by the calling function. /// Returns NULL if an error occurs. TitleInfo **titleGetInfoFromOrphanTitles(u32 *out_count); diff --git a/source/ums.c b/source/ums.c index 1cc18e7..840b492 100644 --- a/source/ums.c +++ b/source/ums.c @@ -113,35 +113,36 @@ bool umsIsDeviceInfoUpdated(void) return ret; } -u32 umsGetDeviceCount(void) -{ - mutexLock(&g_umsMutex); - u32 count = (g_umsInterfaceInit ? g_umsDeviceCount : 0); - mutexUnlock(&g_umsMutex); - return count; -} - -bool umsGetDeviceByIndex(u32 idx, UsbHsFsDevice *out_device) +UsbHsFsDevice *umsGetDevices(u32 *out_count) { mutexLock(&g_umsMutex); - bool ret = false; + UsbHsFsDevice *devices = NULL; - if (!g_umsInterfaceInit || !g_umsDeviceCount || !g_umsDevices || idx >= g_umsDeviceCount || !out_device) + if (!g_umsInterfaceInit || !g_umsDeviceCount || !g_umsDevices || !out_count) { LOGFILE("Invalid parameters!"); goto end; } - /* Copy device data. */ - memcpy(out_device, &(g_umsDevices[idx]), sizeof(UsbHsFsDevice)); + /* Allocate memory for the output devices. */ + devices = calloc(g_umsDeviceCount, sizeof(UsbHsFsDevice)); + if (!devices) + { + LOGFILE("Failed to allocate memory for %u devices!", g_umsDeviceCount); + goto end; + } - ret = true; + /* Copy device data. */ + memcpy(devices, g_umsDevices, g_umsDeviceCount * sizeof(UsbHsFsDevice)); + + /* Update output device count. */ + *out_count = g_umsDeviceCount; end: mutexUnlock(&g_umsMutex); - return ret; + return devices; } static bool umsCreateDetectionThread(void) diff --git a/source/ums.h b/source/ums.h index e596d78..5f2b7e5 100644 --- a/source/ums.h +++ b/source/ums.h @@ -32,10 +32,8 @@ void umsExit(void); /// Returns true if USB Mass Storage device info has been updated. bool umsIsDeviceInfoUpdated(void); -/// Returns the available USB Mass Storage device count. -u32 umsGetDeviceCount(void); - -/// Saves USB Mass Storage device info to 'out_device' using the provided index. -bool umsGetDeviceByIndex(u32 idx, UsbHsFsDevice *out_device); +/// Returns a pointer to a dynamically allocated array of UsbHsFsDevice elements. The allocated buffer must be freed by the calling function. +/// Returns NULL if an error occurs. +UsbHsFsDevice *umsGetDevices(u32 *out_count); #endif /* __UMS_H__ */