X-Git-Url: https://vcs.maemo.org/git/?a=blobdiff_plain;f=hw%2Fscsi-disk.c;h=f545c89c22716a53db204995ce4e57e730ce33b7;hb=51c1ebb1bc2642296379a8db1ba9dfb4f78a2f80;hp=decab1f42b919c91bcad08fe9141f469287ab829;hpb=7a6cba611d09f8eccdfc90d5ad3eb03762e60ce9;p=qemu diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c index decab1f..f545c89 100644 --- a/hw/scsi-disk.c +++ b/hw/scsi-disk.c @@ -348,15 +348,21 @@ int32_t scsi_send_command(SCSIDevice *s, uint32_t tag, uint8_t *buf, int lun) /* The normal LEN field for this command is zero. */ memset(s->buf, 0, 8); bdrv_get_geometry(s->bdrv, &nb_sectors); - s->buf[0] = (nb_sectors >> 24) & 0xff; - s->buf[1] = (nb_sectors >> 16) & 0xff; - s->buf[2] = (nb_sectors >> 8) & 0xff; - s->buf[3] = nb_sectors & 0xff; - s->buf[4] = 0; - s->buf[5] = 0; - s->buf[6] = s->cluster_size * 2; - s->buf[7] = 0; - s->buf_len = 8; + /* Returned value is the address of the last sector. */ + if (nb_sectors) { + nb_sectors--; + s->buf[0] = (nb_sectors >> 24) & 0xff; + s->buf[1] = (nb_sectors >> 16) & 0xff; + s->buf[2] = (nb_sectors >> 8) & 0xff; + s->buf[3] = nb_sectors & 0xff; + s->buf[4] = 0; + s->buf[5] = 0; + s->buf[6] = s->cluster_size * 2; + s->buf[7] = 0; + s->buf_len = 8; + } else { + scsi_command_complete(s, SENSE_NOT_READY); + } break; case 0x08: case 0x28: