--- trunk/src/diskimage.c 2007/10/08 16:20:10 26 +++ 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.110 2006/06/24 19:52:27 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. @@ -451,9 +470,11 @@ /* Warn about non-complete data transfers: */ if (lendone != (ssize_t)len) { +#ifdef UNSTABLE_DEVEL fatal("[ diskimage__internal_access(): disk_id %i, offset %lli" ", transfer not completed. len=%i, len_done=%i ]\n", d->id, (long long)offset, (int)len, (int)lendone); +#endif return 0; } @@ -1141,7 +1162,7 @@ /* * Bits 2..0 of buf[1] contain the 'code' which describes how - * we should space, and buf[2..4] contain the number of + * spacing should be done, and buf[2..4] contain the number of * operations. */ debug("[ SPACE: buf[] = %02x %02x %02x %02x %02x %02x ]\n", @@ -1250,6 +1271,34 @@ diskimage__return_default_status_and_message(xferp); break; + case SCSICDROM_READ_DISCINFO: + debug("(SCSICDROM_READ_DISCINFO: "); + debug("TODO"); + retlen = 0; + + /* Return data: */ + scsi_transfer_allocbuf(&xferp->data_in_len, + &xferp->data_in, retlen, 1); + + /* TODO */ + + diskimage__return_default_status_and_message(xferp); + break; + + case SCSICDROM_READ_TRACKINFO: + debug("(SCSICDROM_READ_TRACKINFO: "); + debug("TODO"); + retlen = 0; + + /* Return data: */ + scsi_transfer_allocbuf(&xferp->data_in_len, + &xferp->data_in, retlen, 1); + + /* TODO */ + + diskimage__return_default_status_and_message(xferp); + break; + case SCSICMD_MODE_SELECT: debug("[ SCSI MODE_SELECT: "); @@ -1371,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); } @@ -1389,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 @@ -1401,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"); @@ -1463,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; @@ -1520,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");