Shared mounting code, also more general. It will mount multiple HD partitions, too, once HAVE_MULTIVOLUME is enabled.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@5518 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Jörg Hohensohn 2004-12-29 22:10:24 +00:00
parent 5c631a1222
commit 1a5962f2be
4 changed files with 57 additions and 78 deletions

View file

@ -156,7 +156,6 @@ void init(void)
void init(void) void init(void)
{ {
int rc, i; int rc, i;
struct partinfo* pinfo;
/* if nobody initialized ATA before, I consider this a cold start */ /* if nobody initialized ATA before, I consider this a cold start */
bool coldstart = (PACR2 & 0x4000) != 0; /* starting from Flash */ bool coldstart = (PACR2 & 0x4000) != 0; /* starting from Flash */
@ -240,12 +239,12 @@ void init(void)
usb_start_monitoring(); usb_start_monitoring();
/* FixMe: the same kind of mounting happens in usb.c, share the code. */ /* FixMe: the same kind of mounting happens in usb.c, share the code. */
pinfo = disk_init(IF_MV(0)); rc = disk_mount_all();
if (!pinfo) if (rc<=0)
{ {
lcd_clear_display(); lcd_clear_display();
lcd_puts(0, 0, "No partition"); lcd_puts(0, 0, "No partition");
lcd_puts(0, 1, "table."); lcd_puts(0, 1, "found.");
#ifdef HAVE_LCD_BITMAP #ifdef HAVE_LCD_BITMAP
lcd_puts(0, 2, "Insert USB cable"); lcd_puts(0, 2, "Insert USB cable");
lcd_puts(0, 3, "and fix it."); lcd_puts(0, 3, "and fix it.");
@ -256,47 +255,6 @@ void init(void)
system_reboot(); system_reboot();
} }
fat_init();
for ( i=0; i<4; i++ ) {
if (!fat_mount(IF_MV2(0,) IF_MV2(0,) pinfo[i].start))
break; /* only one partition gets mounted as of now */
}
if ( i==4 ) {
DEBUGF("No partition found, trying to mount sector 0.\n");
rc = fat_mount(IF_MV2(0,) IF_MV2(0,) 0);
if(rc) {
lcd_clear_display();
lcd_puts(0,0,"No FAT32");
lcd_puts(0,1,"partition!");
lcd_update();
sleep(HZ);
/* Don't leave until we have been in USB mode */
while(!dbg_partitions());
/* The USB thread will panic if the drive still can't be mounted */
}
}
#ifdef HAVE_MULTIVOLUME
/* mount partition on the optional volume */
#ifdef HAVE_MMC
if (mmc_detect()) /* for Ondio, only if card detected */
#endif
{
pinfo = disk_init(1);
if (pinfo)
{
for ( i=0; i<4; i++ ) {
if (!fat_mount(1, 1, pinfo[i].start))
break; /* only one partition gets mounted as of now */
}
if ( i==4 ) {
rc = fat_mount(1, 1, 0);
}
}
}
#endif /* #ifdef HAVE_MULTIVOLUME */
settings_calc_config_sector(); settings_calc_config_sector();
settings_load(SETTINGS_ALL); settings_load(SETTINGS_ALL);
settings_apply(); settings_apply();

View file

@ -19,6 +19,10 @@
#include <stdio.h> #include <stdio.h>
#include "ata.h" #include "ata.h"
#include "debug.h" #include "debug.h"
#include "fat.h"
#ifdef HAVE_MMC
#include "ata_mmc.h"
#endif
#include "disk.h" #include "disk.h"
/* Partition table entry layout: /* Partition table entry layout:
@ -39,7 +43,7 @@
(array[pos] | (array[pos+1] << 8 ) | \ (array[pos] | (array[pos+1] << 8 ) | \
(array[pos+2] << 16 ) | (array[pos+3] << 24 )) (array[pos+2] << 16 ) | (array[pos+3] << 24 ))
static struct partinfo part[8]; static struct partinfo part[8]; /* space for 4 partitions on 2 drives */
struct partinfo* disk_init(IF_MV_NONVOID(int drive)) struct partinfo* disk_init(IF_MV_NONVOID(int drive))
{ {
@ -89,3 +93,48 @@ struct partinfo* disk_partinfo(int partition)
return &part[partition]; return &part[partition];
} }
int disk_mount_all(void)
{
struct partinfo* pinfo;
int i,j;
int mounted = 0;
bool found;
int drives = 1;
#ifdef HAVE_MMC
if (mmc_detect()) /* for Ondio, only if card detected */
{
drives = 2; /* in such case we have two drives to try */
}
#endif
fat_init(); /* reset all mounted partitions */
for (j=0; j<drives; j++)
{
found = false; /* reset partition-on-drive flag */
pinfo = disk_init(IF_MV(j));
if (pinfo == NULL)
{
continue;
}
for (i=0; mounted<NUM_VOLUMES && i<4; i++)
{
if (!fat_mount(IF_MV2(mounted,) IF_MV2(j,) pinfo[i].start))
{
mounted++;
found = true; /* at least one valid entry */
}
}
if (!found && mounted<NUM_VOLUMES) /* none of the 4 entries worked? */
{ /* try "superfloppy" mode */
DEBUGF("No partition found, trying to mount sector 0.\n");
if (!fat_mount(IF_MV2(mounted,) IF_MV2(j,) 0))
{
mounted++;
}
}
}
return mounted;
}

View file

@ -34,5 +34,6 @@ struct partinfo {
/* returns a pointer to an array of 8 partinfo structs */ /* returns a pointer to an array of 8 partinfo structs */
struct partinfo* disk_init(IF_MV_NONVOID(int volume)); struct partinfo* disk_init(IF_MV_NONVOID(int volume));
struct partinfo* disk_partinfo(int partition); struct partinfo* disk_partinfo(int partition);
int disk_mount_all(void); /* returns the # of successful mounts */
#endif #endif

View file

@ -122,7 +122,6 @@ static void usb_enable(bool on)
static void usb_slave_mode(bool on) static void usb_slave_mode(bool on)
{ {
int rc; int rc;
struct partinfo* pinfo;
if(on) if(on)
{ {
@ -135,7 +134,6 @@ static void usb_slave_mode(bool on)
} }
else else
{ {
int i;
DEBUGF("Leaving USB slave mode\n"); DEBUGF("Leaving USB slave mode\n");
/* Let the ISDx00 settle */ /* Let the ISDx00 settle */
@ -146,6 +144,7 @@ static void usb_slave_mode(bool on)
rc = ata_init(); rc = ata_init();
if(rc) if(rc)
{ {
/* fixme: can we remove this? (already such in main.c) */
char str[32]; char str[32];
lcd_clear_display(); lcd_clear_display();
snprintf(str, 31, "ATA error: %d", rc); snprintf(str, 31, "ATA error: %d", rc);
@ -157,38 +156,10 @@ static void usb_slave_mode(bool on)
panicf("ata: %d",rc); panicf("ata: %d",rc);
} }
pinfo = disk_init(IF_MV(0)); rc = disk_mount_all();
if (!pinfo) if (rc <= 0) /* no partition */
panicf("disk: NULL");
fat_init();
for ( i=0; i<4; i++ ) {
rc = fat_mount(IF_MV2(0,) IF_MV2(0,) pinfo[i].start);
if (!rc)
break; /* only one partition gets mounted as of now */
}
if (i==4)
panicf("mount: %d",rc); panicf("mount: %d",rc);
#ifdef HAVE_MULTIVOLUME
/* mount partition on the optional volume */
#ifdef HAVE_MMC
if (mmc_detect()) /* for Ondio, only if card detected */
#endif
{
pinfo = disk_init(1);
if (pinfo)
{
for ( i=0; i<4; i++ ) {
if (!fat_mount(1, 1, pinfo[i].start))
break; /* only one partition gets mounted as of now */
}
if ( i==4 ) {
rc = fat_mount(1, 1, 0);
}
}
}
#endif /* #ifdef HAVE_MULTIVOLUME */
} }
} }