-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
MSC exclusive access support. #8814
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,3 +52,29 @@ void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts) { | |
} | ||
|
||
#endif | ||
|
||
#if MICROPY_HW_USB_MSC_EXCLUSIVE_ACCESS | ||
#include "tusb.h" | ||
#include "extmod/vfs.h" | ||
static mp_sched_node_t mp_remount_sched_node; | ||
|
||
STATIC void tud_msc_remount_task(mp_sched_node_t *node) { | ||
mp_vfs_mount_t *vfs = NULL; | ||
for (vfs = MP_STATE_VM(vfs_mount_table); vfs != NULL; vfs = vfs->next) { | ||
if (vfs->len == 1) { | ||
nlr_buf_t nlr; | ||
if (nlr_push(&nlr) == 0) { | ||
mp_vfs_umount(vfs->obj); | ||
nlr_pop(); | ||
} | ||
mp_obj_t path = mp_obj_new_str(vfs->str, strlen(vfs->str)); | ||
mp_vfs_mount_and_chdir_protected(vfs->obj, path); | ||
break; | ||
} | ||
} | ||
} | ||
|
||
void tud_msc_remount(void) { | ||
mp_sched_schedule_node(&mp_remount_sched_node, tud_msc_remount_task); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At which state will tud_msc_remount be called? Only when the device is ejected? Or is it possible that the PC may remount the drive? I cannot do that with my Linux box. If the board has always go through a power cycle, then it's fine. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Assuming that a board with MSC support will start in locally write protected mode. What happens if the board is running stand-alone? Can it tell that there is no MSC mounted? Then the drive must be mounted write enabled. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It gets called when the device is ejected. It may be possible to remount a safely-removed/ejected drive, but I think that disconnects power from the port anyway, I will have to test to confirm. However, I think that's a very unlikely case that shouldn't be handled, not sure if it should remount as read-only after giving write access to the device. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm chewing on the timing issue. At the moment, the board starts with write enabled, to be able to create a file system, if it does not exist. Then it mounts the flash drive, which must be write protected if MSC is used. It could decide based on the status of the IOCTL_STATUS call. But how long does that status change take? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK. So the tud_msc_start_stop_cb() is only called on eject. The ud_msc_inquiry_cb() is called on start, as well as the tud_msc_capacity_cb(). So we could use these as indicator, that a PC is attempting to connect. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With the softreboot the file is gone. test without the soft reboot. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
maybe a false alarm: The PC/USB simple code waits for tud_msc_start_stop_cb() to finish. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes maybe because you're single stepping the function. The remount is scheduled, so this function returns immediately. Anyway, the mount point of the MSC filesystem should be defined somewhere, or even better if it's detected dynamically somehow, but I'm not sure how to do that. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I single stepped in the tud_msc_remount_task() function. So I know it is called. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we do not find a good solution, we could at least defer opening the file system for write until the next soft boot. That's at least safe. |
||
} | ||
#endif |
Uh oh!
There was an error while loading. Please reload this page.