summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrank Gevaerts <frank@gevaerts.be>2010-11-28 15:22:51 +0000
committerFrank Gevaerts <frank@gevaerts.be>2010-11-28 15:22:51 +0000
commit1db3dfdd759476ae4930958ec775fd2009674091 (patch)
treed3f4ca8200a049ecdad0452ca4bb322e452b2ae6
parent4063389bffe63052da2e78413b0cc1f530733db3 (diff)
downloadrockbox-1db3dfdd759476ae4930958ec775fd2009674091.zip
rockbox-1db3dfdd759476ae4930958ec775fd2009674091.tar.gz
rockbox-1db3dfdd759476ae4930958ec775fd2009674091.tar.bz2
rockbox-1db3dfdd759476ae4930958ec775fd2009674091.tar.xz
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
-rw-r--r--firmware/common/dir_uncached.c2
-rw-r--r--firmware/common/disk.c27
-rw-r--r--firmware/common/file.c2
-rw-r--r--firmware/drivers/fat.c2
-rw-r--r--firmware/export/disk.h1
-rw-r--r--firmware/usb.c2
6 files changed, 26 insertions, 10 deletions
diff --git a/firmware/common/dir_uncached.c b/firmware/common/dir_uncached.c
index e4c4397..00123c1 100644
--- a/firmware/common/dir_uncached.c
+++ b/firmware/common/dir_uncached.c
@@ -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)
{
diff --git a/firmware/common/disk.c b/firmware/common/disk.c
index 6be9b47..400d21f 100644
--- a/firmware/common/disk.c
+++ b/firmware/common/disk.c
@@ -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;
+}
+
+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 */
}
-#endif /* #ifdef HAVE_HOTSWAP */
diff --git a/firmware/common/file.c b/firmware/common/file.c
index da85846..3477c10 100644
--- a/firmware/common/file.c
+++ b/firmware/common/file.c
@@ -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 */
diff --git a/firmware/drivers/fat.c b/firmware/drivers/fat.c
index cff11d2..a99341d 100644
--- a/firmware/drivers/fat.c
+++ b/firmware/drivers/fat.c
@@ -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))
{
diff --git a/firmware/export/disk.h b/firmware/export/disk.h
index db722a8..347d8b4 100644
--- a/firmware/export/disk.h
+++ b/firmware/export/disk.h
@@ -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 */
diff --git a/firmware/usb.c b/firmware/usb.c
index 9eaf201..6309c14 100644
--- a/firmware/usb.c
+++ b/firmware/usb.c
@@ -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);