freemyipod r962 - Code Review

Jump to: navigation, search
Repository:freemyipod
Revision:r961‎ | r962 | r963 >
Date:21:14, 19 July 2014
Author:theseven
Status:new
Tags:
Comment:
emCORE: Improve disk error reporting during startup
Modified paths:
  • /emcore/trunk/disk.c (modified) (history)
  • /emcore/trunk/disk.h (modified) (history)
  • /emcore/trunk/fat.c (modified) (history)

Diff [purge]

Index: emcore/trunk/disk.c
@@ -63,7 +63,7 @@
6464 static int vol_drive[NUM_VOLUMES]; /* mounted to which drive (-1 if none) */
6565 static struct mutex disk_mutex;
6666
67 -struct partinfo* disk_init(IF_MD_NONVOID(int drive))
 67+int disk_init(IF_MD2(int drive,) struct partinfo** partinfo)
6868 {
6969 int i;
7070 #ifdef HAVE_MULTIDRIVE
@@ -78,15 +78,21 @@
7979 const int drive = 0;
8080 (void)drive;
8181 #endif
 82+ *partinfo = pinfo;
8283
8384 unsigned char* sector = fat_get_sector_buffer();
84 - storage_read_sectors(IF_MD2(drive,) 0,1, sector);
 85+ int rc = storage_read_sectors(IF_MD2(drive,) 0, 1, sector);
 86+ if (IS_ERR(rc))
 87+ {
 88+ fat_release_sector_buffer();
 89+ PASS_RC(rc, 1, 0);
 90+ }
8591 /* check that the boot sector is initialized */
8692 if ( (sector[510] != 0x55) ||
8793 (sector[511] != 0xaa)) {
8894 fat_release_sector_buffer();
8995 DEBUGF("Bad boot sector signature");
90 - return NULL;
 96+ RET_ERR(1);
9197 }
9298
9399 /* parse partitions */
@@ -105,7 +111,7 @@
106112 }
107113 }
108114 fat_release_sector_buffer();
109 - return pinfo;
 115+ return 0;
