Skip to content

Commit dc57bf3

Browse files
committed
Don't remount if file is deleted before data sent
When a file with a '.bin' or '.hex' extension is found then the remount timer starts. Abort the remount if the file is deleted before any data is sent. When copying files with attributes that do not exist on FAT16 windows goes through the following steps: 1. Create an uninitialized file of the correct size 2. Delete the file created in step 1 3. Create new file with size 0 4. Prompt user: "Are you sure you want to copy this file without its properties" 5. If yes then send file data, if no the delete file This causes problems because after the file in step 1 is deleted DAPLink detects this as a transfer error and remounts. By aborting the transfer instead of triggering an error files with incompatible attributes can be properly copied. This problem can be reproduced by saving a target binary to Dropbox's sync folder and then from there copying it to DAPLink.
1 parent ad08320 commit dc57bf3

File tree

1 file changed

+36
-8
lines changed

1 file changed

+36
-8
lines changed

source/daplink/drag-n-drop/vfs_manager.c

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,10 @@ static void build_filesystem(void);
140140
static void file_change_handler(const vfs_filename_t filename, vfs_file_change_t change, vfs_file_t file, vfs_file_t new_file_data);
141141
static void file_data_handler(uint32_t sector, const uint8_t *buf, uint32_t num_of_sectors);
142142
static bool ready_for_state_change(void);
143+
static void abort_remount(void);
143144

144145
static void transfer_update_file_info(vfs_file_t file, uint32_t start_sector, uint32_t size, stream_type_t stream);
146+
static void transfer_reset_file_info(void);
145147
static void transfer_stream_open(stream_type_t stream, uint32_t start_sector);
146148
static void transfer_stream_data(uint32_t sector, const uint8_t *data, uint32_t size);
147149
static void transfer_update_state(error_t status);
@@ -408,7 +410,10 @@ static void file_change_handler(const vfs_filename_t filename, vfs_file_change_t
408410
}
409411

410412
if (VFS_FILE_DELETED == change) {
411-
// Unused
413+
if (file == file_transfer_state.file_to_program) {
414+
// The file that was being transferred has been deleted
415+
transfer_reset_file_info();
416+
}
412417
}
413418
}
414419

@@ -521,6 +526,19 @@ static bool ready_for_state_change(void)
521526
return time_usb_idle > timeout_ms ? true : false;
522527
}
523528

529+
// Abort a remount if one is pending
530+
void abort_remount(void)
531+
{
532+
sync_lock();
533+
534+
// Only abort a remount if in the connected state and reconnecting is the next state
535+
if ((VFS_MNGR_STATE_RECONNECTING == vfs_state_next) && (VFS_MNGR_STATE_CONNECTED == vfs_state)) {
536+
vfs_state_next = VFS_MNGR_STATE_CONNECTED;
537+
}
538+
539+
sync_unlock();
540+
}
541+
524542
// Update the tranfer state with file information
525543
static void transfer_update_file_info(vfs_file_t file, uint32_t start_sector, uint32_t size, stream_type_t stream)
526544
{
@@ -558,8 +576,8 @@ static void transfer_update_file_info(vfs_file_t file, uint32_t start_sector, ui
558576
}
559577
}
560578

561-
// Check - File size must be the same or bigger
562-
if (size < file_transfer_state.file_size) {
579+
// Check - File size must either grow or be smaller than the size already transferred
580+
if ((size < file_transfer_state.file_size) && (size < file_transfer_state.size_transferred)) {
563581
vfs_mngr_printf(" error: file size changed from %i to %i\r\n", file_transfer_state.file_size, size);
564582
transfer_update_state(ERROR_ERROR_DURING_TRANSFER);
565583
return;
@@ -579,15 +597,25 @@ static void transfer_update_file_info(vfs_file_t file, uint32_t start_sector, ui
579597
return;
580598
}
581599

582-
// Update values - Size is the only value that can change and it can only increase.
583-
if (size > file_transfer_state.file_size) {
584-
file_transfer_state.file_size = size;
585-
vfs_mngr_printf(" updated size=%i\r\n", size);
586-
}
600+
// Update values - Size is the only value that can change
601+
file_transfer_state.file_size = size;
602+
vfs_mngr_printf(" updated size=%i\r\n", size);
587603

588604
transfer_update_state(ERROR_SUCCESS);
589605
}
590606

607+
// Reset the transfer information or error if transfer is already in progress
608+
static void transfer_reset_file_info()
609+
{
610+
vfs_mngr_printf("vfs_manager transfer_reset_file_info()\r\n");
611+
if (file_transfer_state.stream_open) {
612+
transfer_update_state(ERROR_ERROR_DURING_TRANSFER);
613+
} else {
614+
file_transfer_state = default_transfer_state;
615+
abort_remount();
616+
}
617+
}
618+
591619
// Update the tranfer state with new information
592620
static void transfer_stream_open(stream_type_t stream, uint32_t start_sector)
593621
{

0 commit comments

Comments
 (0)