hosted: Fix HAVE_MULTIDRIVE to work properly with PIVOT_ROOT

Change-Id: Ibc97de5c345e88c19ad8ba8c05fefebbada08790
This commit is contained in:
Solomon Peachy 2020-10-17 15:57:07 -04:00
parent a68fc3b6c2
commit 012908e064
2 changed files with 13 additions and 5 deletions

View File

@ -164,7 +164,7 @@
/* External SD card can be mounted */
#define CONFIG_STORAGE (STORAGE_HOSTFS|STORAGE_SD)
#define HAVE_MULTIDRIVE
#define HAVE_MULTIDRIVE /* But _not_ CONFIG_STORAGE_MULTI */
#define NUM_DRIVES 2
#define HAVE_HOTSWAP
#define HAVE_STORAGE_FLUSH

View File

@ -8,6 +8,7 @@
* $Id$
*
* Copyright (C) 2010 Thomas Martitz
* Copyright (C) 2020 Solomon Peachy
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -53,8 +54,10 @@ static const char rbhome[] = "/sdcard";
#elif (CONFIG_PLATFORM & (PLATFORM_SDL|PLATFORM_MAEMO|PLATFORM_PANDORA)) \
&& !defined(__PCTOOL__)
static const char *rbhome;
#elif defined(PIVOT_ROOT)
static const char rbhome[] = PIVOT_ROOT;
#else
/* YPR0, YPR1, NWZ, etc */
/* Anything else? */
static const char rbhome[] = HOME_DIR;
#endif
#endif
@ -94,9 +97,7 @@ static const char *handle_special_links(const char* link, unsigned flags,
return link;
}
#endif
#ifdef HAVE_MULTIDRIVE
/* we keep an open descriptor of the home directory to detect when it has been
opened by opendir() so that its "symlinks" may be enumerated */
static void cleanup_rbhome(void)
@ -209,12 +210,19 @@ const char * handle_special_dirs(const char *dir, unsigned flags,
dir = _get_user_file_path(dir, flags, buf, bufsize);
#endif
#ifdef HAVE_MULTIDRIVE
#define MULTIDRIVE_DIR_LEN (sizeof(MULTIDRIVE_DIR)-1)
dir = handle_special_links(dir, flags, buf, bufsize);
#endif
#ifdef PIVOT_ROOT
#define PIVOT_ROOT_LEN (sizeof(PIVOT_ROOT)-1)
/* Prepend root prefix to find actual path */
if (strncmp(PIVOT_ROOT, dir, PIVOT_ROOT_LEN))
if (strncmp(PIVOT_ROOT, dir, PIVOT_ROOT_LEN)
#ifdef MULTIDRIVE_DIR
/* Unless it's a MULTIDRIVE dir, in which case use as-is */
&& strncmp(MULTIDRIVE_DIR, dir, MULTIDRIVE_DIR_LEN)
#endif
)
{
snprintf(buf, bufsize, "%s/%s", PIVOT_ROOT, dir);
dir = buf;