From f3ec58c05b1f0044240cf5e95ff28e6966398958 Mon Sep 17 00:00:00 2001 From: Solomon Peachy Date: Sat, 17 Oct 2020 17:21:34 -0400 Subject: hosted: Support hot-swappable internal and external storage Change-Id: I321e9da4d5087dbd91194e6faa35cd4a685a0495 --- firmware/target/hosted/fiio/system-fiio.c | 27 +++++++++++++++++++++------ firmware/target/hosted/system-hosted.c | 20 ++++++++++++++++++-- 2 files changed, 39 insertions(+), 8 deletions(-) diff --git a/firmware/target/hosted/fiio/system-fiio.c b/firmware/target/hosted/fiio/system-fiio.c index 46a4d0f835..3d6b1a82cd 100644 --- a/firmware/target/hosted/fiio/system-fiio.c +++ b/firmware/target/hosted/fiio/system-fiio.c @@ -23,6 +23,8 @@ #include #include #include +#include +#include #include "system.h" #include "mv.h" @@ -31,10 +33,12 @@ #include "button.h" #include "backlight-target.h" #include "lcd.h" - #include "panic.h" -#include -#include + +#include "filesystem-hosted.h" + +/* forward-declare */ +bool os_file_exists(const char *ospath); /* to make thread-internal.h happy */ uintptr_t *stackbegin; @@ -102,7 +106,7 @@ void power_off(void) { panicf("Call AXP173_SHUTDOWN fail"); } - + close(axp_hw); } @@ -151,17 +155,29 @@ bool hostfs_removable(IF_MD_NONVOID(int drive)) return true; else #endif +#ifdef HAVE_HOTSWAP_STORAGE_AS_MAIN + return true; +#else return false; /* internal: always present */ +#endif } bool hostfs_present(IF_MD_NONVOID(int drive)) { #ifdef HAVE_MULTIDRIVE if (drive > 0) /* Active LOW */ - return true; //FIXME +#if defined(MULTIDRIVE_DEV) + return os_file_exists(MULTIDRIVE_DEV); +#else + return true; +#endif else #endif +#ifdef HAVE_HOTSWAP_STORAGE_AS_MAIN + return os_file_exists(ROOTDRIVE_DEV); +#else return true; /* internal: always present */ +#endif } #ifdef HAVE_MULTIDRIVE @@ -206,4 +222,3 @@ bool volume_present(int volume) return hostfs_present(volume); } #endif - diff --git a/firmware/target/hosted/system-hosted.c b/firmware/target/hosted/system-hosted.c index f485dc4c15..fa492c1094 100644 --- a/firmware/target/hosted/system-hosted.c +++ b/firmware/target/hosted/system-hosted.c @@ -31,11 +31,15 @@ #include "button.h" #include "backlight-target.h" #include "lcd.h" +#include "filesystem-hosted.h" /* to make thread-internal.h happy */ uintptr_t *stackbegin; uintptr_t *stackend; +/* forward-declare */ +bool os_file_exists(const char *ospath); + static void sig_handler(int sig, siginfo_t *siginfo, void *context) { /* safe guard variable - we call backtrace() only on first @@ -134,17 +138,29 @@ bool hostfs_removable(IF_MD_NONVOID(int drive)) return true; else #endif +#ifdef HAVE_HOTSWAP_STORAGE_AS_MAIN + return true; +#else return false; /* internal: always present */ +#endif } bool hostfs_present(IF_MD_NONVOID(int drive)) { #ifdef HAVE_MULTIDRIVE - if (drive > 0) /* Active LOW */ - return true; //FIXME + if (drive > 0) +#if defined(MULTIDRIVE_DEV) + return os_file_exists(MULTIDRIVE_DEV); +#else + return true; // FIXME? +#endif else #endif +#ifdef HAVE_HOTSWAP_STORAGE_AS_MAIN + return os_file_exists(ROOTDRIVE_DEV); +#else return true; /* internal: always present */ +#endif } #ifdef HAVE_MULTIDRIVE -- cgit v1.2.3