1 |
/* |
/* |
2 |
* Copyright (C) 2003-2006 Anders Gavare. All rights reserved. |
* Copyright (C) 2003-2007 Anders Gavare. All rights reserved. |
3 |
* |
* |
4 |
* Redistribution and use in source and binary forms, with or without |
* Redistribution and use in source and binary forms, with or without |
5 |
* modification, are permitted provided that the following conditions are met: |
* modification, are permitted provided that the following conditions are met: |
25 |
* SUCH DAMAGE. |
* SUCH DAMAGE. |
26 |
* |
* |
27 |
* |
* |
28 |
* $Id: diskimage.c,v 1.114 2006/09/07 11:44:01 debug Exp $ |
* $Id: diskimage.c,v 1.116 2006/12/30 13:30:51 debug Exp $ |
29 |
* |
* |
30 |
* Disk image support. |
* Disk image support. |
31 |
* |
* |
283 |
|
|
284 |
|
|
285 |
/* |
/* |
286 |
|
* diskimage_get_baseoffset(): |
287 |
|
* |
288 |
|
* Returns -1 if the specified disk id/type does not exists, otherwise |
289 |
|
* the base offset of the disk image is returned. |
290 |
|
*/ |
291 |
|
int64_t diskimage_get_baseoffset(struct machine *machine, int id, int type) |
292 |
|
{ |
293 |
|
struct diskimage *d = machine->first_diskimage; |
294 |
|
|
295 |
|
while (d != NULL) { |
296 |
|
if (d->type == type && d->id == id) |
297 |
|
return d->override_base_offset; |
298 |
|
d = d->next; |
299 |
|
} |
300 |
|
return -1; |
301 |
|
} |
302 |
|
|
303 |
|
|
304 |
|
/* |
305 |
* diskimage_getchs(): |
* diskimage_getchs(): |
306 |
* |
* |
307 |
* Returns the current CHS values of a disk image. |
* Returns the current CHS values of a disk image. |
1420 |
return 0; |
return 0; |
1421 |
} |
} |
1422 |
|
|
1423 |
|
offset -= d->override_base_offset; |
1424 |
|
if (offset < 0 && offset + d->override_base_offset >= 0) { |
1425 |
|
debug("[ reading before start of disk image ]\n"); |
1426 |
|
/* Returning zeros. */ |
1427 |
|
memset(buf, 0, len); |
1428 |
|
return 1; |
1429 |
|
} |
1430 |
|
|
1431 |
return diskimage__internal_access(d, writeflag, offset, buf, len); |
return diskimage__internal_access(d, writeflag, offset, buf, len); |
1432 |
} |
} |
1433 |
|
|
1446 |
* gH;S; set geometry (H=heads, S=sectors per track, cylinders are |
* gH;S; set geometry (H=heads, S=sectors per track, cylinders are |
1447 |
* automatically calculated). (This is ignored for floppies.) |
* automatically calculated). (This is ignored for floppies.) |
1448 |
* i IDE (instead of SCSI) |
* i IDE (instead of SCSI) |
1449 |
|
* oOFS; set base offset in bytes, when booting from an ISO9660 fs |
1450 |
* r read-only (don't allow changes to the file) |
* r read-only (don't allow changes to the file) |
1451 |
* s SCSI (this is the default) |
* s SCSI (this is the default) |
1452 |
* t tape |
* t tape |
1459 |
{ |
{ |
1460 |
struct diskimage *d, *d2; |
struct diskimage *d, *d2; |
1461 |
int id = 0, override_heads=0, override_spt=0; |
int id = 0, override_heads=0, override_spt=0; |
1462 |
int64_t bytespercyl; |
int64_t bytespercyl, override_base_offset=0; |
1463 |
char *cp; |
char *cp; |
1464 |
int prefix_b=0, prefix_c=0, prefix_d=0, prefix_f=0, prefix_g=0; |
int prefix_b=0, prefix_c=0, prefix_d=0, prefix_f=0, prefix_g=0; |
1465 |
int prefix_i=0, prefix_r=0, prefix_s=0, prefix_t=0, prefix_id = -1; |
int prefix_i=0, prefix_r=0, prefix_s=0, prefix_t=0, prefix_id=-1; |
1466 |
|
int prefix_o=0; |
1467 |
|
|
1468 |
if (fname == NULL) { |
if (fname == NULL) { |
1469 |
fprintf(stderr, "diskimage_add(): NULL ptr\n"); |
fprintf(stderr, "diskimage_add(): NULL ptr\n"); |
1522 |
case 'i': |
case 'i': |
1523 |
prefix_i = 1; |
prefix_i = 1; |
1524 |
break; |
break; |
1525 |
|
case 'o': |
1526 |
|
prefix_o = 1; |
1527 |
|
override_base_offset = atoi(fname); |
1528 |
|
while (*fname != '\0' && *fname != ':' |
1529 |
|
&& *fname != ';') |
1530 |
|
fname ++; |
1531 |
|
if (*fname == ':' || *fname == ';') |
1532 |
|
fname ++; |
1533 |
|
if (override_base_offset < 0) { |
1534 |
|
fatal("Bad base offset: %"PRIi64 |
1535 |
|
"\n", override_base_offset); |
1536 |
|
exit(1); |
1537 |
|
} |
1538 |
|
break; |
1539 |
case 'r': |
case 'r': |
1540 |
prefix_r = 1; |
prefix_r = 1; |
1541 |
break; |
break; |
1593 |
if (prefix_s) |
if (prefix_s) |
1594 |
d->type = DISKIMAGE_SCSI; |
d->type = DISKIMAGE_SCSI; |
1595 |
|
|
1596 |
|
if (prefix_o) |
1597 |
|
d->override_base_offset = override_base_offset; |
1598 |
|
|
1599 |
d->fname = strdup(fname); |
d->fname = strdup(fname); |
1600 |
if (d->fname == NULL) { |
if (d->fname == NULL) { |
1601 |
fprintf(stderr, "out of memory\n"); |
fprintf(stderr, "out of memory\n"); |