summaryrefslogtreecommitdiffstats
path: root/firmware/common/disk.c
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 /firmware/common/disk.c
parent4063389bffe63052da2e78413b0cc1f530733db3 (diff)
downloadrockbox-1db3dfdd759476ae4930958ec775fd2009674091.tar.gz
rockbox-1db3dfdd759476ae4930958ec775fd2009674091.zip
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
Diffstat (limited to 'firmware/common/disk.c')
-rw-r--r--firmware/common/disk.c27
1 files changed, 23 insertions, 4 deletions
diff --git a/firmware/common/disk.c b/firmware/common/disk.c
index 6be9b47379..400d21f359 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 */