From 3071cee3bd7814bb62ca81d3febd82f2abacc2e0 Mon Sep 17 00:00:00 2001 From: Pablo Curiel Date: Thu, 29 Jun 2023 00:12:51 +0200 Subject: [PATCH] ums: implement umsUnmountDevice Other changes include: * libs: update libusbhsfs to latest commit * nxdt_rw_poc: fix UMS device unmounting, change output XCI naming scheme. --- code_templates/nxdt_rw_poc.c | 6 +++--- include/core/ums.h | 4 ++++ libs/libusbhsfs | 2 +- source/core/ums.c | 15 +++++++++++++++ 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/code_templates/nxdt_rw_poc.c b/code_templates/nxdt_rw_poc.c index b553107..e10b198 100644 --- a/code_templates/nxdt_rw_poc.c +++ b/code_templates/nxdt_rw_poc.c @@ -31,7 +31,7 @@ #define BLOCK_SIZE USB_TRANSFER_BUFFER_SIZE #define WAIT_TIME_LIMIT 30 -#define OUTDIR "nxdt_rw_poc" +#define OUTDIR APP_TITLE /* Type definitions. */ @@ -1322,7 +1322,7 @@ int main(int argc, char *argv[]) } else if ((btn_down & HidNpadButton_X) && g_umsDeviceCount) { - for(u32 i = 0; i < g_umsDeviceCount; i++) usbHsFsUnmountDevice(&(g_umsDevices[i]), false); + for(u32 i = 0; i < g_umsDeviceCount; i++) umsUnmountDevice(&(g_umsDevices[i])); updateStorageList(); } else if (((btn_down & (HidNpadButton_L)) || (btn_held & HidNpadButton_ZL)) && (cur_menu->id == MenuId_NSP || cur_menu->id == MenuId_Ticket || cur_menu->id == MenuId_Nca) && title_info->previous) @@ -2223,7 +2223,7 @@ static bool saveGameCardImage(void *userdata) consolePrint("gamecard size (with key area): 0x%lX\n", gc_size); } - snprintf(path, MAX_ELEMENTS(path), " (%s) (%s) (%s).xci", prepend_key_area ? "keyarea" : "keyarealess", keep_certificate ? "cert" : "certless", trim_dump ? "trimmed" : "untrimmed"); + snprintf(path, MAX_ELEMENTS(path), " [%s][%s][%s].xci", prepend_key_area ? "KA" : "NKA", keep_certificate ? "C" : "NC", trim_dump ? "T" : "NT"); filename = generateOutputGameCardFileName("Gamecard", path, true); if (!filename) goto end; diff --git a/include/core/ums.h b/include/core/ums.h index 0d377ff..771cca8 100644 --- a/include/core/ums.h +++ b/include/core/ums.h @@ -43,6 +43,10 @@ bool umsIsDeviceInfoUpdated(void); /// Returns NULL if an error occurs. UsbHsFsDevice *umsGetDevices(u32 *out_count); +/// Unmounts a USB Mass Storage device using a UsbHsFsDevice element. +/// If successful, USB Mass Storage device info will be automatically reloaded, and the next call to umsIsDeviceInfoUpdated() shall return true. +bool umsUnmountDevice(const UsbHsFsDevice *device); + #ifdef __cplusplus } #endif diff --git a/libs/libusbhsfs b/libs/libusbhsfs index 68da930..972bddf 160000 --- a/libs/libusbhsfs +++ b/libs/libusbhsfs @@ -1 +1 @@ -Subproject commit 68da93049d85e890c7388f4fc14805dedf55af94 +Subproject commit 972bddf8967e801569d809b776a8d1c9acb606c2 diff --git a/source/core/ums.c b/source/core/ums.c index cde663b..8620b86 100644 --- a/source/core/ums.c +++ b/source/core/ums.c @@ -109,6 +109,21 @@ UsbHsFsDevice *umsGetDevices(u32 *out_count) return devices; } +bool umsUnmountDevice(const UsbHsFsDevice *device) +{ + if (!device) + { + LOG_MSG_ERROR("Invalid parameters!"); + return false; + } + + /* Unmount USB Mass Storage device. If successful, let libusbhsfs automatically call our populate callback. */ + bool ret = usbHsFsUnmountDevice(device, true); + if (!ret) LOG_MSG_ERROR("Failed to unmount UMS device \"%s\"!", device->name); + + return ret; +} + static void umsFreeDeviceData(void) { /* Free devices buffer. */