summaryrefslogtreecommitdiff
path: root/firmware/common/disk.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/common/disk.c')
-rw-r--r--firmware/common/disk.c34
1 files changed, 27 insertions, 7 deletions
diff --git a/firmware/common/disk.c b/firmware/common/disk.c
index 8d93f3b8cd..bc0ad793d2 100644
--- a/firmware/common/disk.c
+++ b/firmware/common/disk.c
@@ -19,11 +19,11 @@
19 * 19 *
20 ****************************************************************************/ 20 ****************************************************************************/
21#include <stdio.h> 21#include <stdio.h>
22#include "kernel.h"
22#include "storage.h" 23#include "storage.h"
23#include "debug.h" 24#include "debug.h"
24#include "fat.h" 25#include "fat.h"
25#ifdef HAVE_HOTSWAP 26#ifdef HAVE_HOTSWAP
26#include "sdmmc.h" /* for card_enable_monitoring() */
27#include "dir.h" /* for release_dirs() */ 27#include "dir.h" /* for release_dirs() */
28#include "file.h" /* for release_files() */ 28#include "file.h" /* for release_files() */
29#endif 29#endif
@@ -60,12 +60,13 @@ static const unsigned char fat_partition_types[] = {
60 60
61static struct partinfo part[NUM_DRIVES*4]; /* space for 4 partitions on 2 drives */ 61static struct partinfo part[NUM_DRIVES*4]; /* space for 4 partitions on 2 drives */
62static int vol_drive[NUM_VOLUMES]; /* mounted to which drive (-1 if none) */ 62static int vol_drive[NUM_VOLUMES]; /* mounted to which drive (-1 if none) */
63static struct mutex disk_mutex;
63 64
64#ifdef MAX_LOG_SECTOR_SIZE 65#ifdef MAX_LOG_SECTOR_SIZE
65int disk_sector_multiplier = 1; 66int disk_sector_multiplier = 1;
66#endif 67#endif
67 68
68struct partinfo* disk_init(IF_MD_NONVOID(int drive)) 69static struct partinfo* disk_init(IF_MD_NONVOID(int drive))
69{ 70{
70 int i; 71 int i;
71 unsigned char sector[SECTOR_SIZE]; 72 unsigned char sector[SECTOR_SIZE];
@@ -113,13 +114,18 @@ struct partinfo* disk_partinfo(int partition)
113 return &part[partition]; 114 return &part[partition];
114} 115}
115 116
117void disk_init_subsystem(void)
118{
119 mutex_init(&disk_mutex);
120}
121
116int disk_mount_all(void) 122int disk_mount_all(void)
117{ 123{
118 int mounted=0; 124 int mounted=0;
119 int i; 125 int i;
120 126
121#ifdef HAVE_HOTSWAP 127#ifdef HAVE_HOTSWAP
122 card_enable_monitoring(false); 128 mutex_lock(&disk_mutex);
123#endif 129#endif
124 130
125 fat_init(); /* reset all mounted partitions */ 131 fat_init(); /* reset all mounted partitions */
@@ -139,9 +145,8 @@ int disk_mount_all(void)
139#endif 145#endif
140 146
141#ifdef HAVE_HOTSWAP 147#ifdef HAVE_HOTSWAP
142 card_enable_monitoring(true); 148 mutex_unlock(&disk_mutex);
143#endif 149#endif
144
145 return mounted; 150 return mounted;
146} 151}
147 152
@@ -160,11 +165,21 @@ static int get_free_volume(void)
160int disk_mount(int drive) 165int disk_mount(int drive)
161{ 166{
162 int mounted = 0; /* reset partition-on-drive flag */ 167 int mounted = 0; /* reset partition-on-drive flag */
163 int volume = get_free_volume(); 168 int volume;
164 struct partinfo* pinfo = disk_init(IF_MD(drive)); 169 struct partinfo* pinfo;
170
171#ifdef HAVE_HOTSWAP
172 mutex_lock(&disk_mutex);
173#endif
174
175 volume = get_free_volume();
176 pinfo = disk_init(IF_MD(drive));
165 177
166 if (pinfo == NULL) 178 if (pinfo == NULL)
167 { 179 {
180#ifdef HAVE_HOTSWAP
181 mutex_unlock(&disk_mutex);
182#endif
168 return 0; 183 return 0;
169 } 184 }
170#if defined(TOSHIBA_GIGABEAT_S) 185#if defined(TOSHIBA_GIGABEAT_S)
@@ -214,6 +229,9 @@ int disk_mount(int drive)
214 vol_drive[volume] = drive; /* remember the drive for this volume */ 229 vol_drive[volume] = drive; /* remember the drive for this volume */
215 } 230 }
216 } 231 }
232#ifdef HAVE_HOTSWAP
233 mutex_unlock(&disk_mutex);
234#endif
217 return mounted; 235 return mounted;
218} 236}
219 237
@@ -222,6 +240,7 @@ int disk_unmount(int drive)
222{ 240{
223 int unmounted = 0; 241 int unmounted = 0;
224 int i; 242 int i;
243 mutex_lock(&disk_mutex);
225 for (i=0; i<NUM_VOLUMES; i++) 244 for (i=0; i<NUM_VOLUMES; i++)
226 { 245 {
227 if (vol_drive[i] == drive) 246 if (vol_drive[i] == drive)
@@ -233,6 +252,7 @@ int disk_unmount(int drive)
233 fat_unmount(i, false); 252 fat_unmount(i, false);
234 } 253 }
235 } 254 }
255 mutex_unlock(&disk_mutex);
236 256
237 return unmounted; 257 return unmounted;
238} 258}