From bc3fa5393762549a16f9de3e238a986607015fe3 Mon Sep 17 00:00:00 2001 From: William Wilgus Date: Sat, 5 Mar 2022 09:33:45 -0500 Subject: [PATCH] Sansa Multiboot Root Redirect Enhance + bug fix filename buffer was too small to retrieve redirect path if redirected to sd root remove as it is redundant Change-Id: I1326601f1ba4a18d6bc173798759eb762b55528c --- apps/debug_menu.c | 11 +++--- firmware/include/dircache_redirect.h | 58 ++++++++++++++-------------- 2 files changed, 35 insertions(+), 34 deletions(-) diff --git a/apps/debug_menu.c b/apps/debug_menu.c index 1b341a96e4..6b76aac162 100644 --- a/apps/debug_menu.c +++ b/apps/debug_menu.c @@ -2526,20 +2526,21 @@ static bool dbg_skin_engine(void) #if defined(HAVE_BOOTDATA) && !defined(SIMULATOR) static bool dbg_boot_data(void) { - unsigned int crc = 0; + unsigned int crc = crc_32(boot_data.payload, boot_data.length, 0xffffffff); struct simplelist_info info; info.scroll_all = true; simplelist_info_init(&info, "Boot data", 1, NULL); simplelist_set_line_count(0); - crc = crc_32(boot_data.payload, boot_data.length, 0xffffffff); + #if defined(HAVE_MULTIBOOT) - char rootpath[VOL_MAX_LEN+2] = RB_ROOT_CONTENTS_DIR; + char rootpath[MAX_PATH / 2] = RB_ROOT_CONTENTS_DIR; int boot_volume = 0; if(crc == boot_data.crc) { boot_volume = boot_data.boot_volume; /* boot volume contained in uint8_t payload */ - get_redirect_dir(rootpath, sizeof(rootpath), boot_volume, "", ""); - rootpath[path_strip_trailing_separators(rootpath,NULL)] = '\0'; + int rtlen = get_redirect_dir(rootpath, sizeof(rootpath), boot_volume, "", ""); + while (rtlen > 0 && rootpath[--rtlen] == PATH_SEPCH) /* remove extra separators */ + rootpath[rtlen] = '\0'; } simplelist_addline("Boot Volume: <%lu>", boot_volume); simplelist_addline("Root:"); diff --git a/firmware/include/dircache_redirect.h b/firmware/include/dircache_redirect.h index a781d6ee76..c8905455f9 100644 --- a/firmware/include/dircache_redirect.h +++ b/firmware/include/dircache_redirect.h @@ -138,49 +138,49 @@ static inline void fileop_onsync_internal(struct filestr_base *stream) static inline void volume_onmount_internal(IF_MV_NONVOID(int volume)) { -#ifdef HAVE_MULTIVOLUME - char path[VOL_MAX_LEN+2]; - make_volume_root(volume, path); -#else - const char *path = PATH_ROOTSTR; -#endif - #if defined(HAVE_MULTIBOOT) && !defined(SIMULATOR) && !defined(BOOTLOADER) - static char rtpath[VOL_MAX_LEN+2] = RB_ROOT_CONTENTS_DIR; - static bool redirected = false; - int boot_volume = 0; - unsigned int crc = 0; - crc = crc_32(boot_data.payload, boot_data.length, 0xffffffff); - if (crc == boot_data.crc) + char path[VOL_MAX_LEN+2]; + char rtpath[MAX_PATH / 2]; + make_volume_root(volume, path); + + unsigned int crc = crc_32(boot_data.payload, boot_data.length, 0xffffffff); + if (crc > 0 && crc == boot_data.crc) { - root_mount_path(path, 0); /*root could be different folder don't hide*/ - boot_volume = boot_data.boot_volume; /* boot volume contained in uint8_t payload */ - //root_mount_path(path, volume == boot_volume ? NSITEM_HIDDEN : 0); - if (!redirected && volume == boot_volume) + /* we need to mount the drive before we can access it */ + root_mount_path(path, 0); /* root could be different folder don't hide */ + + if (volume == boot_data.boot_volume) /* boot volume contained in uint8_t payload */ { - if (get_redirect_dir(rtpath, sizeof(rtpath), volume, "", "") < 0) - { /* Error occurred, card removed? Set root to default */ - root_mount_path(RB_ROOT_CONTENTS_DIR, NSITEM_CONTENTS); - } - else - redirected = true; - } - if (redirected && volume == boot_volume) + int rtlen = get_redirect_dir(rtpath, sizeof(rtpath), volume, "", ""); + while (rtlen > 0 && rtpath[--rtlen] == PATH_SEPCH) + rtpath[rtlen] = '\0'; /* remove extra separators */ + + if (rtlen <= 0 || rtpath[rtlen] == VOL_END_TOK) + root_unmount_volume(volume); /* unmount so root can be hidden*/ + + if (rtlen <= 0) /* Error occurred, card removed? Set root to default */ + goto standard_redirect; root_mount_path(rtpath, NSITEM_CONTENTS); + } + } /*CRC OK*/ else { +standard_redirect: root_mount_path(path, RB_ROOT_VOL_HIDDEN(volume) ? NSITEM_HIDDEN : 0); if (volume == path_strip_volume(RB_ROOT_CONTENTS_DIR, NULL, false)) root_mount_path(RB_ROOT_CONTENTS_DIR, NSITEM_CONTENTS); } -#else /*ndef HAVE_MULTIBOOT */ - +#elif defined(HAVE_MULTIVOLUME) + char path[VOL_MAX_LEN+2]; + make_volume_root(volume, path); root_mount_path(path, RB_ROOT_VOL_HIDDEN(volume) ? NSITEM_HIDDEN : 0); -#ifdef HAVE_MULTIVOLUME if (volume == path_strip_volume(RB_ROOT_CONTENTS_DIR, NULL, false)) -#endif root_mount_path(RB_ROOT_CONTENTS_DIR, NSITEM_CONTENTS); +#else + const char *path = PATH_ROOTSTR; + root_mount_path(path, RB_ROOT_VOL_HIDDEN(volume) ? NSITEM_HIDDEN : 0); + root_mount_path(RB_ROOT_CONTENTS_DIR, NSITEM_CONTENTS); #endif /* HAVE_MULTIBOOT */ #ifdef HAVE_DIRCACHE