FS#13519: multivolume: Ensure absolute paths get drive designation

Change-Id: I8419af670ca101b11bba29d9fd577f21fa22fd42
This commit is contained in:
Dana Conrad 2024-12-05 01:54:01 +00:00 committed by Solomon Peachy
parent aeb4b6c34a
commit 7d3cc24dec
2 changed files with 36 additions and 5 deletions

View file

@ -70,7 +70,7 @@
flushed to disk when required. flushed to disk when required.
*/ */
//#define LOGF_ENABLE // #define LOGF_ENABLE
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <ctype.h> #include <ctype.h>
@ -592,6 +592,8 @@ static ssize_t format_track_path(char *dest, char *src, int buf_length,
dlen = -1u; dlen = -1u;
} }
logf("dir: %s", dir);
len = path_append_ex(dest, dir, dlen, src, buf_length); len = path_append_ex(dest, dir, dlen, src, buf_length);
if (len >= (size_t)buf_length) if (len >= (size_t)buf_length)
return -1; /* buffer too small */ return -1; /* buffer too small */

View file

@ -27,6 +27,9 @@
#include "file_internal.h" #include "file_internal.h"
#include "debug.h" #include "debug.h"
// #define LOGF_ENABLE
#include "logf.h"
#ifdef HAVE_MULTIVOLUME #ifdef HAVE_MULTIVOLUME
#include "storage.h" #include "storage.h"
@ -520,12 +523,38 @@ size_t path_append_ex(char *buf, const char *basepath, size_t basepath_max,
bufsize = 0; bufsize = 0;
if (path_is_absolute(component)) /* starts with a '/' path separator */ if (path_is_absolute(component)) /* starts with a '/' path separator */
{
#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 */ /* 'component' is absolute; replace all */
basepath = component; basepath = component;
component = ""; component = "";
basepath_max = -1u; basepath_max = -1u;
} }
}
/* if basepath is not null or empty, buffer contents are replaced, /* if basepath is not null or empty, buffer contents are replaced,
otherwise buf contains the base path */ otherwise buf contains the base path */