diff options
author | Solomon Peachy <pizza@shaftnet.org> | 2020-10-17 17:25:38 -0400 |
---|---|---|
committer | Solomon Peachy <pizza@shaftnet.org> | 2020-10-17 18:38:49 -0400 |
commit | 6f9a157fcac76466df8834eb73e04d7127e78b52 (patch) | |
tree | a40ab1aa102fae0c70feeed9b6f44c78d711d947 | |
parent | f3ec58c05b1f0044240cf5e95ff28e6966398958 (diff) |
hosted: Fix USB mounting code to work with HAVE_MULTIDRIVE enabled
Change-Id: I48944c28903db117d3d883a5e777cafe5d055600
-rw-r--r-- | firmware/target/hosted/fiio/usb-fiio.c | 12 | ||||
-rw-r--r-- | firmware/target/hosted/filesystem-app.c | 20 | ||||
-rw-r--r-- | firmware/target/hosted/usb-hiby.c | 27 |
3 files changed, 50 insertions, 9 deletions
diff --git a/firmware/target/hosted/fiio/usb-fiio.c b/firmware/target/hosted/fiio/usb-fiio.c index 3084ee0169..3b1a149eea 100644 --- a/firmware/target/hosted/fiio/usb-fiio.c +++ b/firmware/target/hosted/fiio/usb-fiio.c @@ -28,6 +28,11 @@ #include "power.h" #include "power-fiio.h" +#ifdef HAVE_MULTIDRIVE +void cleanup_rbhome(void); +void startup_rbhome(void); +#endif + const char * const sysfs_usb_online = "/sys/class/power_supply/usb/online"; @@ -68,6 +73,9 @@ void usb_enable(bool on) */ int disk_mount_all(void) { +#ifdef HAVE_MULTIDRIVE + startup_rbhome(); +#endif return 1; } @@ -77,6 +85,10 @@ int disk_mount_all(void) */ int disk_unmount_all(void) { +#ifdef HAVE_MULTIDRIVE + cleanup_rbhome(); +#endif + return 1; } diff --git a/firmware/target/hosted/filesystem-app.c b/firmware/target/hosted/filesystem-app.c index 93057e7a83..2121af7752 100644 --- a/firmware/target/hosted/filesystem-app.c +++ b/firmware/target/hosted/filesystem-app.c @@ -100,11 +100,20 @@ static const char *handle_special_links(const char* link, unsigned flags, /* 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) +void cleanup_rbhome(void) { os_close(rbhome_fildes); rbhome_fildes = -1; } +void startup_rbhome(void) +{ + /* if this fails then alternate volumes will not work, but this function + cannot return that fact */ + rbhome_fildes = os_opendirfd(rbhome); + if (rbhome_fildes >= 0) + atexit(cleanup_rbhome); +} + #endif /* HAVE_MULTIDRIVE */ void paths_init(void) @@ -140,14 +149,9 @@ void paths_init(void) os_mkdir(config_dir __MKDIR_MODE_ARG); #endif #endif /* HAVE_SPECIAL_DIRS */ - #ifdef HAVE_MULTIDRIVE - /* if this fails then alternate volumes will not work, but this function - cannot return that fact */ - rbhome_fildes = os_opendirfd(rbhome); - if (rbhome_fildes >= 0) - atexit(cleanup_rbhome); -#endif /* HAVE_MULTIDRIVE */ + startup_rbhome(); +#endif } #ifdef HAVE_SPECIAL_DIRS diff --git a/firmware/target/hosted/usb-hiby.c b/firmware/target/hosted/usb-hiby.c index 6c35e76e29..b82fa5c4ce 100644 --- a/firmware/target/hosted/usb-hiby.c +++ b/firmware/target/hosted/usb-hiby.c @@ -27,8 +27,16 @@ #include "sysfs.h" #include "power.h" +//#define LOGF_ENABLE +#include "logf.h" + static bool adb_mode = false; +#ifdef HAVE_MULTIDRIVE +void cleanup_rbhome(void); +void startup_rbhome(void); +#endif + /* TODO: implement usb detection properly */ int usb_detect(void) { @@ -37,6 +45,8 @@ int usb_detect(void) void usb_enable(bool on) { + logf("usb enable %d %d\n", on, adb_mode); + /* Ignore usb enable/disable when ADB is enabled so we can fireup adb shell * without entering ums mode */ @@ -65,11 +75,16 @@ int disk_mount_all(void) int rval = mount(dev[i], PIVOT_ROOT, fs[j], 0, NULL); if (rval == 0 || errno == -EBUSY) { + logf("mount good! %d/%d %d %d", i, j, rval, errno); +#ifdef HAVE_MULTIDRIVE + startup_rbhome(); +#endif return 1; } } } + logf("mount failed! %d", errno); return 0; } @@ -79,12 +94,22 @@ int disk_mount_all(void) */ int disk_unmount_all(void) { - if (umount("/mnt/sd_0") == 0) +#ifdef HAVE_MULTIDRIVE + cleanup_rbhome(); +#endif + + if (umount(PIVOT_ROOT) == 0) { sysfs_set_string("/sys/class/android_usb/android0/f_mass_storage/lun/file", "/dev/mmcblk0"); + logf("umount_all good"); return 1; } + logf("umount_all failed! %d", errno); +#ifdef HAVE_MULTIDRIVE + startup_rbhome(); +#endif + return 0; } |