aboutsummaryrefslogtreecommitdiff
path: root/hw/ide.c
diff options
context:
space:
mode:
authoraliguori <aliguori@c046a42c-6fe2-441c-8c8c-71466251a162>2009-01-07 17:32:33 +0000
committeraliguori <aliguori@c046a42c-6fe2-441c-8c8c-71466251a162>2009-01-07 17:32:33 +0000
commitfa879c641435bec4b79872ad14b9a90c8b7172f3 (patch)
treed8ade34df31c450b8d597a396f29269a749deb45 /hw/ide.c
parentff4b91c2f7e51dab148aba4bf43c2f39f219e495 (diff)
add "serial" parameter to -drive flag (Gleb Natapov)
Windows calculates HW "uniqueness" based on a hard drive serial number among other things. The patch allows to specify drive serial number from a command line. Signed-off-by: Gleb Natapov <gleb@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6214 c046a42c-6fe2-441c-8c8c-71466251a162
Diffstat (limited to 'hw/ide.c')
-rw-r--r--hw/ide.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/hw/ide.c b/hw/ide.c
index 461ebd61a1..915390ae0a 100644
--- a/hw/ide.c
+++ b/hw/ide.c
@@ -386,6 +386,7 @@ typedef struct IDEState {
PCIDevice *pci_dev;
struct BMDMAState *bmdma;
int drive_serial;
+ char drive_serial_str[21];
/* ide regs */
uint8_t feature;
uint8_t error;
@@ -531,7 +532,6 @@ static void ide_identify(IDEState *s)
{
uint16_t *p;
unsigned int oldsize;
- char buf[20];
if (s->identify_set) {
memcpy(s->io_buffer, s->identify_data, sizeof(s->identify_data));
@@ -546,8 +546,7 @@ static void ide_identify(IDEState *s)
put_le16(p + 4, 512 * s->sectors); /* XXX: retired, remove ? */
put_le16(p + 5, 512); /* XXX: retired, remove ? */
put_le16(p + 6, s->sectors);
- snprintf(buf, sizeof(buf), "QM%05d", s->drive_serial);
- padstr((char *)(p + 10), buf, 20); /* serial number */
+ padstr((char *)(p + 10), s->drive_serial_str, 20); /* serial number */
put_le16(p + 20, 3); /* XXX: retired, remove ? */
put_le16(p + 21, 512); /* cache size in sectors */
put_le16(p + 22, 4); /* ecc bytes */
@@ -601,7 +600,6 @@ static void ide_identify(IDEState *s)
static void ide_atapi_identify(IDEState *s)
{
uint16_t *p;
- char buf[20];
if (s->identify_set) {
memcpy(s->io_buffer, s->identify_data, sizeof(s->identify_data));
@@ -612,8 +610,7 @@ static void ide_atapi_identify(IDEState *s)
p = (uint16_t *)s->io_buffer;
/* Removable CDROM, 50us response, 12 byte packets */
put_le16(p + 0, (2 << 14) | (5 << 8) | (1 << 7) | (2 << 5) | (0 << 0));
- snprintf(buf, sizeof(buf), "QM%05d", s->drive_serial);
- padstr((char *)(p + 10), buf, 20); /* serial number */
+ padstr((char *)(p + 10), s->drive_serial_str, 20); /* serial number */
put_le16(p + 20, 3); /* buffer type */
put_le16(p + 21, 512); /* cache size in sectors */
put_le16(p + 22, 4); /* ecc bytes */
@@ -652,7 +649,6 @@ static void ide_cfata_identify(IDEState *s)
{
uint16_t *p;
uint32_t cur_sec;
- char buf[20];
p = (uint16_t *) s->identify_data;
if (s->identify_set)
@@ -668,8 +664,7 @@ static void ide_cfata_identify(IDEState *s)
put_le16(p + 6, s->sectors); /* Default sectors per track */
put_le16(p + 7, s->nb_sectors >> 16); /* Sectors per card */
put_le16(p + 8, s->nb_sectors); /* Sectors per card */
- snprintf(buf, sizeof(buf), "QM%05d", s->drive_serial);
- padstr((char *)(p + 10), buf, 20); /* Serial number in ASCII */
+ padstr((char *)(p + 10), s->drive_serial_str, 20); /* serial number */
put_le16(p + 22, 0x0004); /* ECC bytes */
padstr((char *) (p + 23), QEMU_VERSION, 8); /* Firmware Revision */
padstr((char *) (p + 27), "QEMU MICRODRIVE", 40);/* Model number */
@@ -2714,6 +2709,11 @@ static void ide_init2(IDEState *ide_state,
}
}
s->drive_serial = drive_serial++;
+ strncpy(s->drive_serial_str, drive_get_serial(s->bs),
+ sizeof(s->drive_serial_str));
+ if (strlen(s->drive_serial_str) == 0)
+ snprintf(s->drive_serial_str, sizeof(s->drive_serial_str),
+ "QM%05d", s->drive_serial);
s->irq = irq;
s->sector_write_timer = qemu_new_timer(vm_clock,
ide_sector_write_timer_cb, s);