diff options
author | Björn Stenberg <bjorn@haxx.se> | 2002-12-09 15:39:32 +0000 |
---|---|---|
committer | Björn Stenberg <bjorn@haxx.se> | 2002-12-09 15:39:32 +0000 |
commit | b17fe5a72722352747111bcb188b4821135ce0b6 (patch) | |
tree | 6c252b310ac3aa9890622eb9529c47fac97e7cb6 | |
parent | cf1317c336c946ee2eeda61729171bae82d87769 (diff) |
Added recalculation of free disk space. Press PLAY in Debug->Disk Info->Free to run it. Takes ~30 sec on my 40GB Toshiba.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@2968 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r-- | apps/debug_menu.c | 23 | ||||
-rw-r--r-- | firmware/drivers/fat.c | 93 | ||||
-rw-r--r-- | firmware/drivers/fat.h | 1 |
3 files changed, 78 insertions, 39 deletions
diff --git a/apps/debug_menu.c b/apps/debug_menu.c index 4c1c9893cb..2dbe472456 100644 --- a/apps/debug_menu.c +++ b/apps/debug_menu.c @@ -40,6 +40,7 @@ #include "mpeg.h" #include "settings.h" #include "ata.h" +#include "fat.h" #ifdef HAVE_LCD_BITMAP #include "widgets.h" #include "peakmeter.h" @@ -1149,7 +1150,16 @@ static bool dbg_disk_info(void) lcd_puts(0, y++, buf); break; - case 3: + case 3: { + unsigned int free; + fat_size( NULL, &free ); + snprintf(buf, sizeof buf, "%d MB", free / 1024 ); + lcd_puts(0, y++, "Free"); + lcd_puts(0, y++, buf); + break; + } + + case 4: snprintf(buf, sizeof buf, "%d ms", ata_spinup_time * (1000/HZ)); lcd_puts(0, y++, "Spinup time"); lcd_puts(0, y++, buf); @@ -1177,6 +1187,17 @@ static bool dbg_disk_info(void) if (++page > max_page) page = 0; break; + + case BUTTON_PLAY: + if (page == 3) { + mpeg_stop(); /* stop playback, to avoid disk access */ + lcd_clear_display(); + lcd_puts(0,0,"Scanning"); + lcd_puts(0,1,"disk..."); + lcd_update(); + fat_recalc_free(); + } + break; } lcd_stop_scroll(); } diff --git a/firmware/drivers/fat.c b/firmware/drivers/fat.c index 907947f31b..a5b900216b 100644 --- a/firmware/drivers/fat.c +++ b/firmware/drivers/fat.c @@ -165,6 +165,7 @@ struct bpb static struct bpb fat_bpb; +static int update_fsinfo(void); static int first_sector_of_cluster(int cluster); static int bpb_is_sane(void); static void *cache_fat_sector(int secnum); @@ -341,23 +342,7 @@ int fat_mount(int startsector) /* calculate freecount if unset */ if ( fat_bpb.fsinfo.freecount == 0xffffffff ) { - int free = 0; - for (i = 0; i<fat_bpb.fatsize; i++) { - unsigned int j; - unsigned int* fat = cache_fat_sector(i); - for (j = 0; j < CLUSTERS_PER_FAT_SECTOR; j++) { - unsigned int c = i * CLUSTERS_PER_FAT_SECTOR + j; - if ( c > fat_bpb.dataclusters+1 ) /* nr 0 is unused */ - break; - - if (!(SWAB32(fat[j]) & 0x0fffffff)) { - free++; - if ( fat_bpb.fsinfo.nextfree == 0xffffffff ) - fat_bpb.fsinfo.nextfree = c; - } - } - } - fat_bpb.fsinfo.freecount = free; + fat_recalc_free(); } LDEBUGF("Freecount: %d\n",fat_bpb.fsinfo.freecount); @@ -369,6 +354,29 @@ int fat_mount(int startsector) return 0; } +void fat_recalc_free(void) +{ + int free = 0; + unsigned i; + for (i = 0; i<fat_bpb.fatsize; i++) { + unsigned int j; + unsigned int* fat = cache_fat_sector(i); + for (j = 0; j < CLUSTERS_PER_FAT_SECTOR; j++) { + unsigned int c = i * CLUSTERS_PER_FAT_SECTOR + j; + if ( c > fat_bpb.dataclusters+1 ) /* nr 0 is unused */ + break; + + if (!(SWAB32(fat[j]) & 0x0fffffff)) { + free++; + if ( fat_bpb.fsinfo.nextfree == 0xffffffff ) + fat_bpb.fsinfo.nextfree = c; + } + } + } + fat_bpb.fsinfo.freecount = free; + update_fsinfo(); +} + static int bpb_is_sane(void) { if(fat_bpb.bpb_bytspersec != 512) @@ -572,15 +580,41 @@ static int get_next_cluster(unsigned int cluster) return next_cluster; } +static int update_fsinfo(void) +{ + unsigned char fsinfo[SECTOR_SIZE]; + unsigned int* intptr; + int err; + + /* update fsinfo */ + err = ata_read_sectors(fat_bpb.startsector + fat_bpb.bpb_fsinfo, 1,fsinfo); + if (err) + { + DEBUGF( "flush_fat() - Couldn't read FSInfo (error code %d)\n", err); + return -1; + } + intptr = (int*)&(fsinfo[FSINFO_FREECOUNT]); + *intptr = SWAB32(fat_bpb.fsinfo.freecount); + + intptr = (int*)&(fsinfo[FSINFO_NEXTFREE]); + *intptr = SWAB32(fat_bpb.fsinfo.nextfree); + + err = ata_write_sectors(fat_bpb.startsector + fat_bpb.bpb_fsinfo,1,fsinfo); + if (err) + { + DEBUGF( "flush_fat() - Couldn't write FSInfo (error code %d)\n", err); + return -2; + } + + return 0; +} + static int flush_fat(void) { int i; int err; unsigned char *sec; int secnum; - unsigned char fsinfo[SECTOR_SIZE]; - unsigned int* intptr; - LDEBUGF("flush_fat()\n"); for(i = 0;i < FAT_CACHE_SIZE;i++) @@ -615,25 +649,8 @@ static int flush_fat(void) } } - /* update fsinfo */ - err = ata_read_sectors(fat_bpb.startsector + fat_bpb.bpb_fsinfo, 1,fsinfo); - if (err) - { - DEBUGF( "flush_fat() - Couldn't read FSInfo (error code %d)\n", err); + if (update_fsinfo()) return -3; - } - intptr = (int*)&(fsinfo[FSINFO_FREECOUNT]); - *intptr = SWAB32(fat_bpb.fsinfo.freecount); - - intptr = (int*)&(fsinfo[FSINFO_NEXTFREE]); - *intptr = SWAB32(fat_bpb.fsinfo.nextfree); - - err = ata_write_sectors(fat_bpb.startsector + fat_bpb.bpb_fsinfo,1,fsinfo); - if (err) - { - DEBUGF( "flush_fat() - Couldn't write FSInfo (error code %d)\n", err); - return -4; - } return 0; } diff --git a/firmware/drivers/fat.h b/firmware/drivers/fat.h index d81ec65363..8d2382f57c 100644 --- a/firmware/drivers/fat.h +++ b/firmware/drivers/fat.h @@ -69,6 +69,7 @@ struct fat_dir extern int fat_mount(int startsector); extern void fat_size(unsigned int* size, unsigned int* free); +extern void fat_recalc_free(void); extern int fat_create_dir(unsigned int currdir, char *name); extern int fat_startsector(void); |