1
0
Fork 0
forked from len0rd/rockbox

hosted: sanitize handling of HOME_DIR

* HOME_DIR is now either "/" or special "<HOME>"
   * target-specific "home dir path" is defined solely by PIVOT_ROOT
 * PIVOT_ROOT path is now defined in toplevel config files
 * Make Samsung YP-R0/R1 and SONY_NWZ use PIVOT_ROOT too
 * Do not prepend PIVOT_ROOT path if the path already has it!
 * Do not play these games for __PCTOOL__ builds

Change-Id: I3d51ad902a5f9cafe45ba15ba654f30f1ec6113a
This commit is contained in:
Solomon Peachy 2020-10-11 08:26:53 -04:00
parent a5add3982b
commit db6f21e295
16 changed files with 58 additions and 68 deletions

View file

@ -24,7 +24,7 @@
#include "plugin.h" #include "plugin.h"
#include "lang_enum.h" #include "lang_enum.h"
#define BATTERY_LOG HOME_DIR"/battery_bench.txt" #define BATTERY_LOG HOME_DIR "/battery_bench.txt"
#define BUF_SIZE 16000 #define BUF_SIZE 16000
#define EV_EXIT 1337 #define EV_EXIT 1337

View file

@ -58,7 +58,7 @@ static int cache_pos = 0;
static bool pending = false; static bool pending = false;
#if CONFIG_RTC #if CONFIG_RTC
static time_t timestamp; static time_t timestamp;
#define BASE_FILENAME ".scrobbler.log" #define BASE_FILENAME HOME_DIR "/.scrobbler.log"
#define HDR_STR_TIMELESS #define HDR_STR_TIMELESS
#define get_timestamp() ((long)timestamp) #define get_timestamp() ((long)timestamp)
#define record_timestamp() ((void)(timestamp = mktime(get_time()))) #define record_timestamp() ((void)(timestamp = mktime(get_time())))
@ -72,21 +72,8 @@ static time_t timestamp;
static void get_scrobbler_filename(char *path, size_t size) static void get_scrobbler_filename(char *path, size_t size)
{ {
int used; int used;
/* Get location of USB mass storage area */
#ifdef APPLICATION
#if (CONFIG_PLATFORM & PLATFORM_MAEMO)
used = snprintf(path, size, "/home/user/MyDocs/%s", BASE_FILENAME);
#elif (CONFIG_PLATFORM & PLATFORM_ANDROID)
used = snprintf(path, size, "/sdcard/%s", BASE_FILENAME);
#elif defined (SAMSUNG_YPR0) || defined(DX50) || defined(DX90)
used = snprintf(path, size, "%s/%s", HOME_DIR, BASE_FILENAME);
#else /* Everything else uses a pivot_root strategy.. */
used = snprintf(path, size, "/%s", BASE_FILENAME);
#endif /* (CONFIG_PLATFORM & PLATFORM_MAEMO) */
#else
used = snprintf(path, size, "/%s", BASE_FILENAME); used = snprintf(path, size, "/%s", BASE_FILENAME);
#endif
if (used >= (int)size) if (used >= (int)size)
{ {

View file

@ -51,14 +51,12 @@
#if defined(AGPTEK_ROCKER) #if defined(AGPTEK_ROCKER)
#define ICON_WIDTH 70 #define ICON_WIDTH 70
#define ICON_HEIGHT 70 #define ICON_HEIGHT 70
#define RBFILE "rockbox.rocker"
#define ICON_NAME bm_hibyicon #define ICON_NAME bm_hibyicon
#define OF_NAME "HIBY PLAYER" #define OF_NAME "HIBY PLAYER"
#include "bitmaps/hibyicon.h" #include "bitmaps/hibyicon.h"
#elif defined(XDUOO_X3II) #elif defined(XDUOO_X3II)
#define ICON_WIDTH 130 #define ICON_WIDTH 130
#define ICON_HEIGHT 130 #define ICON_HEIGHT 130
#define RBFILE "rockbox.x3ii"
#define ICON_NAME bm_hibyicon #define ICON_NAME bm_hibyicon
#define OF_NAME "HIBY PLAYER" #define OF_NAME "HIBY PLAYER"
#define BUTTON_UP BUTTON_OPTION #define BUTTON_UP BUTTON_OPTION
@ -68,7 +66,6 @@
#elif defined(XDUOO_X20) #elif defined(XDUOO_X20)
#define ICON_WIDTH 130 #define ICON_WIDTH 130
#define ICON_HEIGHT 130 #define ICON_HEIGHT 130
#define RBFILE "rockbox.x20"
#define ICON_NAME bm_hibyicon #define ICON_NAME bm_hibyicon
#define OF_NAME "HIBY PLAYER" #define OF_NAME "HIBY PLAYER"
#define BUTTON_UP BUTTON_OPTION #define BUTTON_UP BUTTON_OPTION
@ -78,7 +75,6 @@
#elif defined(FIIO_M3K) #elif defined(FIIO_M3K)
#define ICON_WIDTH 130 #define ICON_WIDTH 130
#define ICON_HEIGHT 130 #define ICON_HEIGHT 130
#define RBFILE "rockbox.fiiom3k"
#define ICON_NAME bm_fiioicon #define ICON_NAME bm_fiioicon
#define BUTTON_LEFT BUTTON_PREV #define BUTTON_LEFT BUTTON_PREV
#define BUTTON_RIGHT BUTTON_NEXT #define BUTTON_RIGHT BUTTON_NEXT
@ -88,7 +84,6 @@
#elif defined(EROS_Q) #elif defined(EROS_Q)
#define ICON_WIDTH 130 #define ICON_WIDTH 130
#define ICON_HEIGHT 130 #define ICON_HEIGHT 130
#define RBFILE "rockbox.erosq"
#define ICON_NAME bm_hibyicon #define ICON_NAME bm_hibyicon
#define OF_NAME "HIBY PLAYER" #define OF_NAME "HIBY PLAYER"
#define BUTTON_UP BUTTON_SCROLL_BACK #define BUTTON_UP BUTTON_SCROLL_BACK
@ -99,11 +94,12 @@
#error "must define ICON_WIDTH/HEIGHT" #error "must define ICON_WIDTH/HEIGHT"
#endif #endif
#ifdef FIIO_M3K #define BASE_DIR PIVOT_ROOT
#define BASE_DIR "/mnt" //#ifdef FIIO_M3K
#else //#define BASE_DIR "/mnt"
#define BASE_DIR "/mnt/sd_0" //#else
#endif //#define BASE_DIR "/mnt/sd_0"
//#endif
/* images */ /* images */
#include "bitmaps/rockboxicon.h" #include "bitmaps/rockboxicon.h"
@ -631,9 +627,9 @@ int main(int argc, char **argv)
{ {
fflush(stdout); fflush(stdout);
mount_storage(true); mount_storage(true);
system("/bin/cp " BASE_DIR "/.rockbox/" RBFILE " /tmp"); system("/bin/cp " BASE_DIR "/.rockbox/" BOOTFILE " /tmp");
system("/bin/chmod +x /tmp/" RBFILE); system("/bin/chmod +x /tmp/" BOOTFILE);
execl("/tmp/" RBFILE, RBFILE, NULL); execl("/tmp/" BOOTFILE, BOOTFILE, NULL);
printf("execvp failed: %s\n", strerror(errno)); printf("execvp failed: %s\n", strerror(errno));
/* fallback to OF in case of failure */ /* fallback to OF in case of failure */
error_screen("Cannot boot Rockbox"); error_screen("Cannot boot Rockbox");

View file

@ -15,6 +15,7 @@
#ifndef SIMULATOR #ifndef SIMULATOR
#define CONFIG_PLATFORM (PLATFORM_HOSTED) #define CONFIG_PLATFORM (PLATFORM_HOSTED)
#define PIVOT_ROOT "/mnt/sd_0"
#endif #endif
#define HIBY_LINUX #define HIBY_LINUX

View file

@ -15,6 +15,7 @@
#ifndef SIMULATOR #ifndef SIMULATOR
#define CONFIG_PLATFORM (PLATFORM_HOSTED) #define CONFIG_PLATFORM (PLATFORM_HOSTED)
#define PIVOT_ROOT "/mnt/sd_0"
#endif #endif
#define HIBY_LINUX #define HIBY_LINUX

View file

@ -15,6 +15,7 @@
#ifndef SIMULATOR #ifndef SIMULATOR
#define CONFIG_PLATFORM (PLATFORM_HOSTED) #define CONFIG_PLATFORM (PLATFORM_HOSTED)
#define PIVOT_ROOT "/mnt"
#endif #endif
#define HAVE_FPU #define HAVE_FPU

View file

@ -24,7 +24,10 @@
/* This config file is for Rockbox as an application on Android without JVM. */ /* This config file is for Rockbox as an application on Android without JVM. */
/* We don't run on hardware directly */ /* We don't run on hardware directly */
#ifndef SIMULATOR
#define CONFIG_PLATFORM PLATFORM_HOSTED #define CONFIG_PLATFORM PLATFORM_HOSTED
#define PIVOT_ROOT "/mnt/sdcard"
#endif
#define HAVE_FPU #define HAVE_FPU
/* For Rolo and boot loader */ /* For Rolo and boot loader */

View file

@ -24,7 +24,10 @@
/* This config file is for Rockbox as an application on Android without JVM. */ /* This config file is for Rockbox as an application on Android without JVM. */
/* We don't run on hardware directly */ /* We don't run on hardware directly */
#ifndef SIMULATOR
#define CONFIG_PLATFORM PLATFORM_HOSTED #define CONFIG_PLATFORM PLATFORM_HOSTED
#define PIVOT_ROOT "/mnt/sdcard"
#endif
#define HAVE_FPU #define HAVE_FPU
/* For Rolo and boot loader */ /* For Rolo and boot loader */

View file

@ -7,6 +7,7 @@
/* YP-R0 need it too of course */ /* YP-R0 need it too of course */
#ifndef SIMULATOR #ifndef SIMULATOR
#define CONFIG_PLATFORM (PLATFORM_HOSTED) #define CONFIG_PLATFORM (PLATFORM_HOSTED)
#define PIVOT_ROOT "/mnt/media0"
#endif #endif
/* For Rolo and boot loader */ /* For Rolo and boot loader */

View file

@ -7,6 +7,7 @@
/* YP-R1 need it too of course */ /* YP-R1 need it too of course */
#ifndef SIMULATOR #ifndef SIMULATOR
#define CONFIG_PLATFORM (PLATFORM_HOSTED) #define CONFIG_PLATFORM (PLATFORM_HOSTED)
#define PIVOT_ROOT "/mnt/media0"
#endif #endif
/* For Rolo and boot loader */ /* For Rolo and boot loader */

View file

@ -4,11 +4,9 @@
#ifndef SIMULATOR #ifndef SIMULATOR
#define CONFIG_PLATFORM (PLATFORM_HOSTED) #define CONFIG_PLATFORM (PLATFORM_HOSTED)
#define PIVOT_ROOT "/contents"
#endif #endif
/* define this if you have a colour LCD */ /* define this if you have a colour LCD */
#define HAVE_LCD_COLOR #define HAVE_LCD_COLOR

View file

@ -15,6 +15,7 @@
#ifndef SIMULATOR #ifndef SIMULATOR
#define CONFIG_PLATFORM (PLATFORM_HOSTED) #define CONFIG_PLATFORM (PLATFORM_HOSTED)
#define PIVOT_ROOT "/mnt/sd_0"
#endif #endif
#define HIBY_LINUX #define HIBY_LINUX

View file

@ -15,6 +15,7 @@
#ifndef SIMULATOR #ifndef SIMULATOR
#define CONFIG_PLATFORM (PLATFORM_HOSTED) #define CONFIG_PLATFORM (PLATFORM_HOSTED)
#define PIVOT_ROOT "/mnt/sd_0"
#endif #endif
#define HIBY_LINUX #define HIBY_LINUX

View file

@ -40,24 +40,12 @@
#define ROCKBOX_DIR_LEN (sizeof(ROCKBOX_DIR)-1) #define ROCKBOX_DIR_LEN (sizeof(ROCKBOX_DIR)-1)
#endif /* def __PCTOOL__ */ #endif /* def __PCTOOL__ */
/* NOTE: target-specific hosted HOME_DIR resides in filesystem-app.c */
#if !defined(APPLICATION) || defined(SAMSUNG_YPR0) || defined(SAMSUNG_YPR1) || \ #if !defined(APPLICATION) || defined(SAMSUNG_YPR0) || defined(SAMSUNG_YPR1) || \
defined(DX50) || defined(DX90) || defined(SONY_NWZ_LINUX) || \ defined(DX50) || defined(DX90) || defined(SONY_NWZ_LINUX) || \
defined(HIBY_LINUX) || defined(FIIO_M3K) defined(HIBY_LINUX) || defined(FIIO_M3K)
#if defined(SAMSUNG_YPR0) || defined(SAMSUNG_YPR1)
#define HOME_DIR "/mnt/media0"
#elif defined(SONY_NWZ_LINUX)
#define HOME_DIR "/contents"
#elif defined(DX50) || defined(DX90)
/* Where to put save files like recordings, playlists, screen dumps ...*/
#define HOME_DIR "/mnt/sdcard"
#elif defined(HIBY_LINUX)
#define HOME_DIR "/mnt/sd_0"
#elif defined(FIIO_M3K)
#define HOME_DIR "/mnt"
#else
#define HOME_DIR "/" #define HOME_DIR "/"
#endif
/* make sure both are the same for native builds */ /* make sure both are the same for native builds */
#undef ROCKBOX_LIBRARY_PATH #undef ROCKBOX_LIBRARY_PATH
@ -69,6 +57,7 @@
#else /* APPLICATION */ #else /* APPLICATION */
#define HOME_DIR "<HOME>" /* replaced at runtime */ #define HOME_DIR "<HOME>" /* replaced at runtime */
#define HAVE_SPECIAL_DIRS
#define PLUGIN_DIR ROCKBOX_LIBRARY_PATH "/rockbox/rocks" #define PLUGIN_DIR ROCKBOX_LIBRARY_PATH "/rockbox/rocks"
#if (CONFIG_PLATFORM & PLATFORM_ANDROID) #if (CONFIG_PLATFORM & PLATFORM_ANDROID)
@ -79,10 +68,8 @@
#endif /* !APPLICATION || SAMSUNG_YPR0 */ #endif /* !APPLICATION || SAMSUNG_YPR0 */
#define HOME_DIR_LEN (sizeof(HOME_DIR)-1) #define REC_BASE_DIR HOME_DIR "/Recordings"
#define PLAYLIST_CATALOG_DEFAULT_DIR HOME_DIR "/Playlists"
#define REC_BASE_DIR "/Recordings"
#define PLAYLIST_CATALOG_DEFAULT_DIR "/Playlists"
#define LANG_DIR ROCKBOX_DIR "/langs" #define LANG_DIR ROCKBOX_DIR "/langs"
@ -91,8 +78,10 @@
#define PLUGIN_DEMOS_DIR PLUGIN_DIR "/demos" #define PLUGIN_DEMOS_DIR PLUGIN_DIR "/demos"
#define VIEWERS_DIR PLUGIN_DIR "/viewers" #define VIEWERS_DIR PLUGIN_DIR "/viewers"
#if defined(APPLICATION) && !(defined(SAMSUNG_YPR0) || defined(SAMSUNG_YPR1) || \ #if defined(APPLICATION) && \
defined(DX50) || defined(DX90) || defined(SONY_NWZ_LINUX) || defined(HIBY_LINUX)) !(defined(SAMSUNG_YPR0) || defined(SAMSUNG_YPR1) || \
defined(DX50) || defined(DX90) || defined(SONY_NWZ_LINUX) || defined(HIBY_LINUX) || defined(FIIO_M3K))
#define PLUGIN_DATA_DIR ROCKBOX_DIR "/rocks.data" #define PLUGIN_DATA_DIR ROCKBOX_DIR "/rocks.data"
#define PLUGIN_GAMES_DATA_DIR PLUGIN_DATA_DIR #define PLUGIN_GAMES_DATA_DIR PLUGIN_DATA_DIR
#define PLUGIN_APPS_DATA_DIR PLUGIN_DATA_DIR #define PLUGIN_APPS_DATA_DIR PLUGIN_DATA_DIR

View file

@ -36,15 +36,13 @@
#include "rbpaths.h" #include "rbpaths.h"
#include "logf.h" #include "logf.h"
#if !(defined(BOOTLOADER) || defined(CHECKWPS) || defined(SIMULATOR)) /* PIVOT_ROOT adds a fixed prefix to all paths */
#if defined(HIBY_LINUX) #if defined(BOOTLOADER) || defined(CHECKWPS) || defined(SIMULATOR) || defined(__PCTOOL__)
#define PIVOT_ROOT "/mnt/sd_0" /* We don't want to use pivot root on these! */
#elif defined(FIIO_M3K) #undef PIVOT_ROOT
#define PIVOT_ROOT "/mnt" // XXX check this!
#else
#endif #endif
#endif // !(BOOTLOADER|WPS|SIM)
#if defined(HAVE_MULTIDRIVE) || defined(HAVE_SPECIAL_DIRS)
#if (CONFIG_PLATFORM & PLATFORM_ANDROID) #if (CONFIG_PLATFORM & PLATFORM_ANDROID)
static const char rbhome[] = "/sdcard"; static const char rbhome[] = "/sdcard";
#elif (CONFIG_PLATFORM & (PLATFORM_SDL|PLATFORM_MAEMO|PLATFORM_PANDORA)) \ #elif (CONFIG_PLATFORM & (PLATFORM_SDL|PLATFORM_MAEMO|PLATFORM_PANDORA)) \
@ -54,15 +52,11 @@ static const char *rbhome;
/* YPR0, YPR1, NWZ, etc */ /* YPR0, YPR1, NWZ, etc */
static const char rbhome[] = HOME_DIR; static const char rbhome[] = HOME_DIR;
#endif #endif
#endif
#if !(defined(SAMSUNG_YPR0) || defined(SAMSUNG_YPR1) || defined(DX50) || \ #if !defined(__PCTOOL__)
defined(SONY_NWZ_LINUX) || defined(DX90) || defined(HIBY_LINUX) || \ /* We don't want this for tools */
defined(FIIO_M3K)) && \ #undef HAVE_SPECIAL_DIRS
!defined(__PCTOOL__)
/* Special dirs are user-accessible (and user-writable) dirs which take priority
* over the ones where Rockbox is installed to. Classic example would be
* $HOME/.config/rockbox.org vs /usr/share/rockbox */
#define HAVE_SPECIAL_DIRS
#endif #endif
#ifdef HAVE_MULTIDRIVE #ifdef HAVE_MULTIDRIVE
@ -202,6 +196,8 @@ const char * handle_special_dirs(const char *dir, unsigned flags,
{ {
(void) flags; (void) buf; (void) bufsize; (void) flags; (void) buf; (void) bufsize;
#ifdef HAVE_SPECIAL_DIRS #ifdef HAVE_SPECIAL_DIRS
#define HOME_DIR_LEN (sizeof(HOME_DIR)-1)
/* This replaces HOME_DIR (ie '<HOME'>') with runtime rbhome */
if (!strncmp(HOME_DIR, dir, HOME_DIR_LEN)) if (!strncmp(HOME_DIR, dir, HOME_DIR_LEN))
{ {
const char *p = dir + HOME_DIR_LEN; const char *p = dir + HOME_DIR_LEN;
@ -216,8 +212,13 @@ const char * handle_special_dirs(const char *dir, unsigned flags,
dir = handle_special_links(dir, flags, buf, bufsize); dir = handle_special_links(dir, flags, buf, bufsize);
#endif #endif
#ifdef PIVOT_ROOT #ifdef PIVOT_ROOT
snprintf(buf, bufsize, "%s/%s", PIVOT_ROOT, dir); #define PIVOT_ROOT_LEN (sizeof(PIVOT_ROOT)-1)
dir = buf; /* Prepend root prefix to find actual path */
if (strncmp(PIVOT_ROOT, dir, PIVOT_ROOT_LEN))
{
snprintf(buf, bufsize, "%s/%s", PIVOT_ROOT, dir);
dir = buf;
}
#endif #endif
return dir; return dir;
} }

View file

@ -91,8 +91,14 @@ int rolo_load(const char* filename)
lcd_remote_update(); lcd_remote_update();
#endif #endif
#ifdef PIVOT_ROOT
#define EXECDIR PIVOT_ROOT
#else
#define EXECDIR ROOT_DIR
#endif
char buf[256]; char buf[256];
snprintf(buf, sizeof(buf), "%s/%s", HOME_DIR, filename); snprintf(buf, sizeof(buf), "%s/%s", EXECDIR, filename);
execl(buf, BOOTFILE, NULL); execl(buf, BOOTFILE, NULL);
rolo_error("Failed to launch!", strerror(errno)); rolo_error("Failed to launch!", strerror(errno));