Index: firmware/export/storage.h =================================================================== --- firmware/export/storage.h (revision 25436) +++ firmware/export/storage.h (working copy) @@ -57,6 +57,7 @@ */ #define storage_num_drives() NUM_DRIVES #if (CONFIG_STORAGE & STORAGE_ATA) + #define STORAGE_FUNCTION(NAME) (ata_## NAME) #define storage_spindown ata_spindown #define storage_sleep ata_sleep #define storage_spin ata_spin @@ -67,8 +68,6 @@ #define storage_soft_reset() ata_soft_reset() #define storage_init() ata_init() #define storage_close() ata_close() - #define storage_read_sectors(drive, start, count, buf) ata_read_sectors(IF_MD2(drive,) start, count, buf) - #define storage_write_sectors(drive, start, count, buf) ata_write_sectors(IF_MD2(drive,) start, count, buf) #ifdef HAVE_STORAGE_FLUSH #define storage_flush() (void)0 #endif @@ -84,6 +83,7 @@ #define storage_present(drive) ata_present(IF_MD(drive)) #endif #elif (CONFIG_STORAGE & STORAGE_SD) + #define STORAGE_FUNCTION(NAME) (sd_## NAME) #define storage_spindown sd_spindown #define storage_sleep sd_sleep #define storage_spin sd_spin @@ -93,8 +93,6 @@ #define storage_disk_is_active() 0 #define storage_soft_reset() (void)0 #define storage_init() sd_init() - #define storage_read_sectors(drive, start, count, buf) sd_read_sectors(IF_MD2(drive,) start, count, buf) - #define storage_write_sectors(drive, start, count, buf) sd_write_sectors(IF_MD2(drive,) start, count, buf) #ifdef HAVE_STORAGE_FLUSH #define storage_flush() (void)0 #endif @@ -110,6 +108,7 @@ #define storage_present(drive) sd_present(IF_MD(drive)) #endif #elif (CONFIG_STORAGE & STORAGE_MMC) + #define STORAGE_FUNCTION(NAME) (mmc_## NAME) #define storage_spindown mmc_spindown #define storage_sleep mmc_sleep #define storage_spin mmc_spin @@ -119,8 +118,6 @@ #define storage_disk_is_active() mmc_disk_is_active() #define storage_soft_reset() (void)0 #define storage_init() mmc_init() - #define storage_read_sectors(drive, start, count, buf) mmc_read_sectors(IF_MD2(drive,) start, count, buf) - #define storage_write_sectors(drive, start, count, buf) mmc_write_sectors(IF_MD2(drive,) start, count, buf) #ifdef HAVE_STORAGE_FLUSH #define storage_flush() (void)0 #endif @@ -136,6 +133,7 @@ #define storage_present(drive) mmc_present(IF_MD(drive)) #endif #elif (CONFIG_STORAGE & STORAGE_NAND) + #define STORAGE_FUNCTION(NAME) (nand_## NAME) #define storage_spindown nand_spindown #define storage_sleep nand_sleep #define storage_spin nand_spin @@ -145,8 +143,6 @@ #define storage_disk_is_active() 0 #define storage_soft_reset() (void)0 #define storage_init() nand_init() - #define storage_read_sectors(drive, start, count, buf) nand_read_sectors(IF_MD2(drive,) start, count, buf) - #define storage_write_sectors(drive, start, count, buf) nand_write_sectors(IF_MD2(drive,) start, count, buf) #ifdef HAVE_STORAGE_FLUSH #define storage_flush() nand_flush() #endif @@ -162,6 +158,7 @@ #define storage_present(drive) nand_present(IF_MD(drive)) #endif #elif (CONFIG_STORAGE & STORAGE_RAMDISK) + #define STORAGE_FUNCTION(NAME) (ramdisk_## NAME) #define storage_spindown ramdisk_spindown #define storage_sleep ramdisk_sleep #define storage_spin ramdisk_spin @@ -171,8 +168,6 @@ #define storage_disk_is_active() 0 #define storage_soft_reset() (void)0 #define storage_init() ramdisk_init() - #define storage_read_sectors(drive, start, count, buf) ramdisk_read_sectors(IF_MD2(drive,) start, count, buf) - #define storage_write_sectors(drive, start, count, buf) ramdisk_write_sectors(IF_MD2(drive,) start, count, buf) #ifdef HAVE_STORAGE_FLUSH #define storage_flush() (void)0 #endif @@ -200,8 +195,6 @@ bool storage_disk_is_active(void); int storage_soft_reset(void); int storage_init(void); -int storage_read_sectors(int drive, unsigned long start, int count, void* buf); -int storage_write_sectors(int drive, unsigned long start, int count, const void* buf); int storage_flush(void); void storage_spin(void); void storage_spindown(int seconds); @@ -217,4 +210,8 @@ #endif #endif /* NOT CONFIG_STORAGE_MULTI and NOT SIMULATOR*/ + +bool storage_is_busy_elsewhere(void); +int storage_read_sectors(IF_MD2(int drive,) unsigned long start, int count, void* buf); +int storage_write_sectors(IF_MD2(int drive,) unsigned long start, int count, const void* buf); #endif Index: firmware/usbstack/usb_storage.c =================================================================== --- firmware/usbstack/usb_storage.c (revision 25436) +++ firmware/usbstack/usb_storage.c (working copy) @@ -353,7 +353,7 @@ return true; #else unsigned char sector[SECTOR_SIZE]; - return storage_read_sectors(volume,0,1,sector) == 0; + return storage_read_sectors(IF_MD2(volume,)0,1,sector) == 0; #endif } @@ -537,7 +537,7 @@ cur_cmd.data[cur_cmd.data_select], MIN(WRITE_BUFFER_SIZE/SECTOR_SIZE, cur_cmd.count)*SECTOR_SIZE); #else - int result = storage_write_sectors(cur_cmd.lun, + int result = storage_write_sectors(IF_MD2(cur_cmd.lun,) cur_cmd.sector, MIN(WRITE_BUFFER_SIZE/SECTOR_SIZE, cur_cmd.count), cur_cmd.data[cur_cmd.data_select]); @@ -726,7 +726,7 @@ ramdisk_buffer + cur_cmd.sector*SECTOR_SIZE, MIN(READ_BUFFER_SIZE/SECTOR_SIZE, cur_cmd.count)*SECTOR_SIZE); #else - cur_cmd.last_result = storage_read_sectors(cur_cmd.lun, + cur_cmd.last_result = storage_read_sectors(IF_MD2(cur_cmd.lun,) cur_cmd.sector, MIN(READ_BUFFER_SIZE/SECTOR_SIZE, cur_cmd.count), cur_cmd.data[cur_cmd.data_select]); @@ -1070,7 +1070,7 @@ ramdisk_buffer + cur_cmd.sector*SECTOR_SIZE, MIN(READ_BUFFER_SIZE/SECTOR_SIZE,cur_cmd.count)*SECTOR_SIZE); #else - cur_cmd.last_result = storage_read_sectors(cur_cmd.lun, + cur_cmd.last_result = storage_read_sectors(IF_MD2(cur_cmd.lun,) cur_cmd.sector, MIN(READ_BUFFER_SIZE/SECTOR_SIZE, cur_cmd.count), cur_cmd.data[cur_cmd.data_select]); Index: firmware/SOURCES =================================================================== --- firmware/SOURCES (revision 25436) +++ 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 25436) +++ firmware/storage.c (working copy) @@ -19,7 +19,10 @@ * ****************************************************************************/ #include "storage.h" +#include "kernel.h" +#ifdef CONFIG_STORAGE_MULTI + #define DRIVER_MASK 0xff000000 #define DRIVER_OFFSET 24 #define DRIVE_MASK 0x00ff0000 @@ -28,7 +31,121 @@ static unsigned int storage_drivers[NUM_DRIVES]; static unsigned int num_drives; +#endif + +#ifdef HAVE_DIRCACHE +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()); +} +#endif + +int storage_read_sectors(IF_MD2(int drive,) unsigned long start, int count, + void* buf) +{ +#ifdef HAVE_DIRCACHE + storage_last_thread = thread_get_current(); +#endif + +#ifdef CONFIG_STORAGE_MULTI + 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) + case STORAGE_ATA: + return ata_read_sectors(IF_MD2(ldrive,) start,count,buf); +#endif + +#if (CONFIG_STORAGE & STORAGE_MMC) + case STORAGE_MMC: + return mmc_read_sectors(IF_MD2(ldrive,) start,count,buf); +#endif + +#if (CONFIG_STORAGE & STORAGE_SD) + case STORAGE_SD: + return sd_read_sectors(IF_MD2(ldrive,) start,count,buf); +#endif + +#if (CONFIG_STORAGE & STORAGE_NAND) + case STORAGE_NAND: + return nand_read_sectors(IF_MD2(ldrive,) start,count,buf); +#endif + +#if (CONFIG_STORAGE & STORAGE_RAMDISK) + case STORAGE_RAMDISK: + return ramdisk_read_sectors(IF_MD2(ldrive,) start,count,buf); +#endif + } + + return -1; +#else /* CONFIG_STORAGE_MULTI */ + return STORAGE_FUNCTION(read_sectors)(IF_MD2(drive,)start,count,buf); +#endif /* CONFIG_STORAGE_MULTI */ + +} + +int storage_write_sectors(IF_MD2(int drive,) unsigned long start, int count, + const void* buf) +{ +#ifdef HAVE_DIRCACHE + storage_last_thread = thread_get_current(); +#endif + +#ifdef CONFIG_STORAGE_MULTI + 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) + case STORAGE_ATA: + return ata_write_sectors(IF_MD2(ldrive,)start,count,buf); +#endif + +#if (CONFIG_STORAGE & STORAGE_MMC) + case STORAGE_MMC: + return mmc_write_sectors(IF_MD2(ldrive,)start,count,buf); +#endif + +#if (CONFIG_STORAGE & STORAGE_SD) + case STORAGE_SD: + return sd_write_sectors(IF_MD2(ldrive,)start,count,buf); +#endif + +#if (CONFIG_STORAGE & STORAGE_NAND) + case STORAGE_NAND: + return nand_write_sectors(IF_MD2(ldrive,)start,count,buf); +#endif + +#if (CONFIG_STORAGE & STORAGE_RAMDISK) + case STORAGE_RAMDISK: + return ramdisk_write_sectors(IF_MD2(ldrive,)start,count,buf); +#endif + } + + return -1; +#else /* CONFIG_STORAGE_MULTI */ + return STORAGE_FUNCTION(write_sectors)(IF_MD2(drive,)start,count,buf); +#endif /* CONFIG_STORAGE_MULTI */ +} + +#ifdef CONFIG_STORAGE_MULTI + +#define DRIVER_MASK 0xff000000 +#define DRIVER_OFFSET 24 +#define DRIVE_MASK 0x00ff0000 +#define DRIVE_OFFSET 16 +#define PARTITION_MASK 0x0000ff00 + +static unsigned int storage_drivers[NUM_DRIVES]; +static unsigned int num_drives; + int storage_num_drives(void) { return num_drives; @@ -98,80 +215,7 @@ return 0; } -int storage_read_sectors(int drive, unsigned long start, int count, - void* buf) -{ - 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) - case STORAGE_ATA: - return ata_read_sectors(ldrive,start,count,buf); -#endif -#if (CONFIG_STORAGE & STORAGE_MMC) - case STORAGE_MMC: - return mmc_read_sectors(ldrive,start,count,buf); -#endif - -#if (CONFIG_STORAGE & STORAGE_SD) - case STORAGE_SD: - return sd_read_sectors(ldrive,start,count,buf); -#endif - -#if (CONFIG_STORAGE & STORAGE_NAND) - case STORAGE_NAND: - return nand_read_sectors(ldrive,start,count,buf); -#endif - -#if (CONFIG_STORAGE & STORAGE_RAMDISK) - case STORAGE_RAMDISK: - return ramdisk_read_sectors(ldrive,start,count,buf); -#endif - } - - return -1; -} - -int storage_write_sectors(int drive, unsigned long start, int count, - const void* buf) -{ - 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) - case STORAGE_ATA: - return ata_write_sectors(ldrive,start,count,buf); -#endif - -#if (CONFIG_STORAGE & STORAGE_MMC) - case STORAGE_MMC: - return mmc_write_sectors(ldrive,start,count,buf); -#endif - -#if (CONFIG_STORAGE & STORAGE_SD) - case STORAGE_SD: - return sd_write_sectors(ldrive,start,count,buf); -#endif - -#if (CONFIG_STORAGE & STORAGE_NAND) - case STORAGE_NAND: - return nand_write_sectors(ldrive,start,count,buf); -#endif - -#if (CONFIG_STORAGE & STORAGE_RAMDISK) - case STORAGE_RAMDISK: - return ramdisk_write_sectors(ldrive,start,count,buf); -#endif - } - - return -1; -} - void storage_enable(bool on) { #if (CONFIG_STORAGE & STORAGE_ATA) @@ -572,3 +616,5 @@ return ret; } #endif + +#endif /*CONFIG_STORAGE_MULTI*/ Index: firmware/common/disk.c =================================================================== --- firmware/common/disk.c (revision 25436) +++ firmware/common/disk.c (working copy) @@ -82,7 +82,7 @@ (void)drive; #endif - storage_read_sectors(drive, 0,1, §or); + storage_read_sectors(IF_MD2(drive,) 0,1, §or); /* check that the boot sector is initialized */ if ( (sector[510] != 0x55) || (sector[511] != 0xaa)) { Index: firmware/common/dircache.c =================================================================== --- firmware/common/dircache.c (revision 25436) +++ 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,13 @@ if(check_event_queue()) return -6; yield(); + while(storage_is_busy_elsewhere()) + { + sleep(HZ/20); + /* Stop if we got an external signal. */ + if(check_event_queue()) + return -6; + } } } Index: firmware/drivers/fat.c =================================================================== --- firmware/drivers/fat.c (revision 25436) +++ firmware/drivers/fat.c (working copy) @@ -311,7 +311,7 @@ #endif /* Read the sector */ - rc = storage_read_sectors(drive, startsector,1,buf); + rc = storage_read_sectors(IF_MD2(drive,) startsector,1,buf); if(rc) { DEBUGF( "fat_mount() - Couldn't read BPB (error code %d)\n", rc); @@ -433,7 +433,7 @@ #endif /* #ifdef HAVE_FAT16SUPPORT */ { /* Read the fsinfo sector */ - rc = storage_read_sectors(drive, + rc = storage_read_sectors(IF_MD2(drive,) startsector + fat_bpb->bpb_fsinfo, 1, buf); if (rc < 0) { @@ -618,7 +618,7 @@ #endif /* Write to the first FAT */ - rc = storage_write_sectors(fce->fat_vol->drive, + rc = storage_write_sectors(IF_MD2(fce->fat_vol->drive,) secnum, 1, sectorbuf); if(rc < 0) @@ -639,7 +639,7 @@ #else secnum += fat_bpbs[0].fatsize; #endif - rc = storage_write_sectors(fce->fat_vol->drive, + rc = storage_write_sectors(IF_MD2(fce->fat_vol->drive,) secnum, 1, sectorbuf); if(rc < 0) { @@ -685,7 +685,7 @@ /* Load the sector if it is not cached */ if(!fce->inuse) { - rc = storage_read_sectors(fat_bpb->drive, + rc = storage_read_sectors(IF_MD2(fat_bpb->drive,) secnum + fat_bpb->startsector,1, sectorbuf); if(rc < 0) @@ -944,7 +944,7 @@ #endif /* #ifdef HAVE_FAT16SUPPORT */ /* update fsinfo */ - rc = storage_read_sectors(fat_bpb->drive, + rc = storage_read_sectors(IF_MD2(fat_bpb->drive,) fat_bpb->startsector + fat_bpb->bpb_fsinfo, 1,fsinfo); if (rc < 0) { @@ -957,7 +957,7 @@ intptr = (long*)&(fsinfo[FSINFO_NEXTFREE]); *intptr = htole32(fat_bpb->fsinfo.nextfree); - rc = storage_write_sectors(fat_bpb->drive, + rc = storage_write_sectors(IF_MD2(fat_bpb->drive,) fat_bpb->startsector + fat_bpb->bpb_fsinfo,1,fsinfo); if (rc < 0) { @@ -2110,11 +2110,11 @@ if (start + count > fat_bpb->totalsectors) panicf("Write %ld after data\n", start + count - fat_bpb->totalsectors); - rc = storage_write_sectors(fat_bpb->drive, + rc = storage_write_sectors(IF_MD2(fat_bpb->drive,) start + fat_bpb->startsector, count, buf); } else - rc = storage_read_sectors(fat_bpb->drive, + rc = storage_read_sectors(IF_MD2(fat_bpb->drive,) start + fat_bpb->startsector, count, buf); if (rc < 0) { DEBUGF( "transfer() - Couldn't %s sector %lx"