hosted: Fix USB mounting code to work with HAVE_MULTIDRIVE enabled

Change-Id: I48944c28903db117d3d883a5e777cafe5d055600
This commit is contained in:
Solomon Peachy 2020-10-17 17:25:38 -04:00
parent f3ec58c05b
commit 6f9a157fca
3 changed files with 50 additions and 9 deletions

View file

@ -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;
}

View file

@ -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

View file

@ -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;
}