* adfMountDev * * mount a dump file (.adf) or a real device (uses adf_nativ.c and .h) * * adfInitDevice() must fill dev->size ! */
| 377 | * adfInitDevice() must fill dev->size ! |
| 378 | */ |
| 379 | struct Device* adfMountDev( char* filename, BOOL ro) |
| 380 | { |
| 381 | struct Device* dev; |
| 382 | struct nativeFunctions *nFct; |
| 383 | RETCODE rc; |
| 384 | uint8_t buf[512]; |
| 385 | |
| 386 | dev = (struct Device*)malloc(sizeof(struct Device)); |
| 387 | if (!dev) { |
| 388 | (*adfEnv.eFct)("adfMountDev : malloc error"); |
| 389 | return NULL; |
| 390 | } |
| 391 | |
| 392 | dev->readOnly = ro; |
| 393 | |
| 394 | /* switch between dump files and real devices */ |
| 395 | nFct = adfEnv.nativeFct; |
| 396 | dev->isNativeDev = (*nFct->adfIsDevNative)(filename); |
| 397 | if (dev->isNativeDev) |
| 398 | rc = (*nFct->adfInitDevice)(dev, filename,ro); |
| 399 | else |
| 400 | rc = adfInitDumpDevice(dev,filename,ro); |
| 401 | if (rc!=RC_OK) { |
| 402 | free(dev); return(NULL); |
| 403 | } |
| 404 | |
| 405 | dev->devType = adfDevType(dev); |
| 406 | |
| 407 | switch( dev->devType ) { |
| 408 | |
| 409 | case DEVTYPE_FLOPDD: |
| 410 | case DEVTYPE_FLOPHD: |
| 411 | if (adfMountFlop(dev)!=RC_OK) { |
| 412 | if (dev->isNativeDev) /* BV */ |
| 413 | (*nFct->adfReleaseDevice)(dev); /* BV */ |
| 414 | else /* BV */ |
| 415 | adfReleaseDumpDevice(dev); /* BV */ |
| 416 | free(dev); return NULL; |
| 417 | } |
| 418 | break; |
| 419 | |
| 420 | case DEVTYPE_HARDDISK: |
| 421 | /* to choose between hardfile or harddisk (real or dump) */ |
| 422 | if (dev->isNativeDev) /* BV ...from here*/ |
| 423 | rc = (*nFct->adfNativeReadSector)(dev, 0, 512, buf); |
| 424 | else |
| 425 | rc = adfReadDumpSector(dev, 0, 512, buf); |
| 426 | if( rc!=RC_OK ) { |
| 427 | nFct = adfEnv.nativeFct; |
| 428 | if (dev->isNativeDev) |
| 429 | (*nFct->adfReleaseDevice)(dev); |
| 430 | else |
| 431 | adfReleaseDumpDevice(dev); |
| 432 | (*adfEnv.eFct)("adfMountDev : adfReadDumpSector failed"); |
| 433 | free(dev); return NULL; |
| 434 | } |
| 435 | |
| 436 | /* a file with the first three bytes equal to 'DOS' */ |
no test coverage detected