From 7d3cc24dec12554d58f65db748a98c3f8bcba71b Mon Sep 17 00:00:00 2001 From: Dana Conrad Date: Thu, 5 Dec 2024 01:54:01 +0000 Subject: [PATCH] FS#13519: multivolume: Ensure absolute paths get drive designation Change-Id: I8419af670ca101b11bba29d9fd577f21fa22fd42 --- apps/playlist.c | 4 +++- firmware/common/pathfuncs.c | 37 +++++++++++++++++++++++++++++++++---- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/apps/playlist.c b/apps/playlist.c index 465ebb88a0..00343e839e 100644 --- a/apps/playlist.c +++ b/apps/playlist.c @@ -70,7 +70,7 @@ flushed to disk when required. */ -//#define LOGF_ENABLE +// #define LOGF_ENABLE #include #include #include @@ -592,6 +592,8 @@ static ssize_t format_track_path(char *dest, char *src, int buf_length, dlen = -1u; } + logf("dir: %s", dir); + len = path_append_ex(dest, dir, dlen, src, buf_length); if (len >= (size_t)buf_length) return -1; /* buffer too small */ diff --git a/firmware/common/pathfuncs.c b/firmware/common/pathfuncs.c index b5e5ecb0cf..ba815e3307 100644 --- a/firmware/common/pathfuncs.c +++ b/firmware/common/pathfuncs.c @@ -27,6 +27,9 @@ #include "file_internal.h" #include "debug.h" +// #define LOGF_ENABLE +#include "logf.h" + #ifdef HAVE_MULTIVOLUME #include "storage.h" @@ -521,10 +524,36 @@ size_t path_append_ex(char *buf, const char *basepath, size_t basepath_max, if (path_is_absolute(component)) /* starts with a '/' path separator */ { - /* 'component' is absolute; replace all */ - basepath = component; - component = ""; - basepath_max = -1u; + #if defined(HAVE_MULTIVOLUME) + const char *baseend; + /* our component doesn't appear to have a drive/volume */ + if (path_strip_volume(component, &baseend, false) == ROOT_VOLUME) + { + /* find the basepath's drive/volume name, if it has one. + * ensure basepath is not NULL, that causes a crash on sim */ + if (basepath != NULL && path_strip_volume(basepath, &baseend, false) != ROOT_VOLUME) + { + basepath_max = baseend - basepath; + /* strip leading separators from component */ + while (*component == PATH_SEPCH) + component++; + } else { + /* component is absolute with no drive/volume, but basepath doesn't + * have a volume either... we must be on root volume */ + basepath = component; + component = ""; + basepath_max = -1u; + } + } + /* else component likely already has drive/volume name */ + else + #endif + { + /* 'component' is absolute; replace all */ + basepath = component; + component = ""; + basepath_max = -1u; + } } /* if basepath is not null or empty, buffer contents are replaced,