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 "mpeg.h"
#include "settings.h" #include "settings.h"
#include "ata.h" #include "ata.h"
#include "fat.h"
#ifdef HAVE_LCD_BITMAP #ifdef HAVE_LCD_BITMAP
#include "widgets.h" #include "widgets.h"
#include "peakmeter.h" #include "peakmeter.h"
@ -1149,7 +1150,16 @@ static bool dbg_disk_info(void)
lcd_puts(0, y++, buf); lcd_puts(0, y++, buf);
break; 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)); snprintf(buf, sizeof buf, "%d ms", ata_spinup_time * (1000/HZ));
lcd_puts(0, y++, "Spinup time"); lcd_puts(0, y++, "Spinup time");
lcd_puts(0, y++, buf); lcd_puts(0, y++, buf);
@ -1177,6 +1187,17 @@ static bool dbg_disk_info(void)
if (++page > max_page) if (++page > max_page)
page = 0; page = 0;
break; 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(); lcd_stop_scroll();
} }

View file

@ -165,6 +165,7 @@ struct bpb
static struct bpb fat_bpb; static struct bpb fat_bpb;
static int update_fsinfo(void);
static int first_sector_of_cluster(int cluster); static int first_sector_of_cluster(int cluster);
static int bpb_is_sane(void); static int bpb_is_sane(void);
static void *cache_fat_sector(int secnum); static void *cache_fat_sector(int secnum);
@ -341,23 +342,7 @@ int fat_mount(int startsector)
/* calculate freecount if unset */ /* calculate freecount if unset */
if ( fat_bpb.fsinfo.freecount == 0xffffffff ) if ( fat_bpb.fsinfo.freecount == 0xffffffff )
{ {
int free = 0; fat_recalc_free();
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;
} }
LDEBUGF("Freecount: %d\n",fat_bpb.fsinfo.freecount); LDEBUGF("Freecount: %d\n",fat_bpb.fsinfo.freecount);
@ -369,6 +354,29 @@ int fat_mount(int startsector)
return 0; 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) static int bpb_is_sane(void)
{ {
if(fat_bpb.bpb_bytspersec != 512) if(fat_bpb.bpb_bytspersec != 512)
@ -572,15 +580,41 @@ static int get_next_cluster(unsigned int cluster)
return next_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) static int flush_fat(void)
{ {
int i; int i;
int err; int err;
unsigned char *sec; unsigned char *sec;
int secnum; int secnum;
unsigned char fsinfo[SECTOR_SIZE];
unsigned int* intptr;
LDEBUGF("flush_fat()\n"); LDEBUGF("flush_fat()\n");
for(i = 0;i < FAT_CACHE_SIZE;i++) for(i = 0;i < FAT_CACHE_SIZE;i++)
@ -615,25 +649,8 @@ static int flush_fat(void)
} }
} }
/* update fsinfo */ if (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 -3; 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; return 0;
} }

View file

@ -69,6 +69,7 @@ struct fat_dir
extern int fat_mount(int startsector); extern int fat_mount(int startsector);
extern void fat_size(unsigned int* size, unsigned int* free); 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_create_dir(unsigned int currdir, char *name);
extern int fat_startsector(void); extern int fat_startsector(void);