Only leave the bootprio code in setup_drive_hd, like in setup_drive_cdrom. This is a preparatory step; later, the SCSI code in usb_msc_init will become entirely generic.
Also, the returned number of sectors is off by one. This will become more important when CHS translation is added later.
Signed-off-by: Paolo Bonzini pbonzini@redhat.com --- src/usb-msc.c | 32 +++++++++++++++----------------- 1 files changed, 15 insertions(+), 17 deletions(-)
diff --git a/src/usb-msc.c b/src/usb-msc.c index c8b9fbe..a0b79a5 100644 --- a/src/usb-msc.c +++ b/src/usb-msc.c @@ -153,7 +153,6 @@ process_usb_op(struct disk_op_s *op) static int setup_drive_cdrom(struct disk_op_s *op, char *desc) { - op->drive_g->blksize = CDROM_SECTOR_SIZE; op->drive_g->sectors = (u64)-1; struct usb_pipe *pipe = container_of( op->drive_g, struct usbdrive_s, drive)->bulkout; @@ -165,29 +164,16 @@ setup_drive_cdrom(struct disk_op_s *op, char *desc) static int setup_drive_hd(struct disk_op_s *op, char *desc) { - struct cdbres_read_capacity info; - int ret = cdb_read_capacity(op, &info); - if (ret) - return ret; - // XXX - retry for some timeout? - - u32 blksize = ntohl(info.blksize), sectors = ntohl(info.sectors); - if (blksize != DISK_SECTOR_SIZE) { - if (blksize == CDROM_SECTOR_SIZE) - return setup_drive_cdrom(op, desc); - dprintf(1, "Unsupported USB MSC block size %d\n", blksize); + if (op->drive_g->blksize != DISK_SECTOR_SIZE) { + dprintf(1, "Unsupported USB MSC block size %d\n", op->drive_g->blksize); return -1; } - op->drive_g->blksize = blksize; - op->drive_g->sectors = sectors; - dprintf(1, "USB MSC blksize=%d sectors=%d\n", blksize, sectors);
// Register with bcv system. struct usb_pipe *pipe = container_of( op->drive_g, struct usbdrive_s, drive)->bulkout; int prio = bootprio_find_usb(pipe->cntl->pci, pipe->path); boot_add_hd(op->drive_g, desc, prio); - return 0; }
@@ -252,7 +238,19 @@ usb_msc_init(struct usb_pipe *pipe , vendor, product, rev, pdt, removable); udrive_g->drive.removable = removable;
- if (pdt == USB_MSC_TYPE_CDROM) { + struct cdbres_read_capacity capdata; + ret = cdb_read_capacity(&dop, &capdata); + if (ret) + return ret; + // XXX - retry for some timeout? + + // READ CAPACITY returns the address of the last block + udrive_g->drive.blksize = ntohl(capdata.blksize); + udrive_g->drive.sectors = ntohl(capdata.sectors) + 1; + dprintf(1, "USB MSC blksize=%d sectors=%d\n", + udrive_g->drive.blksize, (int)udrive_g->drive.sectors); + + if (pdt == USB_MSC_TYPE_CDROM || udrive_g->drive.blksize == CDROM_SECTOR_SIZE) { char *desc = znprintf(MAXDESCSIZE, "DVD/CD [USB Drive %s %s %s]" , vendor, product, rev); ret = setup_drive_cdrom(&dop, desc);