1
0
Fork 0
forked from len0rd/rockbox

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
This commit is contained in:
Björn Stenberg 2002-12-09 15:39:32 +00:00
parent cf1317c336
commit b17fe5a727
3 changed files with 78 additions and 39 deletions

View file

@ -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();
}

View file

@ -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,7 +342,22 @@ int fat_mount(int startsector)
/* calculate freecount if unset */
if ( fat_bpb.fsinfo.freecount == 0xffffffff )
{
fat_recalc_free();
}
LDEBUGF("Freecount: %d\n",fat_bpb.fsinfo.freecount);
LDEBUGF("Nextfree: %x\n",fat_bpb.fsinfo.nextfree);
LDEBUGF("Cluster count: %x\n",fat_bpb.dataclusters);
LDEBUGF("Sectors per cluster: %d\n",fat_bpb.bpb_secperclus);
LDEBUGF("FAT sectors: %x\n",fat_bpb.fatsize);
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);
@ -358,15 +374,7 @@ int fat_mount(int startsector)
}
}
fat_bpb.fsinfo.freecount = free;
}
LDEBUGF("Freecount: %d\n",fat_bpb.fsinfo.freecount);
LDEBUGF("Nextfree: %x\n",fat_bpb.fsinfo.nextfree);
LDEBUGF("Cluster count: %x\n",fat_bpb.dataclusters);
LDEBUGF("Sectors per cluster: %d\n",fat_bpb.bpb_secperclus);
LDEBUGF("FAT sectors: %x\n",fat_bpb.fatsize);
return 0;
update_fsinfo();
}
static int bpb_is_sane(void)
@ -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;
}

View file

@ -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);