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, 20 insertions, 14 deletions
diff --git a/firmware/common/disk.c b/firmware/common/disk.c
index cc0f0d657d..abeadb5c23 100644
--- a/firmware/common/disk.c
+++ b/firmware/common/disk.c
@@ -44,8 +44,8 @@
44 12-15: nr of sectors in partition 44 12-15: nr of sectors in partition
45*/ 45*/
46 46
47#define BYTES2INT32(array,pos) \ 47#define BYTES2INT32(array,pos) \
48 ((long)array[pos] | ((long)array[pos+1] << 8 ) | \ 48 ((long)array[pos] | ((long)array[pos+1] << 8 ) | \
49 ((long)array[pos+2] << 16 ) | ((long)array[pos+3] << 24 )) 49 ((long)array[pos+2] << 16 ) | ((long)array[pos+3] << 24 ))
50 50
51static const unsigned char fat_partition_types[] = { 51static const unsigned char fat_partition_types[] = {
@@ -58,18 +58,18 @@ static const unsigned char fat_partition_types[] = {
58#endif 58#endif
59}; 59};
60 60
61static struct partinfo part[8]; /* 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) */
63 63
64#ifdef MAX_LOG_SECTOR_SIZE 64#ifdef MAX_LOG_SECTOR_SIZE
65int disk_sector_multiplier = 1; 65int disk_sector_multiplier = 1;
66#endif 66#endif
67 67
68struct partinfo* disk_init(IF_MV_NONVOID(int drive)) 68struct partinfo* disk_init(IF_MD_NONVOID(int drive))
69{ 69{
70 int i; 70 int i;
71 unsigned char sector[512]; 71 unsigned char sector[512];
72#ifdef HAVE_MULTIVOLUME 72#ifdef HAVE_MULTIDRIVE
73 /* For each drive, start at a different position, in order not to destroy 73 /* For each drive, start at a different position, in order not to destroy
74 the first entry of drive 0. 74 the first entry of drive 0.
75 That one is needed to calculate config sector position. */ 75 That one is needed to calculate config sector position. */
@@ -115,7 +115,7 @@ struct partinfo* disk_partinfo(int partition)
115 115
116int disk_mount_all(void) 116int disk_mount_all(void)
117{ 117{
118 int mounted; 118 int mounted=0;
119 int i; 119 int i;
120 120
121#ifdef HAVE_HOTSWAP 121#ifdef HAVE_HOTSWAP
@@ -126,13 +126,19 @@ int disk_mount_all(void)
126 for (i=0; i<NUM_VOLUMES; i++) 126 for (i=0; i<NUM_VOLUMES; i++)
127 vol_drive[i] = -1; /* mark all as unassigned */ 127 vol_drive[i] = -1; /* mark all as unassigned */
128 128
129#ifndef HAVE_MULTIDRIVE
129 mounted = disk_mount(0); 130 mounted = disk_mount(0);
130#ifdef HAVE_HOTSWAP 131#else
131 if (card_detect()) 132 for(i=0;i<NUM_DRIVES;i++)
132 { 133 {
133 mounted += disk_mount(1); /* try 2nd "drive", too */ 134#ifdef HAVE_HOTSWAP
135 if (storage_present(i))
136#endif
137 mounted += disk_mount(i);
134 } 138 }
139#endif
135 140
141#ifdef HAVE_HOTSWAP
136 card_enable_monitoring(true); 142 card_enable_monitoring(true);
137#endif 143#endif
138 144
@@ -155,7 +161,7 @@ int disk_mount(int drive)
155{ 161{
156 int mounted = 0; /* reset partition-on-drive flag */ 162 int mounted = 0; /* reset partition-on-drive flag */
157 int volume = get_free_volume(); 163 int volume = get_free_volume();
158 struct partinfo* pinfo = disk_init(IF_MV(drive)); 164 struct partinfo* pinfo = disk_init(IF_MD(drive));
159 165
160 if (pinfo == NULL) 166 if (pinfo == NULL)
161 { 167 {
@@ -166,7 +172,7 @@ int disk_mount(int drive)
166#else 172#else
167 int i = 0; 173 int i = 0;
168#endif 174#endif
169 for (; volume != -1 && i<4; i++) 175 for (; volume != -1 && i<4 && mounted<NUM_VOLUMES_PER_DRIVE; i++)
170 { 176 {
171 if (memchr(fat_partition_types, pinfo[i].type, 177 if (memchr(fat_partition_types, pinfo[i].type,
172 sizeof(fat_partition_types)) == NULL) 178 sizeof(fat_partition_types)) == NULL)
@@ -177,7 +183,7 @@ int disk_mount(int drive)
177 183
178 for (j = 1; j <= (MAX_LOG_SECTOR_SIZE/SECTOR_SIZE); j <<= 1) 184 for (j = 1; j <= (MAX_LOG_SECTOR_SIZE/SECTOR_SIZE); j <<= 1)
179 { 185 {
180 if (!fat_mount(IF_MV2(volume,) IF_MV2(drive,) pinfo[i].start * j)) 186 if (!fat_mount(IF_MV2(volume,) IF_MD2(drive,) pinfo[i].start * j))
181 { 187 {
182 pinfo[i].start *= j; 188 pinfo[i].start *= j;
183 pinfo[i].size *= j; 189 pinfo[i].size *= j;
@@ -190,7 +196,7 @@ int disk_mount(int drive)
190 } 196 }
191 } 197 }
192#else 198#else
193 if (!fat_mount(IF_MV2(volume,) IF_MV2(drive,) pinfo[i].start)) 199 if (!fat_mount(IF_MV2(volume,) IF_MD2(drive,) pinfo[i].start))
194 { 200 {
195 mounted++; 201 mounted++;
196 vol_drive[volume] = drive; /* remember the drive for this volume */ 202 vol_drive[volume] = drive; /* remember the drive for this volume */
@@ -202,7 +208,7 @@ int disk_mount(int drive)
202 if (mounted == 0 && volume != -1) /* none of the 4 entries worked? */ 208 if (mounted == 0 && volume != -1) /* none of the 4 entries worked? */
203 { /* try "superfloppy" mode */ 209 { /* try "superfloppy" mode */
204 DEBUGF("No partition found, trying to mount sector 0.\n"); 210 DEBUGF("No partition found, trying to mount sector 0.\n");
205 if (!fat_mount(IF_MV2(volume,) IF_MV2(drive,) 0)) 211 if (!fat_mount(IF_MV2(volume,) IF_MD2(drive,) 0))
206 { 212 {
207 mounted = 1; 213 mounted = 1;
208 vol_drive[volume] = drive; /* remember the drive for this volume */ 214 vol_drive[volume] = drive; /* remember the drive for this volume */