1
0
Fork 0
mirror of https://github.com/DarkMatterCore/nxdumptool.git synced 2024-11-09 20:21:45 +00:00

Improved UMS interface.

This commit is contained in:
Pablo Curiel 2020-12-23 14:43:12 -04:00
parent 736f2e155b
commit 6f43764e1b
4 changed files with 22 additions and 23 deletions

@ -1 +1 @@
Subproject commit 2c6eaf1396f06629241d94c8cec79fc49ee24c5c Subproject commit d02e10f3c38ee54b8b2f72343a61d8626a27d1c3

View file

@ -86,7 +86,7 @@ NcmContentMetaDatabase *titleGetNcmDatabaseByStorageId(u8 storage_id);
/// Returns a pointer to a ncm storage handle using a NcmStorageId value. /// Returns a pointer to a ncm storage handle using a NcmStorageId value.
NcmContentStorage *titleGetNcmStorageByStorageId(u8 storage_id); 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. /// 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. /// Otherwise, TitleApplicationMetadata entries from user applications with available content data (NcmStorageId_Any) will be returned.
/// Returns NULL if an error occurs. /// 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. /// Orphan titles are patches or add-on contents with no NsApplicationControlData available for their parent user application ID.
bool titleAreOrphanTitlesAvailable(void); 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. /// Returns NULL if an error occurs.
TitleInfo **titleGetInfoFromOrphanTitles(u32 *out_count); TitleInfo **titleGetInfoFromOrphanTitles(u32 *out_count);

View file

@ -113,35 +113,36 @@ bool umsIsDeviceInfoUpdated(void)
return ret; return ret;
} }
u32 umsGetDeviceCount(void) UsbHsFsDevice *umsGetDevices(u32 *out_count)
{
mutexLock(&g_umsMutex);
u32 count = (g_umsInterfaceInit ? g_umsDeviceCount : 0);
mutexUnlock(&g_umsMutex);
return count;
}
bool umsGetDeviceByIndex(u32 idx, UsbHsFsDevice *out_device)
{ {
mutexLock(&g_umsMutex); 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!"); LOGFILE("Invalid parameters!");
goto end; goto end;
} }
/* Copy device data. */ /* Allocate memory for the output devices. */
memcpy(out_device, &(g_umsDevices[idx]), sizeof(UsbHsFsDevice)); 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: end:
mutexUnlock(&g_umsMutex); mutexUnlock(&g_umsMutex);
return ret; return devices;
} }
static bool umsCreateDetectionThread(void) static bool umsCreateDetectionThread(void)

View file

@ -32,10 +32,8 @@ void umsExit(void);
/// Returns true if USB Mass Storage device info has been updated. /// Returns true if USB Mass Storage device info has been updated.
bool umsIsDeviceInfoUpdated(void); bool umsIsDeviceInfoUpdated(void);
/// Returns the available USB Mass Storage device count. /// Returns a pointer to a dynamically allocated array of UsbHsFsDevice elements. The allocated buffer must be freed by the calling function.
u32 umsGetDeviceCount(void); /// Returns NULL if an error occurs.
UsbHsFsDevice *umsGetDevices(u32 *out_count);
/// Saves USB Mass Storage device info to 'out_device' using the provided index.
bool umsGetDeviceByIndex(u32 idx, UsbHsFsDevice *out_device);
#endif /* __UMS_H__ */ #endif /* __UMS_H__ */