110116 }
111117
112118 struct partinfo* disk_partinfo(int partition)
@@ -122,6 +128,7 @@
123129 {
124130 int mounted=0;
125131 int i;
 132+ int rc;
126133
127134 #ifdef HAVE_HOTSWAP
128135 mutex_lock(&disk_mutex, TIMEOUT_BLOCK);
@@ -132,7 +139,7 @@
133140 vol_drive[i] = -1; /* mark all as unassigned */
134141
135142 #ifndef HAVE_MULTIDRIVE
136 - mounted = disk_mount(0);
 143+ PASS_RC(disk_mount(0), 0, 0);
137144 #else
138145 for(i=0;i<NUM_DRIVES;i++)
139146 {
@@ -139,7 +146,10 @@
140147 #ifdef HAVE_HOTSWAP
141148 if (storage_present(i))
142149 #endif
143 - mounted += disk_mount(i);
 150+ {
 151+ rc = disk_mount(i);
 152+ if (!IS_ERR(rc)) mounted += rc;
 153+ }
144154 }
145155 #endif
146156
@@ -146,6 +156,7 @@
147157 #ifdef HAVE_HOTSWAP
148158 mutex_unlock(&disk_mutex);
149159 #endif
 160+ if (!mounted) PASS_RC(rc, 0, 0);
150161 return mounted;
151162 }
152163
@@ -164,6 +175,7 @@
165176 int disk_mount(int drive)
166177 {
167178 int i;
 179+ int rc;
168180 int mounted = 0; /* reset partition-on-drive flag */
169181 int volume;
170182 struct partinfo* pinfo;
@@ -173,7 +185,7 @@
174186 #endif
175187
176188 volume = get_free_volume();
177 - pinfo = disk_init(IF_MD(drive));
 189+ PASS_RC_MTX(disk_init(IF_MD2(drive,) &pinfo), 2, 0, &disk_mutex);
178190
179191 if (pinfo == NULL)
180192 {
@@ -180,7 +192,7 @@
181193 #ifdef HAVE_HOTSWAP
182194 mutex_unlock(&disk_mutex);
183195 #endif
184 - return 0;
 196+ RET_ERR(1);
185197 }
186198 for (i = 0; volume != -1 && i<4 && mounted<NUM_VOLUMES_PER_DRIVE; i++)
187199 {
@@ -187,8 +199,9 @@
188200 if (memchr(fat_partition_types, pinfo[i].type,
189201 sizeof(fat_partition_types)) == NULL)
190202 continue; /* not an accepted partition type */
191 -
192 - if (!fat_mount(IF_MV2(volume,) IF_MD2(drive,) pinfo[i].start))
 203+
 204+ rc = fat_mount(IF_MV2(volume,) IF_MD2(drive,) pinfo[i].start);
 205+ if (!IS_ERR(rc))
193206 {
194207 mounted++;
195208 vol_drive[volume] = drive; /* remember the drive for this volume */
@@ -199,7 +212,8 @@
200213 if (mounted == 0 && volume != -1) /* none of the 4 entries worked? */
201214 { /* try "superfloppy" mode */
202215 DEBUGF("No partition found, trying to mount sector 0.");
203 - if (!fat_mount(IF_MV2(volume,) IF_MD2(drive,) 0))
 216+ rc = fat_mount(IF_MV2(volume,) IF_MD2(drive,) 0);
 217+ if (!IS_ERR(rc))
204218 {
205219 mounted = 1;
206220 vol_drive[volume] = drive; /* remember the drive for this volume */
@@ -208,6 +222,7 @@
209223 #ifdef HAVE_HOTSWAP
210224 mutex_unlock(&disk_mutex);
211225 #endif
 226+ if (!mounted) PASS_RC(rc, 2, 2);
212227 return mounted;
213228 }
214229
Index: emcore/trunk/disk.h
@@ -36,7 +36,7 @@
3737 #define PARTITION_TYPE_OS2_HIDDEN_C_DRIVE 0x84
3838
3939 /* returns a pointer to an array of 8 partinfo structs */
40 -struct partinfo* disk_init(IF_MD_NONVOID(int drive));
 40+int disk_init(IF_MD2(int drive,) struct partinfo** partinfo);
4141 struct partinfo* disk_partinfo(int partition);
4242
4343 void disk_init_subsystem(void); /* Initialises mutexes */
Index: emcore/trunk/fat.c
@@ -315,11 +315,11 @@
316316 /* Read the sector */
317317 unsigned char* buf = fat_get_sector_buffer();
318318 rc = storage_read_sectors(IF_MD2(drive,) startsector,1,buf);
319 - if(rc)
 319+ if (IS_ERR(rc))
320320 {
321321 fat_release_sector_buffer();
322 - DEBUGF( "fat_mount() - Couldn't read BPB (error code %d)", rc);
323 - return rc * 10 - 1;
 322+ DEBUGF("fat_mount() - Couldn't read BPB (error code %d)", rc);
 323+ PASS_RC(rc, 3, 0);
324324 }
325325
326326 memset(fat_bpb, 0, sizeof(struct bpb));
@@ -358,7 +358,7 @@
359359 if (!fat_bpb->bpb_bytspersec)
360360 {
361361 fat_release_sector_buffer();
362 - return -2;
 362+ RET_ERR(1);
363363 }
364364 rootdirsectors = secmult * ((fat_bpb->bpb_rootentcnt * DIR_ENTRY_SIZE
365365 + fat_bpb->bpb_bytspersec - 1) / fat_bpb->bpb_bytspersec);
@@ -377,7 +377,7 @@
378378 else
379379 {
380380 fat_release_sector_buffer();
381 - return -2;
 381+ RET_ERR(2);
382382 }
383383
384384 #ifdef TEST_FAT
@@ -396,12 +396,12 @@
397397 { /* FAT12 */
398398 fat_release_sector_buffer();
399399 DEBUGF("This is FAT12. Go away!");
400 - return -2;
 400+ RET_ERR(3);
401401 }
402402 #else /* #ifdef HAVE_FAT16SUPPORT */
403403 fat_release_sector_buffer();
404404 DEBUGF("This is not FAT32. Go away!");
405 - return -2;
 405+ RET_ERR(3);
406406 #endif /* #ifndef HAVE_FAT16SUPPORT */
407407 }
408408
@@ -433,7 +433,7 @@
434434 {
435435 fat_release_sector_buffer();
436436 DEBUGF( "fat_mount() - BPB is not sane");
437 - return rc * 10 - 3;
 437+ RET_ERR(4);
438438 }
439439
440440 #ifdef HAVE_FAT16SUPPORT
@@ -448,11 +448,11 @@
449449 /* Read the fsinfo sector */
450450 rc = storage_read_sectors(IF_MD2(drive,)
451451 startsector + fat_bpb->bpb_fsinfo, 1, buf);
452 - if (rc < 0)
 452+ if (IS_ERR(rc))
453453 {
454454 fat_release_sector_buffer();
455455 DEBUGF( "fat_mount() - Couldn't read FSInfo (error code %d)", rc);
456 - return rc * 10 - 4;
 456+ PASS_RC(rc, 3, 5);
457457 }
458458 fat_bpb->fsinfo.freecount = BYTES2INT32(buf, FSINFO_FREECOUNT);
459459 fat_bpb->fsinfo.nextfree = BYTES2INT32(buf, FSINFO_NEXTFREE);