--- trunk/src/diskimage.c 2007/10/08 16:20:58 32 +++ trunk/src/diskimage.c 2007/10/08 16:21:17 34 @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2006 Anders Gavare. All rights reserved. + * Copyright (C) 2003-2007 Anders Gavare. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -25,7 +25,7 @@ * SUCH DAMAGE. * * - * $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 $ * * Disk image support. * @@ -283,6 +283,25 @@ /* + * diskimage_get_baseoffset(): + * + * Returns -1 if the specified disk id/type does not exists, otherwise + * the base offset of the disk image is returned. + */ +int64_t diskimage_get_baseoffset(struct machine *machine, int id, int type) +{ + struct diskimage *d = machine->first_diskimage; + + while (d != NULL) { + if (d->type == type && d->id == id) + return d->override_base_offset; + d = d->next; + } + return -1; +} + + +/* * diskimage_getchs(): * * Returns the current CHS values of a disk image. @@ -1401,6 +1420,14 @@ return 0; } + offset -= d->override_base_offset; + if (offset < 0 && offset + d->override_base_offset >= 0) { + debug("[ reading before start of disk image ]\n"); + /* Returning zeros. */ + memset(buf, 0, len); + return 1; + } + return diskimage__internal_access(d, writeflag, offset, buf, len); } @@ -1419,6 +1446,7 @@ * gH;S; set geometry (H=heads, S=sectors per track, cylinders are * automatically calculated). (This is ignored for floppies.) * i IDE (instead of SCSI) + * oOFS; set base offset in bytes, when booting from an ISO9660 fs * r read-only (don't allow changes to the file) * s SCSI (this is the default) * t tape @@ -1431,10 +1459,11 @@ { struct diskimage *d, *d2; int id = 0, override_heads=0, override_spt=0; - int64_t bytespercyl; + int64_t bytespercyl, override_base_offset=0; char *cp; int prefix_b=0, prefix_c=0, prefix_d=0, prefix_f=0, prefix_g=0; - 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; + int prefix_o=0; if (fname == NULL) { fprintf(stderr, "diskimage_add(): NULL ptr\n"); @@ -1493,6 +1522,20 @@ case 'i': prefix_i = 1; break; + case 'o': + prefix_o = 1; + override_base_offset = atoi(fname); + while (*fname != '\0' && *fname != ':' + && *fname != ';') + fname ++; + if (*fname == ':' || *fname == ';') + fname ++; + if (override_base_offset < 0) { + fatal("Bad base offset: %"PRIi64 + "\n", override_base_offset); + exit(1); + } + break; case 'r': prefix_r = 1; break; @@ -1550,6 +1593,9 @@ if (prefix_s) d->type = DISKIMAGE_SCSI; + if (prefix_o) + d->override_base_offset = override_base_offset; + d->fname = strdup(fname); if (d->fname == NULL) { fprintf(stderr, "out of memory\n");