Accept FS#11774 by Michael Hohmuth (with some own modifications to #ifdef conditions)

Unmount all filesystems before connecting USB. This ensures that all filehandles are closed, which avoids possible filesystem corruption



git-svn-id: svn://svn.rockbox.org/rockbox/trunk@28693 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Frank Gevaerts 2010-11-28 15:22:51 +00:00
parent 4063389bff
commit 1db3dfdd75
6 changed files with 26 additions and 10 deletions

View file

@ -36,7 +36,6 @@
static DIR_UNCACHED opendirs[MAX_OPEN_DIRS];
#ifdef HAVE_HOTSWAP
// release all dir handles on a given volume "by force", to avoid leaks
int release_dirs(int volume)
{
@ -57,7 +56,6 @@ int release_dirs(int volume)
}
return closed; /* return how many we did */
}
#endif /* #ifdef HAVE_HOTSWAP */
DIR_UNCACHED* opendir_uncached(const char* name)
{

View file

@ -23,10 +23,8 @@
#include "storage.h"
#include "debug.h"
#include "fat.h"
#ifdef HAVE_HOTSWAP
#include "dir.h" /* for release_dirs() */
#include "file.h" /* for release_files() */
#endif
#include "disk.h"
#include <string.h>
@ -235,12 +233,13 @@ int disk_mount(int drive)
return mounted;
}
#ifdef HAVE_HOTSWAP
int disk_unmount(int drive)
{
int unmounted = 0;
int i;
#ifdef HAVE_HOTSWAP
mutex_lock(&disk_mutex);
#endif
for (i=0; i<NUM_VOLUMES; i++)
{
if (vol_drive[i] == drive)
@ -252,8 +251,28 @@ int disk_unmount(int drive)
fat_unmount(i, false);
}
}
#ifdef HAVE_HOTSWAP
mutex_unlock(&disk_mutex);
#endif
return unmounted;
}
#endif /* #ifdef HAVE_HOTSWAP */
int disk_unmount_all(void)
{
#ifndef HAVE_MULTIDRIVE
return disk_unmount(0);
#else /* HAVE_MULTIDRIVE */
int unmounted = 0;
int i;
for (i = 0; i < NUM_DRIVES; i++)
{
#ifdef HAVE_HOTSWAP
if (storage_present(i))
#endif
unmounted += disk_unmount(i);
}
return unmounted;
#endif /* HAVE_MULTIDRIVE */
}

View file

@ -793,7 +793,6 @@ off_t filesize(int fd)
}
#ifdef HAVE_HOTSWAP
/* release all file handles on a given volume "by force", to avoid leaks */
int release_files(int volume)
{
@ -814,4 +813,3 @@ int release_files(int volume)
}
return closed; /* return how many we did */
}
#endif /* #ifdef HAVE_HOTSWAP */

View file

@ -479,7 +479,6 @@ int fat_mount(IF_MV2(int volume,) IF_MD2(int drive,) long startsector)
return 0;
}
#ifdef HAVE_HOTSWAP
int fat_unmount(int volume, bool flush)
{
int rc;
@ -518,7 +517,6 @@ int fat_unmount(int volume, bool flush)
#endif
return rc;
}
#endif /* #ifdef HAVE_HOTSWAP */
void fat_recalc_free(IF_MV_NONVOID(int volume))
{

View file

@ -41,6 +41,7 @@ struct partinfo* disk_partinfo(int partition);
void disk_init_subsystem(void); /* Initialises mutexes */
int disk_mount_all(void); /* returns the # of successful mounts */
int disk_mount(int drive);
int disk_unmount_all(void);
int disk_unmount(int drive);
/* The number of 512-byte sectors in a "logical" sector. Needed for ipod 5.5G */

View file

@ -131,6 +131,7 @@ static inline void usb_slave_mode(bool on)
#ifdef HAVE_PRIORITY_SCHEDULING
thread_set_priority(THREAD_ID_CURRENT, PRIORITY_REALTIME);
#endif
disk_unmount_all();
usb_attach();
}
else /* usb_state == USB_INSERTED (only!) */
@ -172,6 +173,7 @@ static inline void usb_slave_mode(bool on)
if(on)
{
DEBUGF("Entering USB slave mode\n");
disk_unmount_all();
storage_soft_reset();
storage_init();
storage_enable(false);