| Index: emcore/trunk/disk.c |
| — | — | @@ -63,7 +63,7 @@ |
| 64 | 64 | static int vol_drive[NUM_VOLUMES]; /* mounted to which drive (-1 if none) */ |
| 65 | 65 | static struct mutex disk_mutex; |
| 66 | 66 | |
| 67 | | -struct partinfo* disk_init(IF_MD_NONVOID(int drive)) |
| | 67 | +int disk_init(IF_MD2(int drive,) struct partinfo** partinfo) |
| 68 | 68 | { |
| 69 | 69 | int i; |
| 70 | 70 | #ifdef HAVE_MULTIDRIVE |
| — | — | @@ -78,15 +78,21 @@ |
| 79 | 79 | const int drive = 0; |
| 80 | 80 | (void)drive; |
| 81 | 81 | #endif |
| | 82 | + *partinfo = pinfo; |
| 82 | 83 | |
| 83 | 84 | 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 | + } |
| 85 | 91 | /* check that the boot sector is initialized */ |
| 86 | 92 | if ( (sector[510] != 0x55) || |
| 87 | 93 | (sector[511] != 0xaa)) { |
| 88 | 94 | fat_release_sector_buffer(); |
| 89 | 95 | DEBUGF("Bad boot sector signature"); |
| 90 | | - return NULL; |
| | 96 | + RET_ERR(1); |
| 91 | 97 | } |
| 92 | 98 | |
| 93 | 99 | /* parse partitions */ |
| — | — | @@ -105,7 +111,7 @@ |
| 106 | 112 | } |
| 107 | 113 | } |
| 108 | 114 | fat_release_sector_buffer(); |
| 109 | | - return pinfo; |
| | 115 | + return 0; |
| 110 | 116 | } |
| 111 | 117 | |
| 112 | 118 | struct partinfo* disk_partinfo(int partition) |
| — | — | @@ -122,6 +128,7 @@ |
| 123 | 129 | { |
| 124 | 130 | int mounted=0; |
| 125 | 131 | int i; |
| | 132 | + int rc; |
| 126 | 133 | |
| 127 | 134 | #ifdef HAVE_HOTSWAP |
| 128 | 135 | mutex_lock(&disk_mutex, TIMEOUT_BLOCK); |
| — | — | @@ -132,7 +139,7 @@ |
| 133 | 140 | vol_drive[i] = -1; /* mark all as unassigned */ |
| 134 | 141 | |
| 135 | 142 | #ifndef HAVE_MULTIDRIVE |
| 136 | | - mounted = disk_mount(0); |
| | 143 | + PASS_RC(disk_mount(0), 0, 0); |
| 137 | 144 | #else |
| 138 | 145 | for(i=0;i<NUM_DRIVES;i++) |
| 139 | 146 | { |
| — | — | @@ -139,7 +146,10 @@ |
| 140 | 147 | #ifdef HAVE_HOTSWAP |
| 141 | 148 | if (storage_present(i)) |
| 142 | 149 | #endif |
| 143 | | - mounted += disk_mount(i); |
| | 150 | + { |
| | 151 | + rc = disk_mount(i); |
| | 152 | + if (!IS_ERR(rc)) mounted += rc; |
| | 153 | + } |
| 144 | 154 | } |
| 145 | 155 | #endif |
| 146 | 156 | |
| — | — | @@ -146,6 +156,7 @@ |
| 147 | 157 | #ifdef HAVE_HOTSWAP |
| 148 | 158 | mutex_unlock(&disk_mutex); |
| 149 | 159 | #endif |
| | 160 | + if (!mounted) PASS_RC(rc, 0, 0); |
| 150 | 161 | return mounted; |
| 151 | 162 | } |
| 152 | 163 | |
| — | — | @@ -164,6 +175,7 @@ |
| 165 | 176 | int disk_mount(int drive) |
| 166 | 177 | { |
| 167 | 178 | int i; |
| | 179 | + int rc; |
| 168 | 180 | int mounted = 0; /* reset partition-on-drive flag */ |
| 169 | 181 | int volume; |
| 170 | 182 | struct partinfo* pinfo; |
| — | — | @@ -173,7 +185,7 @@ |
| 174 | 186 | #endif |
| 175 | 187 | |
| 176 | 188 | 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); |
| 178 | 190 | |
| 179 | 191 | if (pinfo == NULL) |
| 180 | 192 | { |
| — | — | @@ -180,7 +192,7 @@ |
| 181 | 193 | #ifdef HAVE_HOTSWAP |
| 182 | 194 | mutex_unlock(&disk_mutex); |
| 183 | 195 | #endif |
| 184 | | - return 0; |
| | 196 | + RET_ERR(1); |
| 185 | 197 | } |
| 186 | 198 | for (i = 0; volume != -1 && i<4 && mounted<NUM_VOLUMES_PER_DRIVE; i++) |
| 187 | 199 | { |
| — | — | @@ -187,8 +199,9 @@ |
| 188 | 200 | if (memchr(fat_partition_types, pinfo[i].type, |
| 189 | 201 | sizeof(fat_partition_types)) == NULL) |
| 190 | 202 | 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)) |
| 193 | 206 | { |
| 194 | 207 | mounted++; |
| 195 | 208 | vol_drive[volume] = drive; /* remember the drive for this volume */ |
| — | — | @@ -199,7 +212,8 @@ |
| 200 | 213 | if (mounted == 0 && volume != -1) /* none of the 4 entries worked? */ |
| 201 | 214 | { /* try "superfloppy" mode */ |
| 202 | 215 | 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)) |
| 204 | 218 | { |
| 205 | 219 | mounted = 1; |
| 206 | 220 | vol_drive[volume] = drive; /* remember the drive for this volume */ |
| — | — | @@ -208,6 +222,7 @@ |
| 209 | 223 | #ifdef HAVE_HOTSWAP |
| 210 | 224 | mutex_unlock(&disk_mutex); |
| 211 | 225 | #endif |
| | 226 | + if (!mounted) PASS_RC(rc, 2, 2); |
| 212 | 227 | return mounted; |
| 213 | 228 | } |
| 214 | 229 | |
| Index: emcore/trunk/disk.h |
| — | — | @@ -36,7 +36,7 @@ |
| 37 | 37 | #define PARTITION_TYPE_OS2_HIDDEN_C_DRIVE 0x84 |
| 38 | 38 | |
| 39 | 39 | /* 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); |
| 41 | 41 | struct partinfo* disk_partinfo(int partition); |
| 42 | 42 | |
| 43 | 43 | void disk_init_subsystem(void); /* Initialises mutexes */ |
| Index: emcore/trunk/fat.c |
| — | — | @@ -315,11 +315,11 @@ |
| 316 | 316 | /* Read the sector */
|
| 317 | 317 | unsigned char* buf = fat_get_sector_buffer();
|
| 318 | 318 | rc = storage_read_sectors(IF_MD2(drive,) startsector,1,buf);
|
| 319 | | - if(rc)
|
| | 319 | + if (IS_ERR(rc))
|
| 320 | 320 | {
|
| 321 | 321 | 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);
|
| 324 | 324 | }
|
| 325 | 325 |
|
| 326 | 326 | memset(fat_bpb, 0, sizeof(struct bpb));
|
| — | — | @@ -358,7 +358,7 @@ |
| 359 | 359 | if (!fat_bpb->bpb_bytspersec)
|
| 360 | 360 | {
|
| 361 | 361 | fat_release_sector_buffer();
|
| 362 | | - return -2;
|
| | 362 | + RET_ERR(1);
|
| 363 | 363 | }
|
| 364 | 364 | rootdirsectors = secmult * ((fat_bpb->bpb_rootentcnt * DIR_ENTRY_SIZE
|
| 365 | 365 | + fat_bpb->bpb_bytspersec - 1) / fat_bpb->bpb_bytspersec);
|
| — | — | @@ -377,7 +377,7 @@ |
| 378 | 378 | else
|
| 379 | 379 | {
|
| 380 | 380 | fat_release_sector_buffer();
|
| 381 | | - return -2;
|
| | 381 | + RET_ERR(2);
|
| 382 | 382 | }
|
| 383 | 383 |
|
| 384 | 384 | #ifdef TEST_FAT
|
| — | — | @@ -396,12 +396,12 @@ |
| 397 | 397 | { /* FAT12 */
|
| 398 | 398 | fat_release_sector_buffer();
|
| 399 | 399 | DEBUGF("This is FAT12. Go away!");
|
| 400 | | - return -2;
|
| | 400 | + RET_ERR(3);
|
| 401 | 401 | }
|
| 402 | 402 | #else /* #ifdef HAVE_FAT16SUPPORT */
|
| 403 | 403 | fat_release_sector_buffer();
|
| 404 | 404 | DEBUGF("This is not FAT32. Go away!");
|
| 405 | | - return -2;
|
| | 405 | + RET_ERR(3);
|
| 406 | 406 | #endif /* #ifndef HAVE_FAT16SUPPORT */
|
| 407 | 407 | }
|
| 408 | 408 |
|
| — | — | @@ -433,7 +433,7 @@ |
| 434 | 434 | {
|
| 435 | 435 | fat_release_sector_buffer();
|
| 436 | 436 | DEBUGF( "fat_mount() - BPB is not sane");
|
| 437 | | - return rc * 10 - 3;
|
| | 437 | + RET_ERR(4);
|
| 438 | 438 | }
|
| 439 | 439 |
|
| 440 | 440 | #ifdef HAVE_FAT16SUPPORT
|
| — | — | @@ -448,11 +448,11 @@ |
| 449 | 449 | /* Read the fsinfo sector */
|
| 450 | 450 | rc = storage_read_sectors(IF_MD2(drive,)
|
| 451 | 451 | startsector + fat_bpb->bpb_fsinfo, 1, buf);
|
| 452 | | - if (rc < 0)
|
| | 452 | + if (IS_ERR(rc))
|
| 453 | 453 | {
|
| 454 | 454 | fat_release_sector_buffer();
|
| 455 | 455 | DEBUGF( "fat_mount() - Couldn't read FSInfo (error code %d)", rc);
|
| 456 | | - return rc * 10 - 4;
|
| | 456 | + PASS_RC(rc, 3, 5);
|
| 457 | 457 | }
|
| 458 | 458 | fat_bpb->fsinfo.freecount = BYTES2INT32(buf, FSINFO_FREECOUNT);
|
| 459 | 459 | fat_bpb->fsinfo.nextfree = BYTES2INT32(buf, FSINFO_NEXTFREE);
|