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.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
-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 e4c4397fe2..00123c1b07 100644
--- a/firmware/common/dir_uncached.c
+++ b/firmware/common/dir_uncached.c
@@ -36,7 +36,6 @@
36 36
37static DIR_UNCACHED opendirs[MAX_OPEN_DIRS]; 37static DIR_UNCACHED opendirs[MAX_OPEN_DIRS];
38 38
39#ifdef HAVE_HOTSWAP
40// release all dir handles on a given volume "by force", to avoid leaks 39// release all dir handles on a given volume "by force", to avoid leaks
41int release_dirs(int volume) 40int release_dirs(int volume)
42{ 41{
@@ -57,7 +56,6 @@ int release_dirs(int volume)
57 } 56 }
58 return closed; /* return how many we did */ 57 return closed; /* return how many we did */
59} 58}
60#endif /* #ifdef HAVE_HOTSWAP */
61 59
62DIR_UNCACHED* opendir_uncached(const char* name) 60DIR_UNCACHED* opendir_uncached(const char* name)
63{ 61{
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 @@
23#include "storage.h" 23#include "storage.h"
24#include "debug.h" 24#include "debug.h"
25#include "fat.h" 25#include "fat.h"
26#ifdef HAVE_HOTSWAP
27#include "dir.h" /* for release_dirs() */ 26#include "dir.h" /* for release_dirs() */
28#include "file.h" /* for release_files() */ 27#include "file.h" /* for release_files() */
29#endif
30#include "disk.h" 28#include "disk.h"
31#include <string.h> 29#include <string.h>
32 30
@@ -235,12 +233,13 @@ int disk_mount(int drive)
235 return mounted; 233 return mounted;
236} 234}
237 235
238#ifdef HAVE_HOTSWAP
239int disk_unmount(int drive) 236int disk_unmount(int drive)
240{ 237{
241 int unmounted = 0; 238 int unmounted = 0;
242 int i; 239 int i;
240#ifdef HAVE_HOTSWAP
243 mutex_lock(&disk_mutex); 241 mutex_lock(&disk_mutex);
242#endif
244 for (i=0; i<NUM_VOLUMES; i++) 243 for (i=0; i<NUM_VOLUMES; i++)
245 { 244 {
246 if (vol_drive[i] == drive) 245 if (vol_drive[i] == drive)
@@ -252,8 +251,28 @@ int disk_unmount(int drive)
252 fat_unmount(i, false); 251 fat_unmount(i, false);
253 } 252 }
254 } 253 }
254#ifdef HAVE_HOTSWAP
255 mutex_unlock(&disk_mutex); 255 mutex_unlock(&disk_mutex);
256#endif
257
258 return unmounted;
259}
260
261int disk_unmount_all(void)
262{
263#ifndef HAVE_MULTIDRIVE
264 return disk_unmount(0);
265#else /* HAVE_MULTIDRIVE */
266 int unmounted = 0;
267 int i;
268 for (i = 0; i < NUM_DRIVES; i++)
269 {
270#ifdef HAVE_HOTSWAP
271 if (storage_present(i))
272#endif
273 unmounted += disk_unmount(i);
274 }
256 275
257 return unmounted; 276 return unmounted;
277#endif /* HAVE_MULTIDRIVE */
258} 278}
259#endif /* #ifdef HAVE_HOTSWAP */
diff --git a/firmware/common/file.c b/firmware/common/file.c
index da85846a34..3477c10061 100644
--- a/firmware/common/file.c
+++ b/firmware/common/file.c
@@ -793,7 +793,6 @@ off_t filesize(int fd)
793} 793}
794 794
795 795
796#ifdef HAVE_HOTSWAP
797/* release all file handles on a given volume "by force", to avoid leaks */ 796/* release all file handles on a given volume "by force", to avoid leaks */
798int release_files(int volume) 797int release_files(int volume)
799{ 798{
@@ -814,4 +813,3 @@ int release_files(int volume)
814 } 813 }
815 return closed; /* return how many we did */ 814 return closed; /* return how many we did */
816} 815}
817#endif /* #ifdef HAVE_HOTSWAP */
diff --git a/firmware/drivers/fat.c b/firmware/drivers/fat.c
index cff11d20cc..a99341d58f 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)
479 return 0; 479 return 0;
480} 480}
481 481
482#ifdef HAVE_HOTSWAP
483int fat_unmount(int volume, bool flush) 482int fat_unmount(int volume, bool flush)
484{ 483{
485 int rc; 484 int rc;
@@ -518,7 +517,6 @@ int fat_unmount(int volume, bool flush)
518#endif 517#endif
519 return rc; 518 return rc;
520} 519}
521#endif /* #ifdef HAVE_HOTSWAP */
522 520
523void fat_recalc_free(IF_MV_NONVOID(int volume)) 521void fat_recalc_free(IF_MV_NONVOID(int volume))
524{ 522{
diff --git a/firmware/export/disk.h b/firmware/export/disk.h
index db722a8eda..347d8b44db 100644
--- a/firmware/export/disk.h
+++ b/firmware/export/disk.h
@@ -41,6 +41,7 @@ struct partinfo* disk_partinfo(int partition);
41void disk_init_subsystem(void); /* Initialises mutexes */ 41void disk_init_subsystem(void); /* Initialises mutexes */
42int disk_mount_all(void); /* returns the # of successful mounts */ 42int disk_mount_all(void); /* returns the # of successful mounts */
43int disk_mount(int drive); 43int disk_mount(int drive);
44int disk_unmount_all(void);
44int disk_unmount(int drive); 45int disk_unmount(int drive);
45 46
46/* The number of 512-byte sectors in a "logical" sector. Needed for ipod 5.5G */ 47/* 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 9eaf2014fa..6309c1481c 100644
--- a/firmware/usb.c
+++ b/firmware/usb.c
@@ -131,6 +131,7 @@ static inline void usb_slave_mode(bool on)
131#ifdef HAVE_PRIORITY_SCHEDULING 131#ifdef HAVE_PRIORITY_SCHEDULING
132 thread_set_priority(THREAD_ID_CURRENT, PRIORITY_REALTIME); 132 thread_set_priority(THREAD_ID_CURRENT, PRIORITY_REALTIME);
133#endif 133#endif
134 disk_unmount_all();
134 usb_attach(); 135 usb_attach();
135 } 136 }
136 else /* usb_state == USB_INSERTED (only!) */ 137 else /* usb_state == USB_INSERTED (only!) */
@@ -172,6 +173,7 @@ static inline void usb_slave_mode(bool on)
172 if(on) 173 if(on)
173 { 174 {
174 DEBUGF("Entering USB slave mode\n"); 175 DEBUGF("Entering USB slave mode\n");
176 disk_unmount_all();
175 storage_soft_reset(); 177 storage_soft_reset();
176 storage_init(); 178 storage_init();
177 storage_enable(false); 179 storage_enable(false);