FS#10913 - File Browser not updated properly upon microSD insert/removal with dircache enabled

Attached to Project: Rockbox
Opened by Michael Chicoine (mc2739) - Thursday, 14 January 2010, 15:43 GMT
Last edited by amaury pouly (pamaury) - Friday, 21 May 2010, 09:28 GMT
Task Type Bugs
Category Drivers
Status Closed
Assigned To No-one
Operating System Sansa e200
Severity Low
Priority Normal
Reported Version Daily build (which?)
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 0
Private No


With dircache disabled, if you are in the file browser and insert or remove the microSD card it will consistently update the list by adding <microSD1> on insert and removing it when the card is removed.

With dircache enabled, the list is not consistently updated.

Tested with r24224 and as old as r22000 on e280v1
Tested with r24224 on e260v2

Process to reproduce:
1. Boot and clear all settings
2. Enable dircache setting
3. Power off and reboot
4. Enter the file browser by selecting Files on the Main Menu
5. Insert and remove microSD card and observe the Files list

If the microSD card was not inserted on boot, the list is not updated on the first insert. After the card is removed, subsequent inserts/removals seem to update properly.

If the microSD card was inserted on boot, the list is not updated on the first removal. Upon insert, the list may or may not update. The updates are very inconsistent on subsequent inserts/removals. If you exit the file browser and then reenter, the correct state is shown.
This task depends upon

Closed by  amaury pouly (pamaury)
Friday, 21 May 2010, 09:28 GMT
Reason for closing:  Fixed
Additional comments about closing:  r26222
Comment by amaury pouly (pamaury) - Sunday, 21 February 2010, 13:36 GMT
I'm investigating the bug and I think it's due to the following issue:
On microSD insertion/removal, SYS_FS_CHANGED (SFC) is triggered. This SFC message is used in two placed:
- in the file browser (tree.c:dirbrowse) (1)
=> it triggers a complete reload of the current directory and a complete redraw
- in the dircache thread (dircache.c:dircache_thread) (2)
=> it disables dircache and ask for a transparent rebuild

Now, the problem is the synchronization because if (1) happen before (2), (1) will call ft_load that will ask dircache to opendir/readdir the current directory, but as (2) as not yet happened, dircache is still enabled and thus the sd insertion has not yet been taken into the dircache subsystem.

So the solution is to make sure that (2) happens before (1).