Index: firmware/export/storage.h =================================================================== --- firmware/export/storage.h (revision 25429) +++ firmware/export/storage.h (working copy) @@ -217,4 +217,7 @@ #endif #endif /* NOT CONFIG_STORAGE_MULTI and NOT SIMULATOR*/ + +extern unsigned int storage_last_thread; +bool storage_is_busy_elsewhere(void); #endif Index: firmware/SOURCES =================================================================== --- firmware/SOURCES (revision 25429) +++ firmware/SOURCES (working copy) @@ -152,9 +152,7 @@ #if (CONFIG_STORAGE & STORAGE_RAMDISK) drivers/ramdisk.c #endif -#ifdef CONFIG_STORAGE_MULTI storage.c -#endif drivers/fat.c #if (CONFIG_STORAGE & STORAGE_MMC) || (CONFIG_STORAGE & STORAGE_SD) hotswap.c Index: firmware/storage.c =================================================================== --- firmware/storage.c (revision 25429) +++ firmware/storage.c (working copy) @@ -19,7 +19,18 @@ * ****************************************************************************/ #include "storage.h" +#include "kernel.h" +unsigned int storage_last_thread; + +bool storage_is_busy_elsewhere(void) +{ + return (current_tick-storage_last_disk_activity() < (HZ/10) && + storage_last_thread != thread_get_current()); +} + +#ifdef CONFIG_STORAGE_MULTI + #define DRIVER_MASK 0xff000000 #define DRIVER_OFFSET 24 #define DRIVE_MASK 0x00ff0000 @@ -103,7 +114,7 @@ { int driver=(storage_drivers[drive] & DRIVER_MASK)>>DRIVER_OFFSET; int ldrive=(storage_drivers[drive] & DRIVE_MASK)>>DRIVE_OFFSET; - + switch (driver) { #if (CONFIG_STORAGE & STORAGE_ATA) @@ -141,6 +152,8 @@ int driver=(storage_drivers[drive] & DRIVER_MASK)>>DRIVER_OFFSET; int ldrive=(storage_drivers[drive] & DRIVE_MASK)>>DRIVE_OFFSET; + last_thread = thread_get_current(); + switch (driver) { #if (CONFIG_STORAGE & STORAGE_ATA) @@ -572,3 +585,5 @@ return ret; } #endif + +#endif /*CONFIG_STORAGE_MULTI*/ Index: firmware/common/dircache.c =================================================================== --- firmware/common/dircache.c (revision 25429) +++ firmware/common/dircache.c (working copy) @@ -40,6 +40,7 @@ #include "file.h" #include "buffer.h" #include "dir.h" +#include "storage.h" #if CONFIG_RTC #include "time.h" #include "timefuncs.h" @@ -236,6 +237,10 @@ if(check_event_queue()) return -6; yield(); + while(storage_is_busy_elsewhere()) + { + sleep(HZ/20); + } } } Index: firmware/drivers/ata.c =================================================================== --- firmware/drivers/ata.c (revision 25429) +++ firmware/drivers/ata.c (working copy) @@ -356,6 +356,8 @@ bool usedma = false; #endif + storage_last_thread = thread_get_current(); + #ifndef MAX_PHYS_SECTOR_SIZE mutex_lock(&ata_mtx); #endif