forked from len0rd/rockbox
preparations for hotswapping MMC
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@5701 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
3662ad2ae3
commit
dc7534bdb2
7 changed files with 128 additions and 36 deletions
|
|
@ -23,6 +23,8 @@
|
|||
#ifdef HAVE_MMC
|
||||
#include "ata_mmc.h"
|
||||
#endif
|
||||
#include "file.h" /* for release_dirs() */
|
||||
#include "dir.h" /* for release_files() */
|
||||
#include "disk.h"
|
||||
|
||||
/* Partition table entry layout:
|
||||
|
|
@ -44,6 +46,7 @@
|
|||
((long)array[pos+2] << 16 ) | ((long)array[pos+3] << 24 ))
|
||||
|
||||
static struct partinfo part[8]; /* space for 4 partitions on 2 drives */
|
||||
static int vol_drive[NUM_VOLUMES]; /* mounted to which drive (-1 if none) */
|
||||
|
||||
struct partinfo* disk_init(IF_MV_NONVOID(int drive))
|
||||
{
|
||||
|
|
@ -95,46 +98,86 @@ struct partinfo* disk_partinfo(int partition)
|
|||
|
||||
int disk_mount_all(void)
|
||||
{
|
||||
struct partinfo* pinfo;
|
||||
int i,j;
|
||||
int mounted = 0;
|
||||
bool found;
|
||||
int drives = 1;
|
||||
int mounted;
|
||||
int i;
|
||||
|
||||
fat_init(); /* reset all mounted partitions */
|
||||
for (i=0; i<NUM_VOLUMES; i++)
|
||||
vol_drive[i] = -1; /* mark all as unassigned */
|
||||
|
||||
mounted = disk_mount(0);
|
||||
#ifdef HAVE_MMC
|
||||
if (mmc_detect()) /* for Ondio, only if card detected */
|
||||
{
|
||||
drives = 2; /* in such case we have two drives to try */
|
||||
mounted += disk_mount(1); /* try 2nd "drive", too */
|
||||
}
|
||||
#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;
|
||||
}
|
||||
|
||||
static int get_free_volume(void)
|
||||
{
|
||||
int i;
|
||||
for (i=0; i<NUM_VOLUMES; i++)
|
||||
{
|
||||
if (vol_drive[i] == -1) /* unassigned? */
|
||||
return i;
|
||||
}
|
||||
|
||||
return -1; /* none found */
|
||||
}
|
||||
|
||||
int disk_mount(int drive)
|
||||
{
|
||||
int i;
|
||||
int mounted = 0; /* reset partition-on-drive flag */
|
||||
int volume = get_free_volume();
|
||||
struct partinfo* pinfo = disk_init(IF_MV(drive));
|
||||
|
||||
if (pinfo == NULL)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
for (i=0; volume != -1 && i<4; i++)
|
||||
{
|
||||
if (!fat_mount(IF_MV2(volume,) IF_MV2(drive,) pinfo[i].start))
|
||||
{
|
||||
mounted++;
|
||||
vol_drive[volume] = drive; /* remember the drive for this volume */
|
||||
volume = get_free_volume(); /* prepare next entry */
|
||||
}
|
||||
}
|
||||
|
||||
if (mounted == 0 && volume != -1) /* none of the 4 entries worked? */
|
||||
{ /* try "superfloppy" mode */
|
||||
DEBUGF("No partition found, trying to mount sector 0.\n");
|
||||
if (!fat_mount(IF_MV2(volume,) IF_MV2(drive,) 0))
|
||||
{
|
||||
mounted = 1;
|
||||
vol_drive[volume] = drive; /* remember the drive for this volume */
|
||||
}
|
||||
}
|
||||
return mounted;
|
||||
}
|
||||
|
||||
#ifdef HAVE_HOTSWAP
|
||||
int disk_unmount(int drive)
|
||||
{
|
||||
int unmounted = 0;
|
||||
int i;
|
||||
for (i=0; i<NUM_VOLUMES; i++)
|
||||
{
|
||||
if (vol_drive[i] == drive)
|
||||
{ /* force releasing resources */
|
||||
vol_drive[i] = -1; /* mark unused */
|
||||
unmounted++;
|
||||
release_files(i);
|
||||
release_dirs(i);
|
||||
fat_unmount(i, false);
|
||||
}
|
||||
}
|
||||
|
||||
return unmounted;
|
||||
}
|
||||
#endif /* #ifdef HAVE_HOTSWAP */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue